Skip to content

Commit 4226a19

Browse files
chore(artifacts): Update artifact SNAPSHOT publish script
1 parent d0c46ce commit 4226a19

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

scripts/artifact_tagging.js

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!env node
22
"use strict";
33

4-
let pkg = require('../package.json');
5-
let version = pkg.version;
6-
let hybridVersion = require('../../angular-hybrid/package.json').version;
4+
const CONFIG = require('./artifact_tagging.json');
5+
const COMMIT_ARTIFACTS = CONFIG.COMMIT_ARTIFACTS;
76

87
let shx = require('shelljs');
98
let readlineSync = require('readline-sync');
@@ -12,9 +11,12 @@ let path = require('path');
1211
let util = require('./util');
1312
let _exec = util._exec;
1413

14+
let pkg = require('../package.json');
15+
let version = pkg.version;
16+
1517
shx.cd(path.join(__dirname, '..'));
1618

17-
var widen = false;
19+
var widen = false, npm = false, githubtag = false;
1820
var coreDep = pkg.dependencies['@uirouter/core'];
1921
var isNarrow = /^[[=~]?(\d.*)/.exec(coreDep);
2022
var widenedDep = isNarrow && '^' + isNarrow[1];
@@ -23,6 +25,21 @@ if (isNarrow && readlineSync.keyInYN('Widen @uirouter/core dependency from ' + c
2325
widen = false;
2426
}
2527

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+
2643
const YYYYMMDD = (function() {
2744
var date = new Date();
2845
var year = date.getFullYear();
@@ -37,9 +54,17 @@ const YYYYMMDD = (function() {
3754
})();
3855

3956
let tagname = `SNAPSHOT-${YYYYMMDD}`;
40-
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+
}
4162

42-
if (!readlineSync.keyInYN(`Ready to publish ${tagname} tag?`)) {
63+
if (npm) {
64+
pkgver += readlineSync.question(`Suffix for package version ${pkgver} (optional)?`);
65+
}
66+
67+
if (!readlineSync.keyInYN(`Ready to publish ${label}?`)) {
4368
process.exit(1);
4469
}
4570

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

5176
pkg.dependencies['@uirouter/core'] = widenedDep;
52-
// pkg.version = tagname;
77+
pkg.version += pkgver;
5378

5479
fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 2));
55-
_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+
}
5697

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

59-
_exec(`git add --force lib _bundles package.json`);
60-
_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+
}
61106

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

scripts/artifact_tagging.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"COMMIT_ARTIFACTS": [
3+
"lib",
4+
"_bundles",
5+
"package.json"
6+
]
7+
}

0 commit comments

Comments
 (0)