UNPKG

2.5 kBJavaScriptView Raw
1#!/usr/bin/env node
2'use strict';
3// eslint-disable-next-line import/no-unassigned-import
4require('symbol-observable'); // Important: This needs to be first to prevent weird Observable incompatibilities
5const logSymbols = require('log-symbols');
6const meow = require('meow');
7const updateNotifier = require('update-notifier');
8const hasYarn = require('has-yarn');
9const config = require('./config');
10const {isPackageNameAvailable} = require('./npm/util');
11const version = require('./version');
12const util = require('./util');
13const ui = require('./ui');
14const np = require('.');
15
16const cli = meow(`
17 Usage
18 $ np <version>
19
20 Version can be:
21 ${version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
22
23 Options
24 --any-branch Allow publishing from any branch
25 --no-cleanup Skips cleanup of node_modules
26 --no-tests Skips tests
27 --yolo Skips cleanup and testing
28 --no-publish Skips publishing
29 --tag Publish under a given dist-tag
30 --no-yarn Don't use Yarn
31 --contents Subdirectory to publish
32 --no-release-draft Skips opening a GitHub release draft
33
34 Examples
35 $ np
36 $ np patch
37 $ np 1.0.2
38 $ np 1.0.2-beta.3 --tag=beta
39 $ np 1.0.2-beta.3 --tag=beta --contents=dist
40`, {
41 booleanDefault: undefined,
42 flags: {
43 anyBranch: {
44 type: 'boolean'
45 },
46 cleanup: {
47 type: 'boolean'
48 },
49 tests: {
50 type: 'boolean'
51 },
52 yolo: {
53 type: 'boolean'
54 },
55 publish: {
56 type: 'boolean'
57 },
58 releaseDraft: {
59 type: 'boolean',
60 default: true
61 },
62 tag: {
63 type: 'string'
64 },
65 yarn: {
66 type: 'boolean'
67 },
68 contents: {
69 type: 'string'
70 }
71 }
72});
73
74updateNotifier({pkg: cli.pkg}).notify();
75
76(async () => {
77 const pkg = util.readPkg();
78
79 const defaultFlags = {
80 cleanup: true,
81 tests: true,
82 publish: true,
83 yarn: hasYarn()
84 };
85
86 const localConfig = await config();
87
88 const flags = {
89 ...defaultFlags,
90 ...localConfig,
91 ...cli.flags
92 };
93
94 const isAvailable = flags.publish ? await isPackageNameAvailable(pkg) : false;
95
96 const version = cli.input.length > 0 ? cli.input[0] : false;
97
98 const options = await ui({...flags, exists: !isAvailable, version}, pkg);
99
100 if (!options.confirm) {
101 process.exit(0);
102 }
103
104 console.log(); // Prints a newline for readability
105 const newPkg = await np(options.version, options);
106 console.log(`\n ${newPkg.name} ${newPkg.version} published 🎉`);
107})().catch(error => {
108 console.error(`\n${logSymbols.error} ${error.message}`);
109 process.exit(1);
110});