Skip to content

Commit 832922d

Browse files
author
Robert Messerle
committed
chore(release): adds a script to automate the release process
1 parent e4ebd59 commit 832922d

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

release

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node --harmony release.js

release.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
var fs = require('fs');
2+
var prompt = require('prompt-sync');
3+
var child_process = require('child_process');
4+
var pkg = require('./package.json');
5+
var oldVersion = pkg.version;
6+
var newVersion = getNewVersion();
7+
8+
//-- do stuff
9+
checkoutVersionBranch();
10+
updateVersion();
11+
createChangelog();
12+
commitChanges();
13+
tagRelease();
14+
cloneBower();
15+
removeBower();
16+
17+
console.log('\n--------\n');
18+
console.log('Your repo is ready to be pushed.');
19+
console.log('Please look over CHANGELOG.md and amend-commit any changes.');
20+
21+
//-- utility methods
22+
function checkoutVersionBranch () {
23+
child_process.execSync(fill('git co -b v{{newVersion}}'));
24+
}
25+
26+
function updateVersion () {
27+
process.stdout.write(fill('Updating package.json version from {{oldVersion}} to {{newVersion}}...'));
28+
pkg.version = newVersion;
29+
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
30+
console.log('done.');
31+
}
32+
33+
function createChangelog () {
34+
process.stdout.write(fill('Generating changelog from v{{oldVersion}} to v{{newVersion}}...'));
35+
var cmd = fill('gulp changelog --sha=$(git merge-base v{{oldVersion}} HEAD)');
36+
child_process.execSync(cmd);
37+
console.log('done.');
38+
}
39+
40+
function clear () {
41+
process.stdout.write("\u001b[2J\u001b[0;0H");
42+
}
43+
44+
function getNewVersion () {
45+
clear();
46+
var options = getVersionOptions(oldVersion), key, type, version;
47+
console.log(fill('The current version is {{oldVersion}}.'));
48+
console.log('What type of release is this?');
49+
for (key in options) { console.log((+key + 1) + ') ' + options[key]); }
50+
process.stdout.write('Please select a new version: ');
51+
type = prompt();
52+
53+
if (options[type - 1]) version = options[type - 1];
54+
else if (type.match(/^\d+\.\d+\.\d+(-rc\d+)?$/)) version = type;
55+
else throw new Error('Your entry was invalid.');
56+
57+
clear();
58+
process.stdout.write('The new version will be ' + version + '. Is this correct? [yes/no] ');
59+
return prompt() === 'yes' ? version : getNewVersion();
60+
61+
function getVersionOptions (version) {
62+
return version.match(/-rc\d+$/)
63+
? [ increment(version, 'rc'),
64+
increment(version, 'minor') ]
65+
: [ increment(version, 'rc'),
66+
increment(version, 'patch'),
67+
increment(version, 'minor'),
68+
increment(version, 'major') ];
69+
70+
function increment (versionString, type) {
71+
var version = parseVersion(versionString);
72+
if (version.rc) {
73+
switch (type) {
74+
case 'minor': version.rc = 0; break;
75+
case 'rc': version.rc++; break;
76+
}
77+
} else {
78+
version[type]++;
79+
//-- reset any version numbers lower than the one changed
80+
switch (type) {
81+
case 'major': version.minor = 0;
82+
case 'minor': version.patch = 0;
83+
case 'patch': version.rc = 0;
84+
}
85+
}
86+
return getVersionString(version);
87+
88+
function parseVersion (version) {
89+
var parts = version.split(/\.|\-rc/g);
90+
return { string: version, major: parts[0], minor: parts[1], patch: parts[2], rc: parts[3] || 0 };
91+
}
92+
93+
function getVersionString(version) {
94+
var str = version.major + '.' + version.minor + '.' + version.patch;
95+
if (version.rc) str += '-rc' + version.rc;
96+
return str;
97+
}
98+
};
99+
}
100+
}
101+
102+
function tagRelease () {
103+
process.stdout.write('Tagging release...');
104+
child_process.execSync(fill('git tag v{{newVersion}}'));
105+
console.log('done.');
106+
}
107+
108+
function commitChanges () {
109+
process.stdout.write('Committing changes...');
110+
child_process.execSync(fill('git commit -am "release: version {{newVersion}}"'));
111+
console.log('done.');
112+
}
113+
114+
function removeBower () {
115+
process.stdout.write('Removing bower-material...');
116+
child_process.execSync('rm -rf bower-material');
117+
console.log('done.');
118+
}
119+
120+
function cloneBower () {
121+
process.stdout.write('Cloning bower-material from Github...');
122+
child_process.execSync('git clone https://github.com/angular/bower-material.git');
123+
console.log('done.');
124+
}
125+
126+
function fill(str) {
127+
return str.replace(/\{\{[^\}]+\}\}/g, function (match) {
128+
return eval(match.substr(2, match.length - 4));
129+
});
130+
}
131+
132+

reset

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
git co package.json CHANGELOG.md 2> /dev/null
2+
git co build 2> /dev/null
3+
git br -q -D v0.9.0-rc1 v0.9.1 v0.10.0 v1.0.0 2> /dev/null
4+
git tag -d v0.9.0-rc1 v0.9.1 v0.10.0 v1.0.0 2> /dev/null

0 commit comments

Comments
 (0)