Skip to content

Commit ea64b32

Browse files
chore(*): commit scripts from angular to separate repo
0 parents  commit ea64b32

12 files changed

+1278
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# common
2+
node_modules
3+
.DS_Store
4+
*~
5+
.tscache
6+
.baseDir.ts
7+
8+
# webstorm files
9+
.idea
10+
idea-out
11+
*.iml
12+
*.ipr
13+
*.iws
14+
15+
_doc
16+
_bundles
17+
lib
18+
lib-esm
19+
stats.html

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.*

artifact_tagging.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!env node
2+
"use strict";
3+
4+
const CONFIG = require('./artifacts.json');
5+
const COMMIT_ARTIFACTS = CONFIG.ARTIFACTS;
6+
7+
let shx = require('shelljs');
8+
let readlineSync = require('readline-sync');
9+
let fs = require('fs');
10+
let path = require('path');
11+
let util = require('./util');
12+
let _exec = util._exec;
13+
14+
let pkg = require('../package.json');
15+
let version = pkg.version;
16+
17+
shx.cd(path.join(__dirname, '..'));
18+
19+
var widen = false, npm = false, githubtag = false;
20+
var coreDep = pkg.dependencies['@uirouter/core'];
21+
var isNarrow = /^[[=~]?(\d.*)/.exec(coreDep);
22+
var widenedDep = isNarrow && '^' + isNarrow[1];
23+
24+
if (isNarrow && readlineSync.keyInYN('Widen @uirouter/core dependency from ' + coreDep + ' to ' + widenedDep + '?')) {
25+
widen = false;
26+
}
27+
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+
43+
const YYYYMMDD = (function() {
44+
var date = new Date();
45+
var year = date.getFullYear();
46+
47+
var month = date.getMonth() + 1;
48+
month = (month < 10 ? "0" : "") + month;
49+
50+
var day = date.getDate();
51+
day = (day < 10 ? "0" : "") + day;
52+
53+
return year + month + day;
54+
})();
55+
56+
let tagname = `SNAPSHOT-${YYYYMMDD}`;
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+
}
66+
67+
if (!readlineSync.keyInYN(`Ready to publish ${label}?`)) {
68+
process.exit(1);
69+
}
70+
71+
util.ensureCleanMaster('master');
72+
73+
// then tag and push tag
74+
_exec(`git checkout -b ${tagname}-prep`);
75+
76+
pkg.dependencies['@uirouter/core'] = widenedDep;
77+
pkg.version += pkgver;
78+
79+
fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 2));
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+
}
97+
98+
if (githubtag) {
99+
_exec(`git add --force ${COMMIT_ARTIFACTS.join(' ')}`);
100+
_exec(`git rm yarn.lock`);
101+
102+
_exec(`git commit -m 'chore(*): commiting build files'`);
103+
_exec(`git tag ${tagname}`);
104+
_exec(`git push -u origin ${tagname}`);
105+
}
106+
107+
_exec(`git checkout master`);
108+
_exec(`git branch -D ${tagname}-prep`);
109+

ensure_clean_master.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!env node
2+
if(require.main === module && process.argv[2])
3+
branch = process.argv[2];
4+
5+
require('./util').ensureCleanMaster(branch);

modify_sourcemap_paths.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!env node
2+
"use strict";
3+
4+
require('shelljs/global');
5+
const fs = require('fs');
6+
const path = require('path');
7+
const glob = require('glob');
8+
const pkgName = require('../package.json').name;
9+
const prefix = path.resolve(__dirname, '..');
10+
11+
const allartifacts = require('./artifacts.json').ARTIFACTS;
12+
const globs = allartifacts
13+
.map(dir => path.resolve(prefix, dir))
14+
.filter(dir => fs.lstatSync(dir).isDirectory())
15+
.map(dir => `${dir}/**/*.js.map`);
16+
17+
const files = globs
18+
.map(pattern => glob.sync(pattern))
19+
.reduce((acc, arr) => acc.concat(arr), []);
20+
21+
files.forEach(file => {
22+
const data = JSON.parse(fs.readFileSync(file));
23+
if (Array.isArray(data.sources)) {
24+
data.sources = data.sources.map(source => source.replace(/^(?:\.\.\/)*src/, pkgName));
25+
fs.writeFileSync(file, JSON.stringify(data));
26+
}
27+
});

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@uirouter/publish-scripts",
3+
"version": "1.0.0",
4+
"description": "Helper scripts for publishing UI-Router projects",
5+
"main": "x",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/ui-router/publish-scripts.git"
9+
},
10+
"author": "Chris Thielen",
11+
"license": "MIT",
12+
"bugs": {
13+
"url": "https://github.com/ui-router/publish-scripts/issues"
14+
},
15+
"homepage": "https://github.com/ui-router/publish-scripts#readme",
16+
"bin": {
17+
"artifact_tagging": "./artifact_tagging.js",
18+
"ensure_clean_master": "./ensure_clean_master.js",
19+
"release": "./release.js",
20+
"show_changelog": "./show_changelog.js",
21+
"show_core_changelog": "./show_core_changelog.js",
22+
"update_changelog": "./update_changelog.js",
23+
"util": "./util.js"
24+
},
25+
"dependencies": {
26+
"conventional-changelog": "^1.1.4",
27+
"conventional-changelog-ui-router-core": "^1.4.1",
28+
"git-semver-tags": "^1.2.1",
29+
"readline-sync": "^1.4.7",
30+
"shelljs": "^0.7.8"
31+
}
32+
}

