Skip to content

Commit 94d139b

Browse files
chore(artifacts): Allow publishing artifacts to either npm or github branch
1 parent 4d01238 commit 94d139b

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

scripts/artifact_tagging.js

+54-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!env node
22
"use strict";
33

4-
const COMMIT_ARTIFACTS = ['lib', 'lib-esm', 'release', 'package.json'];
4+
const CONFIG = require('./artifact_tagging.json');
5+
const COMMIT_ARTIFACTS = CONFIG.COMMIT_ARTIFACTS;
56

67
let shx = require('shelljs');
78
let readlineSync = require('readline-sync');
@@ -15,7 +16,7 @@ let version = pkg.version;
1516

1617
shx.cd(path.join(__dirname, '..'));
1718

18-
var widen = false;
19+
var widen = false, npm = false, githubtag = false;
1920
var coreDep = pkg.dependencies['@uirouter/core'];
2021
var isNarrow = /^[[=~]?(\d.*)/.exec(coreDep);
2122
var widenedDep = isNarrow && '^' + isNarrow[1];
@@ -24,6 +25,21 @@ if (isNarrow && readlineSync.keyInYN('Widen @uirouter/core dependency from ' + c
2425
widen = false;
2526
}
2627

28+
if (readlineSync.keyInYN('Publish to NPM')) {
29+
npm = true;
30+
}
31+
32+
33+
if (readlineSync.keyInYN('publish to Github Tag?')) {
34+
githubtag = true;
35+
}
36+
37+
if (!npm && !githubtag) {
38+
process.exit(1);
39+
}
40+
41+
var label = githubtag && npm ? "npm package and github tag" : npm ? "npm package" : "github tag";
42+
2743
const YYYYMMDD = (function() {
2844
var date = new Date();
2945
var year = date.getFullYear();
@@ -38,9 +54,17 @@ const YYYYMMDD = (function() {
3854
})();
3955

4056
let tagname = `SNAPSHOT-${YYYYMMDD}`;
41-
tagname += readlineSync.question(`Suffix for tag ${tagname} (optional)?`);
57+
let pkgver = `-SNAPSHOT.${YYYYMMDD}`;
58+
59+
if (githubtag) {
60+
tagname += readlineSync.question(`Suffix for tag ${tagname} (optional)?`);
61+
}
62+
63+
if (npm) {
64+
pkgver += readlineSync.question(`Suffix for package version ${pkgver} (optional)?`);
65+
}
4266

43-
if (!readlineSync.keyInYN(`Ready to publish ${tagname} tag?`)) {
67+
if (!readlineSync.keyInYN(`Ready to publish ${label}?`)) {
4468
process.exit(1);
4569
}
4670

@@ -50,18 +74,36 @@ util.ensureCleanMaster('master');
5074
_exec(`git checkout -b ${tagname}-prep`);
5175

5276
pkg.dependencies['@uirouter/core'] = widenedDep;
53-
// pkg.version = tagname;
77+
pkg.version += pkgver;
5478

5579
fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 2));
56-
_exec('git commit -m "Widening @uirouter/core dependency range to ' + widenedDep + '" package.json');
80+
_exec(`git commit -m "Widening @uirouter/core dependency range to ${widenedDep}" package.json`);
81+
82+
_exec(`npm run package`);
83+
84+
if (npm) {
85+
let output = _exec(`npm dist-tag ls ${pkg.name}`).stdout;
86+
let latest = output.split(/[\r\n]/)
87+
.map(line => line.split(": "))
88+
.filter(linedata => linedata[0] === 'latest')[0];
89+
90+
if (!latest) {
91+
throw new Error(`Could not determine value of "latest" dist-tag for ${pkg.name}`);
92+
}
93+
94+
_exec(`npm publish`);
95+
_exec(`npm dist-tag add ${pkg.name}@${latest} latest`);
96+
}
5797

58-
_exec('npm run package');
98+
if (githubtag) {
99+
_exec(`git add --force ${COMMIT_ARTIFACTS.join(' ')}`);
100+
_exec(`git rm yarn.lock`);
59101

60-
_exec(`git add --force ${COMMIT_ARTIFACTS.join(' ')}`);
61-
_exec(`git rm yarn.lock`);
102+
_exec(`git commit -m 'chore(*): commiting build files'`);
103+
_exec(`git tag ${tagname}`);
104+
_exec(`git push -u origin ${tagname}`);
105+
}
62106

63-
_exec(`git commit -m 'chore(*): commiting build files'`);
64-
_exec(`git tag ${tagname}`);
65-
_exec(`git push -u origin ${tagname}`);
66107
_exec(`git checkout master`);
67108
_exec(`git branch -D ${tagname}-prep`);
109+

scripts/artifact_tagging.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"COMMIT_ARTIFACTS": [
3+
"lib",
4+
"lib-esm",
5+
"release",
6+
"package.json"
7+
]
8+
}

0 commit comments

Comments
 (0)