1 | #!/usr/bin/env node
|
2 | 'use strict';
|
3 | const logSymbols = require('log-symbols');
|
4 | const meow = require('meow');
|
5 | const updateNotifier = require('update-notifier');
|
6 | const hasYarn = require('has-yarn');
|
7 | const version = require('./lib/version');
|
8 | const ui = require('./lib/ui');
|
9 | const np = require('.');
|
10 |
|
11 | const cli = meow(`
|
12 | Usage
|
13 | $ np <version>
|
14 |
|
15 | Version can be:
|
16 | ${version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
|
17 |
|
18 | Options
|
19 | --any-branch Allow publishing from any branch
|
20 | --no-cleanup Skips cleanup of node_modules
|
21 | --yolo Skips cleanup and testing
|
22 | --no-publish Skips publishing
|
23 | --tag Publish under a given dist-tag
|
24 | --no-yarn Don't use Yarn
|
25 | --contents Subdirectory to publish
|
26 |
|
27 | Examples
|
28 | $ np
|
29 | $ np patch
|
30 | $ np 1.0.2
|
31 | $ np 1.0.2-beta.3 --tag=beta
|
32 | $ np 1.0.2-beta.3 --tag=beta --contents=dist
|
33 | `, {
|
34 | flags: {
|
35 | anyBranch: {
|
36 | type: 'boolean'
|
37 | },
|
38 | cleanup: {
|
39 | type: 'boolean',
|
40 | default: true
|
41 | },
|
42 | yolo: {
|
43 | type: 'boolean'
|
44 | },
|
45 | publish: {
|
46 | type: 'boolean',
|
47 | default: true
|
48 | },
|
49 | tag: {
|
50 | type: 'string'
|
51 | },
|
52 | yarn: {
|
53 | type: 'boolean',
|
54 | default: hasYarn()
|
55 | },
|
56 | contents: {
|
57 | type: 'string'
|
58 | }
|
59 | }
|
60 | });
|
61 |
|
62 | updateNotifier({pkg: cli.pkg}).notify();
|
63 |
|
64 | process.on('SIGINT', () => {
|
65 | console.log('\nAborted!');
|
66 | process.exit(1);
|
67 | });
|
68 |
|
69 | Promise
|
70 | .resolve()
|
71 | .then(() => {
|
72 | if (cli.input.length > 0) {
|
73 | return Object.assign({}, cli.flags, {
|
74 | confirm: true,
|
75 | version: cli.input[0]
|
76 | });
|
77 | }
|
78 |
|
79 | return ui(cli.flags);
|
80 | })
|
81 | .then(options => {
|
82 | if (!options.confirm) {
|
83 | process.exit(0);
|
84 | }
|
85 |
|
86 | return options;
|
87 | })
|
88 | .then(options => np(options.version, options))
|
89 | .then(pkg => {
|
90 | console.log(`\n ${pkg.name} ${pkg.version} published 🎉`);
|
91 | })
|
92 | .catch(err => {
|
93 | console.error(`\n${logSymbols.error} ${err.message}`);
|
94 | process.exit(1);
|
95 | });
|