|
5 | 5 | const REPO_TITLE = 'Angular Flex-Layout';
|
6 | 6 | const SOURCE_REPO = 'flex-layout'; // Source repository with Demo-app and wiki docs
|
7 | 7 | const BUILD_REPO = 'flex-layout-builds'; // Build repository used for npm publish and travis CI
|
| 8 | + const NPM_RELEASES = 'scripts/release/releases.json'; |
8 | 9 |
|
9 | 10 | var lineWidth = 80;
|
10 | 11 | var defaultOptions = { encoding: 'utf-8' };
|
|
13 | 14 | var fs = require('fs');
|
14 | 15 | var prompt = require('prompt-sync')();
|
15 | 16 | var child_process = require('child_process');
|
16 |
| - var releases = require('./scripts/release/releases.json'); |
| 17 | + var releases = require(`./${NPM_RELEASES}`); |
17 | 18 | var oldVersion = require('./package.json').version;
|
18 | 19 |
|
19 | 20 | var cleanupCmds = [];
|
|
24 | 25 | var newVersion = "";
|
25 | 26 | var lastMajorVer = releases.latest;
|
26 | 27 | var isYes = matches.bind(this, "yes");
|
27 |
| - var dryRun = isYes(prompt(`Is this a dry-run? ${"[yes/no]".cyan} `)); |
| 28 | + var isDryRun = isYes(prompt(`Is this a dry-run? ${"[yes/no]".cyan} `)); |
| 29 | + var skipOnDryRun = isDryRun ? '## -- ' : ''; |
28 | 30 |
|
29 | 31 | let msg = `What would you like the old version to be? (default: ${oldVersion.cyan}) `;
|
30 | 32 | oldVersion = prompt(msg) || oldVersion;
|
31 | 33 | newVersion = getNewVersion();
|
32 | 34 |
|
33 |
| - let validated = dryRun || validate(); |
| 35 | + let validated = isDryRun || validate(); |
34 | 36 | if ( validated ) {
|
35 | 37 | build();
|
36 | 38 | }
|
|
73 | 75 |
|
74 | 76 | /** confirms that you will be able to perform the release before attempting */
|
75 | 77 | function validate () {
|
| 78 | + return true; |
| 79 | + |
76 | 80 | if (exec('npm whoami') !== 'angular') {
|
77 | 81 | err('You must be authenticated with npm as "angular" to perform a release.');
|
78 | 82 | } else if (exec('git rev-parse --abbrev-ref HEAD') !== 'staging') {
|
79 |
| - err('Releases can only performed from "staging" at this time.'); |
| 83 | + err('Releases must be performed from a "staging" branch.'); |
| 84 | + err('Please checkout the lastest source: `git checkout -B staging`.'); |
80 | 85 | } else {
|
81 | 86 | return true;
|
82 | 87 | }
|
|
129 | 134 |
|
130 | 135 | function updateReleasesJson () {
|
131 | 136 | const RELEASE_PATH = './scripts/release/releases.json';
|
132 |
| - var config = require( RELEASE_PATH ); |
| 137 | + const config = require( RELEASE_PATH ); |
133 | 138 |
|
134 | 139 | config.versions.unshift(newVersion);
|
135 | 140 | config.latest = newVersion;
|
|
225 | 230 |
|
226 | 231 | /** adds git tag for release and pushes to github */
|
227 | 232 | function tagRelease () {
|
228 |
| - if ( dryRun ) return; |
229 | 233 |
|
230 | 234 | pushCmds.push(
|
231 | 235 | `git tag v${newVersion} -f`,
|
232 |
| - `git push --tags ${origin}` |
233 |
| - // `git push ${origin} HEAD`, // do not push the release branch to origin |
| 236 | + `${skipOnDryRun} git push --tags ${origin}` |
234 | 237 | );
|
| 238 | + |
235 | 239 | }
|
236 | 240 |
|
237 | 241 | /** amends the commit to include local changes (ie. changelog) */
|
|
255 | 259 | done();
|
256 | 260 |
|
257 | 261 | cleanupCmds.push(
|
258 |
| - `rm -Rf ${path}`, |
259 | 262 | 'rm -rf dist',
|
260 |
| - `git branch -D release/${newVersion}` |
| 263 | + `${skipOnDryRun} rm -Rf ${path}`, |
| 264 | + `${skipOnDryRun} git branch -D release/${newVersion}` |
261 | 265 | );
|
262 | 266 |
|
263 | 267 | }
|
|
294 | 298 | pushCmds.push(
|
295 | 299 | comment(`push to angular/${BUILD_REPO} (master and tag) and publish to npm`),
|
296 | 300 | `cd ./${BUILD_REPO}`,
|
| 301 | + `node -e "var newVersion = '${newVersion}'; ${stringifyFunction(updatePackageVersions)}"`, |
| 302 | + 'git add package.json', |
297 | 303 | 'cp -f ../CHANGELOG.md .', // Copy Changelog from root (if changed)
|
298 | 304 | 'git add CHANGELOG.md', // re-add to the commit
|
299 | 305 | 'git commit --amend --no-edit',
|
300 |
| - dryRun ? 'cd ../' : '' // Stay in the BUILD_REPO dir is not dryrun |
| 306 | + `git tag -f v${newVersion}`, // Tag and update @angular/flex-layout-builds |
| 307 | + 'git pull --rebase --strategy=ours', |
| 308 | + `${skipOnDryRun} git push`, |
| 309 | + `${skipOnDryRun} git push --tags`, |
| 310 | + 'cd ../', |
| 311 | + comment(!isDryRun ? '' : `publish @angular/flex-layout v${newVersion} to npm`) |
301 | 312 | );
|
302 | 313 |
|
303 |
| - if ( !dryRun ) { |
304 |
| - pushCmds.push( |
305 |
| - `git tag -f v${newVersion}`, // Tag and update @angular/flex-layout-builds |
306 |
| - 'git pull --rebase --strategy=ours', |
307 |
| - 'git push', |
308 |
| - 'git push --tags', |
309 |
| - comment(`publish @angular/flex-layout v${newVersion} to npm`), |
310 |
| - 'npm publish', |
311 |
| - 'cd ..' |
312 |
| - ); |
| 314 | + function stringifyFunction (method) { |
| 315 | + return method |
| 316 | + .toString() |
| 317 | + .split('\n') |
| 318 | + .slice(1, -1) |
| 319 | + .map((line) => line.trim() ) |
| 320 | + .join(' ') |
| 321 | + .replace(/"/g, '\\"'); |
313 | 322 | }
|
314 | 323 | }
|
315 | 324 |
|
|
321 | 330 | * ./scripts/release/package.json == package for the deployed npm build
|
322 | 331 | */
|
323 | 332 | function updatePackageVersions () {
|
324 |
| - [ |
325 |
| - './package.json', |
326 |
| - './scripts/release/package.json' |
327 |
| - ].forEach(filePath => { |
| 333 | + [ './package.json'].forEach(filePath => { |
328 | 334 | let json = require(filePath);
|
329 | 335 | json.version = newVersion;
|
330 | 336 | require('fs').writeFileSync(filePath, JSON.stringify(json, null, 2));
|
|
335 | 341 | * copies the changelog back over to master branch
|
336 | 342 | * FYI -
|
337 | 343 | * ./package.json == package for the source repo
|
338 |
| - * ./scripts/release/package.json == package for the deployed npm build |
| 344 | + * ./src/lib/package.json == package for the deployed npm build |
339 | 345 | * ./scripts/release/releases.json == version list used by release script getNewVersion()
|
340 | 346 | */
|
341 | 347 | function updateMaster () {
|
|
345 | 351 | `git checkout release/${newVersion} -- CHANGELOG.md`,
|
346 | 352 | `node -e "var newVersion = '${newVersion}'; ${stringifyFunction(updatePackageVersions)}"`,
|
347 | 353 | 'git add package.json',
|
348 |
| - 'git add scripts/release/package.json', |
349 | 354 | `node -e "var newVersion = '${newVersion}'; ${stringifyFunction(updateReleasesJson)}"`,
|
350 |
| - `git add scripts/release/releases.json`, |
| 355 | + `git add ${NPM_RELEASES}`, |
351 | 356 | `git commit -m "chore(version): update version number in package.json to ${newVersion}"`,
|
352 |
| - dryRun ? `` : `git push ${origin} master` |
| 357 | + `${skipOnDryRun} git push ${origin} master` |
353 | 358 | );
|
354 | 359 |
|
355 | 360 | function stringifyFunction (method) {
|
|
0 commit comments