1 | #!/usr/bin/env node
|
2 | 'use strict';
|
3 |
|
4 | var program = require('commander');
|
5 | var getStdin = require('get-stdin');
|
6 | var path = require('path');
|
7 | var Invig = require('./Invig');
|
8 | var pkgUp = require('pkg-up');
|
9 | var scrolex = require('scrolex');
|
10 |
|
11 | var rootDir = path.dirname(pkgUp.sync(__filename));
|
12 | var npmDir = rootDir + '/node_modules';
|
13 | var npmBinDir = npmDir + '/.bin';
|
14 | var untildify = require('untildify');
|
15 |
|
16 | program.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 |
|
18 | if (!('concurrency' in program)) {
|
19 | program.concurrency = 1;
|
20 | }
|
21 |
|
22 | program.src = untildify(program.src);
|
23 | program.init = !!program.init;
|
24 | program.dryrun = !!program.dryrun;
|
25 | program.bail = !!program.bail;
|
26 | program.quiet = !!program.quiet;
|
27 |
|
28 | scrolex.persistOpts({
|
29 | announce: true,
|
30 | addCommandAsComponent: true,
|
31 | components: 'invig',
|
32 | shell: true,
|
33 | fatal: program.bail,
|
34 | dryrun: program.dryrun
|
35 | });
|
36 | if (program.quiet === true) {
|
37 | scrolex.persistOpts({
|
38 | mode: 'silent'
|
39 | });
|
40 | }
|
41 |
|
42 | if (!('src' in program)) {
|
43 | scrolex.failure('You should provide at least a --src <dir> argument');
|
44 | process.exit(1);
|
45 | }
|
46 |
|
47 | var 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 |
|
57 | if (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 |
|
\ | No newline at end of file |