Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit c60d16b

Browse files
Robert MesserleThomasBurleson
authored andcommitted
fix(release): cleans up git commands used for release script
Closes #7369
1 parent 40be6ed commit c60d16b

File tree

1 file changed

+62
-74
lines changed

1 file changed

+62
-74
lines changed

release.js

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
var dryRun;
2020

2121
header();
22-
write('Is this a dry-run? {{"[yes/no]".cyan}} ');
22+
write(`Is this a dry-run? ${"[yes/no]".cyan} `);
2323
dryRun = prompt() !== 'no';
2424

2525
if (dryRun) {
26-
write('What would you like the old version to be? (default: {{oldVersion.cyan}}) ');
26+
write(`What would you like the old version to be? (default: ${oldVersion.cyan}) `);
2727
oldVersion = prompt() || oldVersion;
2828
build();
2929
} else if (validate()) {
@@ -50,8 +50,8 @@
5050

5151
line();
5252
log('Your repo is ready to be pushed.');
53-
log('Please look over {{"CHANGELOG.md".cyan}} and make any changes.');
54-
log('When you are ready, please run "{{"./push".cyan}}" to finish the process.');
53+
log(`Please look over ${"CHANGELOG.md".cyan} and make any changes.`);
54+
log(`When you are ready, please run "${"./push".cyan}" to finish the process.`);
5555
log('If you would like to cancel this release, please run "./abort"');
5656
}
5757

@@ -74,13 +74,14 @@
7474

7575
/** creates the version branch and adds abort steps */
7676
function checkoutVersionBranch () {
77-
exec('git checkout -q -b release/{{newVersion}}');
78-
abortCmds.push('git branch -D release/{{newVersion}}');
77+
exec(`git branch -q -D release/${newVersion}`);
78+
exec(`git checkout -q -b release/${newVersion}`);
79+
abortCmds.push(`git branch -D release/${newVersion}`);
7980
}
8081