release.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!env node
2+
"use strict";
3+
4+
let version = require('../package.json').version;
5+
6+
require('shelljs/global');
7+
let readlineSync = require('readline-sync');
8+
let fs = require('fs');
9+
let path = require('path');
10+
let util = require('./util');
11+
let _exec = util._exec;
12+
13+
cd(path.join(__dirname, '..'));
14+
15+
if (!readlineSync.keyInYN('Did you bump the version number in package.json?')) {
16+
process.exit(1);
17+
}
18+
19+
if (!readlineSync.keyInYN('Did you update CHANGELOG.md using scripts/update_changelog.js?')) {
20+
process.exit(1);
21+
}
22+
23+
if (!readlineSync.keyInYN('Did you push all changes back to origin?')) {
24+
process.exit(1);
25+
}
26+
27+
if (!readlineSync.keyInYN('Ready to publish?')) {
28+
process.exit(1);
29+
}
30+
31+
util.ensureCleanMaster('master');
32+
33+
_exec('npm run package');
34+
35+
// publish to npm first
36+
_exec(`npm publish`);
37+
38+
// then tag and push tag
39+
_exec(`git tag ${version}`);
40+
_exec(`git push origin ${version}`);
41+
_exec(`npm run artifacts`);

show_changelog.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!env node
2+
"use strict";
3+
let conventionalChangelog = require('conventional-changelog');
4+
5+
let options = {
6+
preset: 'angular'
7+
};
8+
9+
if(require.main === module) {
10+
let context, gitOpts;
11+
12+
if (process.argv[2]) {
13+
context = {};
14+
gitOpts = {};
15+
context.previousTag = process.argv[2];
16+
gitOpts.from = process.argv[2];
17+
}
18+
19+
if (process.argv[3]) {
20+
context.currentTag = process.argv[3];
21+
}
22+
23+
showChangelog(context, gitOpts);
24+
}
25+
26+
function showChangelog(context, gitOpts) {
27+
conventionalChangelog(options, context, gitOpts).pipe(process.stdout);
28+
}

