forked from rwjblue/codemod-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·43 lines (36 loc) · 1.02 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
'use strict';
if (process.env.REQUIRE_TRACE) {
// eslint-disable-next-line node/no-unpublished-require
const requireSoSlow = require('require-so-slow');
process.on('exit', function() {
requireSoSlow.write('require-trace.trace');
});
}
const importLocal = require('import-local');
const pkgUp = require('pkg-up');
function insideProject() {
let nearestPackagePath = pkgUp.sync();
if (!nearestPackagePath) {
return false;
}
let pkg = require(nearestPackagePath);
return pkg.keywords && pkg.keywords.includes('codemod-cli');
}
if (importLocal(__filename) || insideProject()) {
require('yargs')
.locale('en')
.commandDir('../commands/local')
.demandCommand()
.help()
.epilog('For more information, see https://github.com/rwjblue/codemod-cli')
.parse();
} else {
require('yargs')
.locale('en')
.commandDir('../commands/global')
.demandCommand()
.help()
.epilog('For more information, see https://github.com/rwjblue/codemod-cli')
.parse();
}