UNPKG

2.16 kBJavaScriptView Raw
1#!/usr/bin/env node
2'use strict';
3
4var program = require('commander');
5var getStdin = require('get-stdin');
6var path = require('path');
7var Invig = require('./Invig');
8var pkgUp = require('pkg-up');
9var scrolex = require('scrolex');
10
11var rootDir = path.dirname(pkgUp.sync(__filename));
12var npmDir = rootDir + '/node_modules';
13var npmBinDir = npmDir + '/.bin';
14var untildify = require('untildify');
15
16program.version(require('../package.json').version).option('-s, --src <dir>', "Directory or file to convert. DESTRUCTIVE. MAKE SURE IT'S UNDER SOURCE CONTROL. ").option('-b, --bail', 'Abort on the first error instead of continuing to port the next file').option('-c, --check', 'When done, run dependency check to see if there are unused or unupdated ones').option('-d, --dryrun', 'Wether to execute commands or just output them').option('-q, --quiet', 'Hide any output').parse(process.argv);
17
18if (!('concurrency' in program)) {
19 program.concurrency = 1;
20}
21
22program.src = untildify(program.src);
23program.init = !!program.init;
24program.dryrun = !!program.dryrun;
25program.bail = !!program.bail;
26program.quiet = !!program.quiet;
27
28scrolex.persistOpts({
29 announce: true,
30 addCommandAsComponent: true,
31 components: 'invig',
32 shell: true,
33 fatal: program.bail,
34 dryrun: program.dryrun
35});
36if (program.quiet === true) {
37 scrolex.persistOpts({
38 mode: 'silent'
39 });
40}
41
42if (!('src' in program)) {
43 scrolex.failure('You should provide at least a --src <dir> argument');
44 process.exit(1);
45}
46
47var invig = new Invig({
48 src: program.src,
49 dryrun: program.dryrun,
50 bail: program.bail,
51 init: program.init,
52 quiet: program.quiet,
53 concurrency: program.concurrency,
54 npmBinDir: npmBinDir
55});
56
57if (program.src === '-') {
58 getStdin().then(function (stdin) {
59 invig.runOnStdIn(stdin, function (err) {
60 if (err) {
61 scrolex.failure('' + err);
62 process.exit(1);
63 } else {
64 scrolex.success('Done');
65 }
66 });
67 });
68} else {
69 invig.runOnPattern(function (err) {
70 if (err) {
71 scrolex.failure('' + err);
72 process.exit(1);
73 } else {
74 scrolex.success('Done');
75 }
76 });
77}
78//# sourceMappingURL=cli.js.map
\No newline at end of file