From 4226a19c01dc67f36152c892aa4f2be66fab370a Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Wed, 12 Jul 2017 11:04:17 -0700 Subject: [PATCH] chore(artifacts): Update artifact SNAPSHOT publish script --- scripts/artifact_tagging.js | 71 ++++++++++++++++++++++++++++------- scripts/artifact_tagging.json | 7 ++++ 2 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 scripts/artifact_tagging.json diff --git a/scripts/artifact_tagging.js b/scripts/artifact_tagging.js index a61007dd5..b356c959f 100755 --- a/scripts/artifact_tagging.js +++ b/scripts/artifact_tagging.js @@ -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'); @@ -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]; @@ -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(); @@ -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); } @@ -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`); + diff --git a/scripts/artifact_tagging.json b/scripts/artifact_tagging.json new file mode 100644 index 000000000..01e0d6d8e --- /dev/null +++ b/scripts/artifact_tagging.json @@ -0,0 +1,7 @@ +{ + "COMMIT_ARTIFACTS": [ + "lib", + "_bundles", + "package.json" + ] +}