8182
/** writes the new version to package.json */
8283
function updateVersion () {
83-
start('Updating {{"package.json".cyan}} version from {{oldVersion.cyan}} to {{newVersion.cyan}}...');
84+
start(`Updating ${"package.json".cyan} version from ${oldVersion.cyan} to ${newVersion.cyan}...`);
8485
pkg.version = newVersion;
8586
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
8687
done();
@@ -90,13 +91,14 @@
9091

9192
/** generates the changelog from the commits since the last release */
9293
function createChangelog () {
93-
start('Generating changelog from {{oldVersion.cyan}} to {{newVersion.cyan}}...');
94-
exec([
95-
'git fetch --tags',
96-
'git checkout v{{lastMajorVer}} -- CHANGELOG.md',
97-
'gulp changelog --sha=$(git merge-base v{{lastMajorVer}} HEAD)'
98-
]);
94+
start(`Generating changelog from ${oldVersion.cyan} to ${newVersion.cyan}...`);
95+
96+
exec('git fetch --tags');
97+
exec(`git checkout v${lastMajorVer} -- CHANGELOG.md`);
98+
exec(`gulp changelog --sha=$(git merge-base v${lastMajorVer} HEAD)`);
99+
99100
done();
101+
100102
abortCmds.push('git checkout CHANGELOG.md');
101103
pushCmds.push('git add CHANGELOG.md');
102104
}
@@ -110,7 +112,7 @@
110112
function getNewVersion () {
111113
header();
112114
var options = getVersionOptions(oldVersion), key, type, version;
113-
log('The current version is {{oldVersion.cyan}}.');
115+
log(`The current version is ${oldVersion.cyan}.`);
114116
log('');
115117
log('What should the next version be?');
116118
for (key in options) { log((+key + 1) + ') ' + options[ key ].cyan); }
@@ -124,7 +126,7 @@
124126

125127
log('');
126128
log('The new version will be ' + version.cyan + '.');
127-
write('Is this correct? {{"[yes/no]".cyan}} ');
129+
write(`Is this correct? ${"[yes/no]".cyan} `);
128130
return prompt() === 'yes' ? version : getNewVersion();
129131

130132
function getVersionOptions (version) {
@@ -136,21 +138,15 @@
136138
var version = parseVersion(versionString);
137139
if (version.rc) {
138140
switch (type) {
139-
case 'minor':
140-
version.rc = 0;
141-
break;
142-
case 'rc':
143-
version.rc++;
144-
break;
141+
case 'minor': version.rc = 0; break;
142+
case 'rc': version.rc++; break;
145143
}
146144
} else {
147145
version[ type ]++;
148146
//-- reset any version numbers lower than the one changed
149147
switch (type) {
150-
case 'minor':
151-
version.patch = 0;
152-
case 'patch':
153-
version.rc = 0;
148+
case 'minor': version.patch = 0;
149+
case 'patch': version.rc = 0;
154150
}
155151
}
156152
return getVersionString(version);
@@ -182,40 +178,32 @@
182178
/** adds git tag for release and pushes to github */
183179
function tagRelease () {
184180
pushCmds.push(
185-
'git tag v{{newVersion}}',
186-
'git push {{origin}} HEAD',
181+
`git tag v${newVersion} -f`,
182+
`git push ${origin} HEAD`,
187183
'git push --tags'
188184
);
189185
}
190186

191187
/** amends the commit to include local changes (ie. changelog) */
192188
function commitChanges () {
193189
start('Committing changes...');
194-
exec('git commit -am "release: version {{newVersion}}"');
190+
exec(`git commit -am "release: version ${newVersion}"`);
195191
done();
196192
pushCmds.push('git commit --amend --no-edit');
197193
}
198194

199195
/** utility method for cloning github repos */
200196
function cloneRepo (repo) {
201-
start('Cloning ' + repo.cyan + ' from Github...');
202-
exec('rm -rf ' + repo);
203-
exec('git clone https://github.com/angular/' + repo + '.git --depth=1');
197+
start(`Cloning ${repo.cyan} from Github...`);
198+
exec(`rm -rf ${repo}`);
199+
exec(`git clone https://github.com/angular/${repo}.git --depth=1`);
204200
done();
205-
cleanupCmds.push('rm -rf ' + repo);
206-
}
207-
208-
// TODO: Remove this method and use template strings instead
209-
/** utility method for inserting variables into a string */
210-
function fill (str) {
211-
return str.replace(/\{\{[^\}]+\}\}/g, function (match) {
212-
return eval(match.substr(2, match.length - 4));
213-
});
201+
cleanupCmds.push(`rm -rf ${repo}`);
214202
}
215203

216204
/** writes an array of commands to a bash script */
217205
function writeScript (name, cmds) {
218-
fs.writeFileSync(name, '#!/usr/bin/env bash\n\n' + fill(cmds.join('\n')));
206+
fs.writeFileSync(name, '#!/usr/bin/env bash\n\n' + cmds.join('\n'));
219207
exec('chmod +x ' + name);
220208
}
221209

@@ -233,35 +221,35 @@
233221
start('Building bower files...');
234222
//-- build files for bower
235223
exec([
236-
'rm -rf dist',
237-
'gulp build',
238-
'gulp build-all-modules --mode=default',
239-
'gulp build-all-modules --mode=closure',
240-
'rm -rf dist/demos',
241-
]);
224+
'rm -rf dist',
225+
'gulp build',
226+
'gulp build-all-modules --mode=default',
227+
'gulp build-all-modules --mode=closure',
228+
'rm -rf dist/demos',
229+
]);
242230
done();
243231
start('Copy files into bower repo...');
244232
//-- copy files over to bower repo
245233
exec([
246234
'cp -Rf ../dist/* ./',
247235
'git add -A',
248-
'git commit -m "release: version {{newVersion}}"',
236+
`git commit -m "release: version ${newVersion}"`,
249237
'rm -rf ../dist'
250238
], options);
251239
done();
252240
//-- add steps to push script
253241
pushCmds.push(
254-
comment('push to bower (master and tag) and publish to npm'),
255-
'cd ' + options.cwd,
256-
'cp ../CHANGELOG.md .',
257-
'git add CHANGELOG.md',
258-
'git commit --amend --no-edit',
259-
'git tag -f v{{newVersion}}',
260-
'git pull --rebase',
261-
'git push',
262-
'git push --tags',
263-
( newVersion.indexOf('rc') < 0 ? 'npm publish' : '# skipped npm publish due to RC version' ),
264-
'cd ..'
242+
comment('push to bower (master and tag) and publish to npm'),
243+
'cd ' + options.cwd,
244+
'cp ../CHANGELOG.md .',
245+
'git add CHANGELOG.md',
246+
'git commit --amend --no-edit',
247+
`git tag -f v${newVersion}`,
248+
'git pull --rebase --strategy=ours',
249+
'git push',
250+
'git push --tags',
251+
( newVersion.indexOf('rc') < 0 ? 'npm publish' : '# skipped npm publish due to RC version' ),
252+
'cd ..'
265253
);
266254
}
267255

