-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·77 lines (70 loc) · 1.6 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
const meow = require('meow');
const fs = require('fs');
const getStdin = require('get-stdin');
const safeUpdater = require('.');
const cli = meow(`
Usage
$ safety-update ['major'|'minor'|'patch'|'all']
Options
--config, Config file path
--only-prod, Update Only dependency
--only-dev, Update Only devDependency
--break, -B, Update include breaking changes
--force, Skip test command on update
--manager <'npm'|'yarn'>, Detect your module manager.
Examples
$ safety-update minor patch --only-dev
for more infomation: https://github.com/pastak/npm-safety-updater
`, {
flags: {
config: {
type: 'string',
default: 'safety-update.config.json'
},
onlyProd: {
type: 'boolean',
default: false
},
onlyDev: {
type: 'boolean',
default: false
},
break: {
type: 'boolean',
default: false,
alias: 'B'
},
force: {
type: 'boolean',
default: false
},
manager: {
type: 'string'
},
emoji: {
type: 'boolean',
default: true
}
}
});
if (cli.input.length > 0) {
const configPath = require('path').resolve(cli.flags.config);
const existConfig = fs.existsSync(configPath);
let config;
if (existConfig) {
try {
config = JSON.parse(fs.readFileSync(configPath).toString());
} catch (e) { } // eslint-disable-line
} else {
return console.log('Require safety-update.config.json or use --config');
}
try {
getStdin()
.then(() => safeUpdater(cli.input, cli.flags, config));
} catch (e) {
console.error(e);
}
} else {
cli.showHelp();
}