forked from sindresorhus/np
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·95 lines (86 loc) · 1.77 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
'use strict';
const logSymbols = require('log-symbols');
const meow = require('meow');
const updateNotifier = require('update-notifier');
const hasYarn = require('has-yarn');
const version = require('./lib/version');
const ui = require('./lib/ui');
const np = require('.');
const cli = meow(`
Usage
$ np <version>
Version can be:
${version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
Options
--any-branch Allow publishing from any branch
--no-cleanup Skips cleanup of node_modules
--yolo Skips cleanup and testing
--no-publish Skips publishing
--tag Publish under a given dist-tag
--no-yarn Don't use Yarn
--contents Subdirectory to publish
Examples
$ np
$ np patch
$ np 1.0.2
$ np 1.0.2-beta.3 --tag=beta
$ np 1.0.2-beta.3 --tag=beta --contents=dist
`, {
flags: {
anyBranch: {
type: 'boolean'
},
cleanup: {
type: 'boolean',
default: true
},
yolo: {
type: 'boolean'
},
publish: {
type: 'boolean',
default: true
},
tag: {
type: 'string'
},
yarn: {
type: 'boolean',
default: hasYarn()
},
contents: {
type: 'string'
}
}
});
updateNotifier({pkg: cli.pkg}).notify();
process.on('SIGINT', () => {
console.log('\nAborted!');
process.exit(1);
});
Promise
.resolve()
.then(() => {
if (cli.input.length > 0) {
return Object.assign({}, cli.flags, {
confirm: true,
version: cli.input[0]
});
}
return ui(cli.flags);
})
.then(options => {
if (!options.confirm) {
process.exit(0);
}
return options;
})
.then(options => np(options.version, options))
.then(pkg => {
console.log(`\n ${pkg.name} ${pkg.version} published 🎉`);
})
.catch(err => {
console.error(`\n${logSymbols.error} ${err.message}`);
process.exit(1);
});