-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
cli.js
executable file
·110 lines (97 loc) · 2.4 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env node
'use strict';
// eslint-disable-next-line import/no-unassigned-import
require('symbol-observable'); // Important: This needs to be first to prevent weird Observable incompatibilities
const logSymbols = require('log-symbols');
const meow = require('meow');
const updateNotifier = require('update-notifier');
const hasYarn = require('has-yarn');
const config = require('./config');
const {isPackageNameAvailable} = require('./npm/util');
const version = require('./version');
const util = require('./util');
const ui = require('./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
--no-release-draft Skips opening a GitHub release draft
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
`, {
booleanDefault: undefined,
flags: {
anyBranch: {
type: 'boolean'
},
cleanup: {
type: 'boolean'
},
yolo: {
type: 'boolean'
},
publish: {
type: 'boolean'
},
releaseDraft: {
type: 'boolean',
default: true
},
tag: {
type: 'string'
},
yarn: {
type: 'boolean'
},
contents: {
type: 'string'
}
}
});
updateNotifier({pkg: cli.pkg}).notify();
(async () => {
const pkg = util.readPkg();
const defaultFlags = {
cleanup: true,
publish: true,
yarn: hasYarn()
};
const localConfig = await config();
const flags = {
...defaultFlags,
...localConfig,
...cli.flags
};
const isAvailable = flags.publish ? await isPackageNameAvailable(pkg) : false;
const options = cli.input.length > 0 ?
{
...flags,
confirm: true,
exists: !isAvailable,
version: cli.input[0]
} :
await ui({...flags, exists: !isAvailable}, pkg);
if (!options.confirm) {
process.exit(0);
}
console.log(); // Prints a newline for readability
const newPkg = await np(options.version, options);
console.log(`\n ${newPkg.name} ${newPkg.version} published 🎉`);
})().catch(error => {
console.error(`\n${logSymbols.error} ${error.message}`);
process.exit(1);
});