@samitouri / QOS-React-2 / commits / e3a41edd83

[rrm] npm-publish command

This will publish all packages in build/packages/*.tgz to the "next" tag. If the current version is "stable" (doesn't trigger semver.prerelease()) then it will also update the "latest" dist-tag to point at that version.

Paul O’Shannessy committed Jul 21, 2016 at 16:01 UTC e3a41edd83073b52c26da1e6f30b532fb25af553
4 files changed +83
scripts/release-manager/Readme.md
+7
@@ -31,6 +31,13 @@ Cherry-picks PRs that are set to the `15-next` milestone. Handles merge conflict
31
32 Bumps the version in all the places that need it.
33
34 +### `npm-publish`
35 +
36 +Publishes all built packages to npm (`next` dist-tag) and then for stable releases, also updates the `latest` dist-tag.
37 +
38 +**Prereqs:**
39 +- Have done everything else required for releasing (updating version, etc) and run `grunt build` or `grunt release`.
40 +
41 ### `q`
42
43 A secret alias to `exit` because `q` is faster.
scripts/release-manager/cli.js
+1
@@ -115,6 +115,7 @@ const app = {
115 'q',
116 'stable-prs',
117 'version',
118 + 'npm-publish',
119 ].forEach((command) => {
120 vorpal.use(require(`./commands/${command}`)(vorpal, app));
121 });
scripts/release-manager/commands/npm-publish.js new
+74
@@ -0,0 +1,74 @@
1 +
2 +// Publishes the built npm packages from build/packages
3 +// 1. Show checklist (automate later)
4 +// 2. Prompt to ensure build is complete
5 +// 3. Prompt for dist-tag?
6 +
7 +
8 +'use strict';
9 +
10 +const path = require('path');
11 +const semver = require('semver');
12 +
13 +const chalk = require('chalk');
14 +const glob = require('glob');
15 +
16 +
17 +module.exports = function(vorpal, app) {
18 + vorpal
19 + .command('npm-publish')
20 + .description('Update the version of React, useful while publishing')
21 + .action(function (args) {
22 + return new Promise((resolve, reject) => {
23 + const currentVersion = app.getReactVersion();
24 + const isStable = semver.prerelease(currentVersion) === null;
25 +
26 + this.log(`Preparing to publish v${currentVersion}…`);
27 + if (isStable) {
28 + this.log(`"latest" dist-tag will be added to this version`);
29 + }
30 +
31 + // TODO: show checklist
32 + this.prompt([
33 + {
34 + type: 'confirm',
35 + message: 'Did you run `grunt build` or `grunt release` and bump the version number?',
36 + name: 'checklist'
37 + },
38 + ]).then((answers) => {
39 + if (!answers.checklist) {
40 + return reject('Complete the build process first')
41 + }
42 +
43 + // We'll grab all the tarballs and publish those directly. This
44 + // is how we've historically done it, though in the past it was
45 + // just npm publish pkg1.tgz && npm publish pkg2.tgz. This
46 + // avoided the need to cd and publish.
47 + const tgz = glob.sync('build/packages/*.tgz', {
48 + cwd: app.PATH_TO_REPO
49 + });
50 +
51 + // Just in case they didn't actually prep this.
52 + // TODO: verify packages?
53 + if (tgz.length === 0) {
54 + reject('No built packages found');
55 + }
56 +
57 + // TODO: track success
58 + tgz.forEach((file) => {
59 + this.log(app.execInRepo(`npm publish ${file} --tag=next`));
60 + });
61 +
62 + if (isStable) {
63 + tgz.forEach((file) => {
64 + const pkg = path.parse(file).name
65 + this.log(app.execInRepo(`npm dist-tag add ${pkg}@${currentVersion} latest`));
66 + });
67 + }
68 +
69 + resolve();
70 + })
71 + });
72 +
73 + });
74 +}
scripts/release-manager/package.json
+1
@@ -8,6 +8,7 @@
8 "chalk": "^1.1.3",
9 "colors": "^1.1.2",
10 "github-api": "^2.2.0",
11 + "glob": "^7.0.5",
12 "semver": "^5.3.0",
13 "vorpal": "^1.10.10"
14 },