@@ -281,10 +269,10 @@
281269
//-- copy files over to site repo
282270
exec([
283271
'rm -rf ./*-rc*',
284-
'cp -Rf ../dist/docs {{newVersion}}',
272+
`cp -Rf ../dist/docs ${newVersion}`,
285273
'rm -rf latest && cp -Rf ../dist/docs latest',
286274
'git add -A',
287-
'git commit -m "release: version {{newVersion}}"',
275+
`git commit -m "release: version ${newVersion}"`,
288276
'rm -rf ../dist'
289277
], options);
290278
replaceBaseHref(newVersion);
@@ -365,20 +353,21 @@
365353
function updateMaster () {
366354
pushCmds.push(
367355
comment('update package.json in master'),
368-
'git co master',
369-
'git pull --rebase {{origin}} master',
370-
'git checkout release/{{newVersion}} -- CHANGELOG.md',
371-
'node -e "' + stringifyFunction(buildCommand) + '"',
356+
'git checkout master',
357+
`git pull --rebase ${origin} master --strategy=theirs`,
358+
`git checkout release/${newVersion} -- CHANGELOG.md`,
359+
`node -e "${stringifyFunction(buildCommand)}"`,
372360
'git add CHANGELOG.md',
373361
'git add package.json',
374-
'git commit -m "update version number in package.json to {{newVersion}}"',
362+
`git commit -m "update version number in package.json to ${newVersion}"`,
375363
'git push'
376364
);
365+
377366
function buildCommand () {
378367
require('fs').writeFileSync('package.json', JSON.stringify(getUpdatedJson(), null, 2));
379368
function getUpdatedJson () {
380-
var json = require('./package.json');
381-
json.version = '{{newVersion}}';
369+
var json = require('./package.json');
370+
json.version = newVersion;
382371
return json;
383372
}
384373
}
@@ -423,7 +412,7 @@
423412
try {
424413
var options = Object.create(defaultOptions);
425414
for (var key in userOptions) options[ key ] = userOptions[ key ];
426-
return child_process.execSync(fill(cmd) + ' 2> /dev/null', options).toString().trim();
415+
return child_process.execSync(cmd + ' 2> /dev/null', options).toString().trim();
427416
} catch (err) {
428417
return err;
429418
}
@@ -436,21 +425,20 @@
436425

437426
/** prints the left side of a task while it is being performed */
438427
function start (msg) {
439-
var parsedMsg = fill(msg),
440-
msgLength = strip(parsedMsg).length,
428+
var msgLength = strip(msg).length,
441429
diff = lineWidth - 4 - msgLength;
442-
write(parsedMsg + Array(diff + 1).join(' '));
430+
write(msg + Array(diff + 1).join(' '));
443431
}
444432

445433
/** outputs to the terminal with string variable replacement */
446434
function log (msg) {
447435
msg = msg || '';
448-
console.log(fill(msg));
436+
console.log(msg);
449437
}
450438

451439
/** writes a message without a newline */
452440
function write (msg) {
453-
process.stdout.write(fill(msg));
441+
process.stdout.write(msg);
454442
}
455443

456444
/** prints a horizontal line to the terminal */

0 commit comments

Comments
 (0)