Skip to content

Commit

Permalink
chore(artifacts): Update artifact SNAPSHOT publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Jul 12, 2017
1 parent d0c46ce commit 4226a19
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 14 deletions.
71 changes: 57 additions & 14 deletions scripts/artifact_tagging.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!env node
"use strict";

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

let shx = require('shelljs');
let readlineSync = require('readline-sync');
Expand All @@ -12,9 +11,12 @@ let path = require('path');
let util = require('./util');
let _exec = util._exec;

let pkg = require('../package.json');
let version = pkg.version;

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

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

if (readlineSync.keyInYN('Publish to NPM')) {
npm = true;
}


if (readlineSync.keyInYN('publish to Github Tag?')) {
githubtag = true;
}

if (!npm && !githubtag) {
process.exit(1);
}

var label = githubtag && npm ? "npm package and github tag" : npm ? "npm package" : "github tag";

const YYYYMMDD = (function() {
var date = new Date();
var year = date.getFullYear();
Expand All @@ -37,9 +54,17 @@ const YYYYMMDD = (function() {
})();

let tagname = `SNAPSHOT-${YYYYMMDD}`;
tagname += readlineSync.question(`Suffix for tag ${tagname} (optional)?`);
let pkgver = `-SNAPSHOT.${YYYYMMDD}`;

if (githubtag) {
tagname += readlineSync.question(`Suffix for tag ${tagname} (optional)?`);
}

if (!readlineSync.keyInYN(`Ready to publish ${tagname} tag?`)) {
if (npm) {
pkgver += readlineSync.question(`Suffix for package version ${pkgver} (optional)?`);
}

if (!readlineSync.keyInYN(`Ready to publish ${label}?`)) {
process.exit(1);
}

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

pkg.dependencies['@uirouter/core'] = widenedDep;
// pkg.version = tagname;
pkg.version += pkgver;

fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 2));
_exec('git commit -m "Widening @uirouter/core dependency range to ' + widenedDep + '" package.json');
_exec(`git commit -m "Widening @uirouter/core dependency range to ${widenedDep}" package.json`);

_exec(`npm run package`);

if (npm) {
let output = _exec(`npm dist-tag ls ${pkg.name}`).stdout;
let latest = output.split(/[\r\n]/)
.map(line => line.split(": "))
.filter(linedata => linedata[0] === 'latest')[0];

if (!latest) {
throw new Error(`Could not determine value of "latest" dist-tag for ${pkg.name}`);
}

_exec(`npm publish`);
_exec(`npm dist-tag add ${pkg.name}@${latest} latest`);
}

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

_exec(`git add --force lib _bundles package.json`);
_exec(`git rm yarn.lock`);
_exec(`git commit -m 'chore(*): commiting build files'`);
_exec(`git tag ${tagname}`);
_exec(`git push -u origin ${tagname}`);
}

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

7 changes: 7 additions & 0 deletions scripts/artifact_tagging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"COMMIT_ARTIFACTS": [
"lib",
"_bundles",
"package.json"
]
}

0 comments on commit 4226a19

Please sign in to comment.