show_core_changelog.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!env node
2+
"use strict";
3+
4+
var gitSemverTags = require('git-semver-tags');
5+
var shelljs = require('shelljs');
6+
var path = require('path');
7+
var fs = require('fs');
8+
9+
var CORE_PKG = `@uirouter/core`;
10+
var ALT_CORE_PKG = `ui-router-core`;
11+
var CORE_DIR = path.join(__dirname, "..", "..", 'core');
12+
var SHOWCHANGELOG_SCRIPT = path.join(CORE_DIR, "scripts", "show_changelog.js");
13+
14+
var currentPackage = require('../package.json');
15+
if (!currentPackage.dependencies || (!currentPackage.dependencies[CORE_PKG] && !currentPackage[ALT_CORE_PKG])) {
16+
console.error(stringify(currentPackage.dependencies));
17+
throw new Error("No dependency on " + CORE_PKG + " found in package.json.")
18+
}
19+
20+
if (!fs.existsSync(CORE_DIR)) {
21+
throw new Error(CORE_PKG + " not found at " + path.resolve(CORE_DIR));
22+
}
23+
24+
if (!fs.existsSync(SHOWCHANGELOG_SCRIPT)) {
25+
throw new Error("show_changelog.js not found at " + path.resolve(SHOWCHANGELOG_SCRIPT));
26+
}
27+
28+
shelljs.config.silent = true;
29+
gitSemverTags(function (err, val) {
30+
var fromTag;
31+
if (require.main === module && process.argv[2]) {
32+
fromTag = process.argv[2];
33+
} else {
34+
var prevRaw = shelljs.exec('git show ' + val[0] + ':package.json', {silent:true}).stdout;
35+
var prevPackage;
36+
try {
37+
prevPackage = JSON.parse(prevRaw);
38+
} catch (error) {
39+
console.error("Unable to parse previous package.json in ${val[0]}");
40+
console.error(prevRaw);
41+
throw error;
42+
}
43+
44+
if (!prevPackage.dependencies) {
45+
console.error(stringify(prevPackage));
46+
throw new Error(`previous package.json in ${val[0]} has no "dependencies" key.`);
47+
} else if (!prevPackage.dependencies[CORE_PKG] && !prevPackage.dependencies[ALT_CORE_PKG]) {
48+
console.error(stringify(prevPackage.dependencies));
49+
throw new Error(`previous package.json in ${val[0]} has no "dependencies['${CORE_PKG}']" key.`);
50+
}
51+
52+
var prevDep = prevPackage.dependencies[CORE_PKG] || prevPackage.dependencies[ALT_CORE_PKG];
53+
fromTag = prevDep.replace(/[=~^]/, "");
54+
}
55+
56+
let pkg = require("../package.json");
57+
let currentDep = pkg.dependencies[CORE_PKG] || pkg.dependencies[ALT_CORE_PKG];
58+
var toTag = currentDep.replace(/[=~^]/g, "");
59+
60+
shelljs.pushd(CORE_DIR);
61+
// console.log("node " + SHOWCHANGELOG_SCRIPT + " " + fromTag + " " + toTag)
62+
shelljs.config.silent = false;
63+
shelljs.exec("node " + SHOWCHANGELOG_SCRIPT + " " + fromTag + " " + toTag)
64+
});
65+
66+
67+
function stringify(object) {
68+
return JSON.stringify(object, null, 2);
69+
}

update_changelog.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!env node
2+
"use strict";
3+
4+
require('shelljs/global');
5+
let path = require('path');
6+
let _exec = require('./util')._exec;
7+
8+
cd(path.resolve(__dirname, '..'));
9+
10+
echo('Updating CHANGELOG...');
11+
cp('CHANGELOG.md', 'CHANGELOG.bak');
12+
_exec('node ./scripts/show_changelog.js >> CHANGELOG.new');
13+
_exec('node ./scripts/show_core_changelog.js >> CHANGELOG.new');
14+
_exec('cat CHANGELOG.new CHANGELOG.bak > CHANGELOG.md');
15+
rm('CHANGELOG.bak', 'CHANGELOG.new');

util.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
3+
require('shelljs/global');
4+
let fs = require('fs');
5+
6+
function ensureCleanMaster(branch) {
7+
branch = branch || 'master';
8+
if (exec('git symbolic-ref HEAD').stdout.trim() !== `refs/heads/${branch}`)
9+
throw new Error(`Not on ${branch} branch, aborting`);
10+
if (exec('git status --porcelain').stdout.trim() !== '')
11+
throw new Error('Working copy is dirty, aborting');
12+
}
13+
14+
function _exec(command) {
15+
echo(command);
16+
echo();
17+
var result = exec(command);
18+
if (result.code === 0) return result;
19+
echo(`Aborting; non-zero return value (${result.code}) from: ${command}`);
20+
exit(result.code)
21+
}
22+
23+
function asJson (obj) { return JSON.stringify(obj, null, 2); }
24+
25+
let ensure = (type) => (path) => {
26+
let is = false;
27+
try { is = fs.lstatSync(path)['is' + type](); } catch (e) { console.log(e); }
28+
if (!is) echo(`Not a ${type}: ${path}`) && exit(-3);
29+
};
30+
let assertDir = ensure('Directory');
31+
let assertFile = ensure('File');
32+
33+
module.exports = {
34+
ensureCleanMaster: ensureCleanMaster,
35+
_exec: _exec,
36+
asJson: asJson,
37+
assertDir: assertDir,
38+
assertFile: assertFile
39+
};

0 commit comments

Comments
 (0)