/
npm-publish.js
73 lines (58 loc) · 2.13 KB
/
npm-publish.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
// Publishes the built npm packages from build/packages
// 1. Show checklist (automate later)
// 2. Prompt to ensure build is complete
// 3. Prompt for dist-tag?
'use strict';
const path = require('path');
const semver = require('semver');
const glob = require('glob');
module.exports = function(vorpal, app) {
vorpal
.command('npm-publish')
.description('Update the version of React, useful while publishing')
.action(function(args) {
return new Promise((resolve, reject) => {
const currentVersion = app.getReactVersion();
const isStable = semver.prerelease(currentVersion) === null;
this.log(`Preparing to publish v${currentVersion}…`);
if (isStable) {
this.log(`"latest" dist-tag will be added to this version`);
}
// TODO: show checklist
this.prompt([
{
type: 'confirm',
message: 'Did you run `grunt build` or `grunt release` and bump the version number?',
name: 'checklist',
},
]).then((answers) => {
if (!answers.checklist) {
return reject('Complete the build process first');
}
// We'll grab all the tarballs and publish those directly. This
// is how we've historically done it, though in the past it was
// just npm publish pkg1.tgz && npm publish pkg2.tgz. This
// avoided the need to cd and publish.
const tgz = glob.sync('build/packages/*.tgz', {
cwd: app.PATH_TO_REPO,
});
// Just in case they didn't actually prep this.
// TODO: verify packages?
if (tgz.length === 0) {
reject('No built packages found');
}
// TODO: track success
tgz.forEach((file) => {
this.log(app.execInRepo(`npm publish ${file} --tag=next`));
});
if (isStable) {
tgz.forEach((file) => {
const pkg = path.parse(file).name;
this.log(app.execInRepo(`npm dist-tag add ${pkg}@${currentVersion} latest`));
});
}
resolve();
});
});
});
};