2018-01-18 12:44:09 -05:00
|
|
|
/* eslint-disable no-fallthrough */
|
2015-05-14 15:54:26 -07:00
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
2015-05-13 15:28:58 -07:00
|
|
|
|
2018-01-18 12:44:09 -05:00
|
|
|
const colors = require('colors');
|
|
|
|
|
const strip = require('cli-color/strip');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const path = require('path');
|
2019-05-31 12:45:54 -04:00
|
|
|
const prompt = require('prompt-sync')({sigint: true});
|
2018-01-18 12:44:09 -05:00
|
|
|
const child_process = require('child_process');
|
|
|
|
|
const pkg = require('./package.json');
|
2020-04-22 21:56:57 -04:00
|
|
|
const pkgLock = require('./package-lock.json');
|
2018-01-18 12:44:09 -05:00
|
|
|
let oldVersion = pkg.version;
|
2019-01-11 18:42:32 -05:00
|
|
|
const abortCmds = ['git reset --hard', 'git checkout staging', 'rm abort push'];
|
|
|
|
|
const pushCmds = ['rm abort push'];
|
2018-01-18 12:44:09 -05:00
|
|
|
const cleanupCmds = [];
|
|
|
|
|
const defaultOptions = { encoding: 'utf-8' };
|
|
|
|
|
const origin = 'git@github.com:angular/material.git';
|
|
|
|
|
const lineWidth = 80;
|
|
|
|
|
const lastMajorVer = JSON.parse(exec('curl https://material.angularjs.org/docs.json')).latest;
|
|
|
|
|
let newVersion;
|
2020-03-10 21:47:34 -04:00
|
|
|
let npmTag = 'latest';
|
2015-06-09 16:16:09 -07:00
|
|
|
|
2019-06-13 01:13:51 -04:00
|
|
|
try {
|
|
|
|
|
child_process.execSync('gulp --version', defaultOptions);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw new Error('Please install gulp globally via "npm i -g gulp@^3.9.1".');
|
|
|
|
|
}
|
2015-06-09 16:16:09 -07:00
|
|
|
header();
|
2019-05-31 12:45:54 -04:00
|
|
|
const dryRun = prompt(`Is this a dry-run? [${"yes".cyan}/no] `, 'yes') !== 'no';
|
2020-03-10 21:47:34 -04:00
|
|
|
npmTag = prompt(`What would you like the NPM tag to be? [${npmTag.cyan}/next] `, npmTag);
|
2015-06-09 16:16:09 -07:00
|
|
|
|
2015-06-09 16:54:37 -07:00
|
|
|
if (dryRun) {
|
2019-05-31 12:45:54 -04:00
|
|
|
oldVersion = prompt(`What would you like the old version to be? (default: ${oldVersion.cyan}) `, oldVersion);
|
2015-06-09 16:16:09 -07:00
|
|
|
build();
|
|
|
|
|
} else if (validate()) {
|
|
|
|
|
build();
|
|
|
|
|
}
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2015-06-09 16:16:09 -07:00
|
|
|
function build () {
|
2015-05-14 15:54:26 -07:00
|
|
|
newVersion = getNewVersion();
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2015-05-14 17:46:02 -07:00
|
|
|
line();
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
checkoutVersionBranch();
|
|
|
|
|
updateVersion();
|
|
|
|
|
createChangelog();
|
|
|
|
|
commitChanges();
|
|
|
|
|
tagRelease();
|
2015-05-14 17:46:02 -07:00
|
|
|
cloneRepo('bower-material');
|
2015-05-14 15:54:26 -07:00
|
|
|
updateBowerVersion();
|
2015-05-14 17:46:02 -07:00
|
|
|
cloneRepo('code.material.angularjs.org');
|
2015-05-14 15:54:26 -07:00
|
|
|
updateSite();
|
|
|
|
|
updateMaster();
|
2015-05-14 16:05:27 -07:00
|
|
|
writeScript('abort', abortCmds.concat(cleanupCmds));
|
2015-06-09 16:16:09 -07:00
|
|
|
if (!dryRun) writeScript('push', pushCmds.concat(cleanupCmds));
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2015-05-14 17:46:02 -07:00
|
|
|
line();
|
|
|
|
|
log('Your repo is ready to be pushed.');
|
2016-03-01 21:07:26 -08:00
|
|
|
log(`Please look over ${"CHANGELOG.md".cyan} and make any changes.`);
|
2020-04-22 21:56:57 -04:00
|
|
|
log(`When you are ready, please run "${"./push".green}" to finish the process.`);
|
|
|
|
|
log(`If you would like to cancel this release, please run "${"./abort".red}"`);
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
|
|
|
|
|
2019-01-11 18:15:27 -05:00
|
|
|
// utility methods
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** confirms that you will be able to perform the release before attempting */
|
2015-05-14 15:54:26 -07:00
|
|
|
function validate () {
|
2019-02-20 17:31:12 -08:00
|
|
|
if (exec('npm whoami') !== 'angular') {
|
|
|
|
|
err('You must be authenticated with npm as "angular" to perform a release.');
|
2015-08-11 09:56:39 -07:00
|
|
|
} else if (exec('git rev-parse --abbrev-ref HEAD') !== 'staging') {
|
|
|
|
|
err('Releases can only performed from "staging" at this time.');
|
2015-05-14 15:54:26 -07:00
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-05-15 05:34:54 -07:00
|
|
|
function err (msg) {
|
2018-01-18 12:44:09 -05:00
|
|
|
const str = 'Error: ' + msg;
|
2015-05-15 08:08:33 -07:00
|
|
|
log(str.red);
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-14 13:39:47 -07:00
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** creates the version branch and adds abort steps */
|
2015-05-14 15:54:26 -07:00
|
|
|
function checkoutVersionBranch () {
|
2016-03-01 21:07:26 -08:00
|
|
|
exec(`git branch -q -D release/${newVersion}`);
|
|
|
|
|
exec(`git checkout -q -b release/${newVersion}`);
|
2018-01-18 12:44:09 -05:00
|
|
|
abortCmds.push('git checkout master');
|
2016-03-01 21:07:26 -08:00
|
|
|
abortCmds.push(`git branch -D release/${newVersion}`);
|
2015-05-14 14:37:56 -07:00
|
|
|
}
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2020-04-22 21:56:57 -04:00
|
|
|
/** writes the new version to package.json and package-lock.json */
|
2015-05-14 15:54:26 -07:00
|
|
|
function updateVersion () {
|
2016-03-01 21:07:26 -08:00
|
|
|
start(`Updating ${"package.json".cyan} version from ${oldVersion.cyan} to ${newVersion.cyan}...`);
|
2015-05-14 15:54:26 -07:00
|
|
|
pkg.version = newVersion;
|
|
|
|
|
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
|
|
|
|
|
done();
|
2020-04-22 21:56:57 -04:00
|
|
|
start(`Updating ${"package-lock.json".cyan} version from ${oldVersion.cyan} to ${newVersion.cyan}...`);
|
|
|
|
|
pkgLock.version = newVersion;
|
|
|
|
|
fs.writeFileSync('./package-lock.json', JSON.stringify(pkgLock, null, 2));
|
|
|
|
|
done();
|
2015-05-14 15:54:26 -07:00
|
|
|
abortCmds.push('git checkout package.json');
|
2020-04-22 21:56:57 -04:00
|
|
|
abortCmds.push('git checkout package-lock.json');
|
2015-05-14 15:54:26 -07:00
|
|
|
pushCmds.push('git add package.json');
|
2020-04-22 21:56:57 -04:00
|
|
|
pushCmds.push('git add package-lock.json');
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** generates the changelog from the commits since the last release */
|
2015-05-14 15:54:26 -07:00
|
|
|
function createChangelog () {
|
2016-03-01 21:07:26 -08:00
|
|
|
start(`Generating changelog from ${oldVersion.cyan} to ${newVersion.cyan}...`);
|
|
|
|
|
|
2016-04-01 15:20:08 -07:00
|
|
|
exec(`git fetch --tags ${origin}`);
|
2018-04-27 16:38:59 -04:00
|
|
|
exec(`git checkout CHANGELOG.md`);
|
2016-03-01 21:07:26 -08:00
|
|
|
exec(`gulp changelog --sha=$(git merge-base v${lastMajorVer} HEAD)`);
|
|
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
done();
|
2016-03-01 21:07:26 -08:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
abortCmds.push('git checkout CHANGELOG.md');
|
|
|
|
|
pushCmds.push('git add CHANGELOG.md');
|
|
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** utility method for clearing the terminal */
|
2015-05-14 15:54:26 -07:00
|
|
|
function clear () {
|
2015-05-14 17:46:02 -07:00
|
|
|
write("\u001b[2J\u001b[0;0H");
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** prompts the user for the new version */
|
2015-05-14 15:54:26 -07:00
|
|
|
function getNewVersion () {
|
2015-06-09 16:16:09 -07:00
|
|
|
header();
|
2018-01-18 12:44:09 -05:00
|
|
|
const options = getVersionOptions(oldVersion);
|
|
|
|
|
let key, version;
|
2016-03-01 21:07:26 -08:00
|
|
|
log(`The current version is ${oldVersion.cyan}.`);
|
2015-05-14 17:46:02 -07:00
|
|
|
log('');
|
2015-06-09 16:16:09 -07:00
|
|
|
log('What should the next version be?');
|
2015-09-30 12:04:53 -07:00
|
|
|
for (key in options) { log((+key + 1) + ') ' + options[ key ].cyan); }
|
2015-05-14 17:46:02 -07:00
|
|
|
log('');
|
2019-05-31 12:45:54 -04:00
|
|
|
const type = prompt('Please select a new version: ');
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2015-09-30 12:04:53 -07:00
|
|
|
if (options[ type - 1 ]) version = options[ type - 1 ];
|
2016-06-03 10:38:39 -07:00
|
|
|
else if (type.match(/^\d+\.\d+\.\d+(-rc\.?\d+)?$/)) version = type;
|
2015-05-14 15:54:26 -07:00
|
|
|
else throw new Error('Your entry was invalid.');
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2015-05-14 17:46:02 -07:00
|
|
|
log('');
|
|
|
|
|
log('The new version will be ' + version.cyan + '.');
|
2019-05-31 12:45:54 -04:00
|
|
|
return prompt(`Is this correct? [${"yes".cyan}/no] `, 'yes') === 'yes' ? version : getNewVersion();
|
2015-05-13 15:28:58 -07:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
function getVersionOptions (version) {
|
2016-06-03 10:38:39 -07:00
|
|
|
return version.match(/-rc\.?\d+$/)
|
2019-05-31 12:45:54 -04:00
|
|
|
? [increment(version, 'rc'), increment(version, 'minor')]
|
|
|
|
|
: [increment(version, 'patch'), addRC(increment(version, 'minor'))];
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
function increment (versionString, type) {
|
2018-01-18 12:44:09 -05:00
|
|
|
const version = parseVersion(versionString);
|
2015-05-14 15:54:26 -07:00
|
|
|
if (version.rc) {
|
|
|
|
|
switch (type) {
|
2016-03-01 21:07:26 -08:00
|
|
|
case 'minor': version.rc = 0; break;
|
|
|
|
|
case 'rc': version.rc++; break;
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
2015-09-30 12:04:53 -07:00
|
|
|
version[ type ]++;
|
2019-01-11 18:15:27 -05:00
|
|
|
// reset any version numbers lower than the one changed
|
2015-05-14 15:54:26 -07:00
|
|
|
switch (type) {
|
2016-03-01 21:07:26 -08:00
|
|
|
case 'minor': version.patch = 0;
|
|
|
|
|
case 'patch': version.rc = 0;
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
return getVersionString(version);
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
function parseVersion (version) {
|
2018-01-18 12:44:09 -05:00
|
|
|
const parts = version.split(/-rc\.|\./g);
|
2015-09-30 12:04:53 -07:00
|
|
|
return {
|
|
|
|
|
string: version,
|
|
|
|
|
major: parts[ 0 ],
|
|
|
|
|
minor: parts[ 1 ],
|
|
|
|
|
patch: parts[ 2 ],
|
|
|
|
|
rc: parts[ 3 ] || 0
|
|
|
|
|
};
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2015-09-30 12:04:53 -07:00
|
|
|
function getVersionString (version) {
|
2018-01-18 12:44:09 -05:00
|
|
|
let str = version.major + '.' + version.minor + '.' + version.patch;
|
2016-06-03 10:38:39 -07:00
|
|
|
if (version.rc) str += '-rc.' + version.rc;
|
2015-05-14 15:54:26 -07:00
|
|
|
return str;
|
|
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
}
|
2015-06-09 16:16:09 -07:00
|
|
|
|
|
|
|
|
function addRC (str) {
|
2016-06-03 10:38:39 -07:00
|
|
|
return str + '-rc.1';
|
2015-06-09 16:16:09 -07:00
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
}
|
|
|
|
|
|
2020-04-22 21:56:57 -04:00
|
|
|
/** adds git tag for release and pushes to GitHub */
|
2015-05-14 15:54:26 -07:00
|
|
|
function tagRelease () {
|
|
|
|
|
pushCmds.push(
|
2019-05-31 12:45:54 -04:00
|
|
|
`git tag v${newVersion} -f`,
|
|
|
|
|
`git push ${origin} HEAD`,
|
|
|
|
|
`git push --tags ${origin}`
|
2015-05-14 15:54:26 -07:00
|
|
|
);
|
|
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** amends the commit to include local changes (ie. changelog) */
|
2015-05-14 15:54:26 -07:00
|
|
|
function commitChanges () {
|
2015-05-14 17:46:02 -07:00
|
|
|
start('Committing changes...');
|
2020-04-22 21:56:57 -04:00
|
|
|
exec(`git commit -am "release: v${newVersion}"`);
|
2015-05-14 15:54:26 -07:00
|
|
|
done();
|
|
|
|
|
pushCmds.push('git commit --amend --no-edit');
|
|
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2020-04-22 21:56:57 -04:00
|
|
|
/** utility method for cloning GitHub repos */
|
2015-05-14 17:46:02 -07:00
|
|
|
function cloneRepo (repo) {
|
2020-04-22 21:56:57 -04:00
|
|
|
start(`Cloning ${repo.cyan} from GitHub...`);
|
2016-03-01 21:07:26 -08:00
|
|
|
exec(`rm -rf ${repo}`);
|
2016-04-15 14:44:02 -07:00
|
|
|
exec(`git clone git@github.com:angular/${repo}.git --depth=1`);
|
2015-05-14 15:54:26 -07:00
|
|
|
done();
|
2016-03-01 21:07:26 -08:00
|
|
|
cleanupCmds.push(`rm -rf ${repo}`);
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** writes an array of commands to a bash script */
|
2015-05-14 15:54:26 -07:00
|
|
|
function writeScript (name, cmds) {
|
2016-03-01 21:07:26 -08:00
|
|
|
fs.writeFileSync(name, '#!/usr/bin/env bash\n\n' + cmds.join('\n'));
|
2015-05-14 15:54:26 -07:00
|
|
|
exec('chmod +x ' + name);
|
|
|
|
|
}
|
2015-05-14 08:07:16 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** updates the version for bower-material in package.json and bower.json */
|
2015-05-14 15:54:26 -07:00
|
|
|
function updateBowerVersion () {
|
2020-04-22 21:56:57 -04:00
|
|
|
start(`Updating ${"bower-material".cyan} version...`);
|
2018-01-18 12:44:09 -05:00
|
|
|
const options = { cwd: './bower-material' };
|
|
|
|
|
const bower = require(options.cwd + '/bower.json'),
|
|
|
|
|
pkg = require(options.cwd + '/package.json');
|
2019-01-11 18:15:27 -05:00
|
|
|
// update versions in config files
|
2015-05-14 15:54:26 -07:00
|
|
|
bower.version = pkg.version = newVersion;
|
|
|
|
|
fs.writeFileSync(options.cwd + '/package.json', JSON.stringify(pkg, null, 2));
|
|
|
|
|
fs.writeFileSync(options.cwd + '/bower.json', JSON.stringify(bower, null, 2));
|
|
|
|
|
done();
|
2020-04-22 21:56:57 -04:00
|
|
|
start(`Building ${"bower-material".cyan} files...`);
|
2019-01-11 18:15:27 -05:00
|
|
|
// build files for bower
|
2015-05-15 05:34:54 -07:00
|
|
|
exec([
|
2016-03-01 21:07:26 -08:00
|
|
|
'rm -rf dist',
|
|
|
|
|
'gulp build',
|
|
|
|
|
'gulp build-all-modules --mode=default',
|
|
|
|
|
'gulp build-all-modules --mode=closure',
|
2016-04-18 15:24:12 -05:00
|
|
|
'rm -rf dist/demos'
|
2019-05-31 12:45:54 -04:00
|
|
|
]);
|
2015-05-14 15:54:26 -07:00
|
|
|
done();
|
2020-04-22 21:56:57 -04:00
|
|
|
start(`Copying files into ${"bower-material".cyan} repo...`);
|
2019-01-11 18:15:27 -05:00
|
|
|
// copy files over to bower repo
|
2015-05-15 05:34:54 -07:00
|
|
|
exec([
|
2019-05-31 12:45:54 -04:00
|
|
|
'cp -Rf ../dist/* ./',
|
|
|
|
|
'git add -A',
|
2020-04-22 21:56:57 -04:00
|
|
|
`git commit -am "release: v${newVersion}"`,
|
2019-05-31 12:45:54 -04:00
|
|
|
'rm -rf ../dist'
|
|
|
|
|
], options);
|
2015-05-14 15:54:26 -07:00
|
|
|
done();
|
2019-01-11 18:15:27 -05:00
|
|
|
// add steps to push script
|
2015-05-14 15:54:26 -07:00
|
|
|
pushCmds.push(
|
2020-04-22 21:56:57 -04:00
|
|
|
comment(`push to bower-material (master and tag) and publish to npm as '${npmTag}'`),
|
2016-03-01 21:07:26 -08:00
|
|
|
'cd ' + options.cwd,
|
|
|
|
|
'cp ../CHANGELOG.md .',
|
|
|
|
|
'git add CHANGELOG.md',
|
|
|
|
|
'git commit --amend --no-edit',
|
|
|
|
|
`git tag -f v${newVersion}`,
|
|
|
|
|
'git pull --rebase --strategy=ours',
|
|
|
|
|
'git push',
|
|
|
|
|
'git push --tags',
|
2019-04-01 14:00:00 -05:00
|
|
|
'rm -rf .git/',
|
2020-03-10 21:47:34 -04:00
|
|
|
`npm publish --tag ${npmTag}`,
|
2016-03-01 21:07:26 -08:00
|
|
|
'cd ..'
|
2015-05-14 15:54:26 -07:00
|
|
|
);
|
|
|
|
|
}
|
2015-05-07 14:51:02 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** builds the website for the new version */
|
2015-05-14 15:54:26 -07:00
|
|
|
function updateSite () {
|
2015-05-14 17:46:02 -07:00
|
|
|
start('Adding new version of the docs site...');
|
2018-01-18 12:44:09 -05:00
|
|
|
const options = { cwd: './code.material.angularjs.org' };
|
2015-09-30 12:04:53 -07:00
|
|
|
writeDocsJson();
|
|
|
|
|
|
2019-01-11 18:15:27 -05:00
|
|
|
// build files for bower
|
2015-05-15 05:34:54 -07:00
|
|
|
exec([
|
2019-05-31 12:45:54 -04:00
|
|
|
'rm -rf dist',
|
|
|
|
|
'gulp docs'
|
2016-01-15 19:58:59 -08:00
|
|
|
]);
|
|
|
|
|
replaceFilePaths();
|
2015-06-22 11:01:14 -05:00
|
|
|
|
2019-01-11 18:15:27 -05:00
|
|
|
// copy files over to site repo
|
2015-05-15 05:34:54 -07:00
|
|
|
exec([
|
2019-05-31 12:45:54 -04:00
|
|
|
`cp -Rf ../dist/docs ${newVersion}`,
|
|
|
|
|
'rm -rf latest && cp -Rf ../dist/docs latest',
|
|
|
|
|
'git add -A',
|
2020-04-22 21:56:57 -04:00
|
|
|
`git commit -am "release: v${newVersion}"`,
|
|
|
|
|
`git tag -f v${newVersion}`,
|
2019-05-31 12:45:54 -04:00
|
|
|
'rm -rf ../dist'
|
2016-01-15 19:58:59 -08:00
|
|
|
], options);
|
|
|
|
|
replaceBaseHref(newVersion);
|
|
|
|
|
replaceBaseHref('latest');
|
2015-09-30 12:04:53 -07:00
|
|
|
|
2019-01-11 18:15:27 -05:00
|
|
|
// update firebase.json file
|
2017-03-13 18:05:11 -05:00
|
|
|
updateFirebaseJson();
|
2019-01-11 18:42:32 -05:00
|
|
|
exec(['git commit --amend --no-edit -a'], options);
|
2015-05-14 15:54:26 -07:00
|
|
|
done();
|
2015-09-30 12:04:53 -07:00
|
|
|
|
2019-01-11 18:15:27 -05:00
|
|
|
// add steps to push script
|
2015-05-14 15:54:26 -07:00
|
|
|
pushCmds.push(
|
2019-05-31 12:45:54 -04:00
|
|
|
comment('push the site'),
|
|
|
|
|
'cd ' + options.cwd,
|
|
|
|
|
'git pull --rebase --strategy=ours',
|
|
|
|
|
'git push',
|
2020-04-22 21:56:57 -04:00
|
|
|
'git push --tags',
|
2019-05-31 12:45:54 -04:00
|
|
|
'cd ..'
|
2015-05-14 15:54:26 -07:00
|
|
|
);
|
2015-09-30 12:04:53 -07:00
|
|
|
|
2017-03-13 18:05:11 -05:00
|
|
|
function updateFirebaseJson () {
|
2015-09-30 12:04:53 -07:00
|
|
|
fs.writeFileSync(options.cwd + '/firebase.json', getFirebaseJson());
|
|
|
|
|
function getFirebaseJson () {
|
2018-01-18 12:44:09 -05:00
|
|
|
const json = require(options.cwd + '/firebase.json');
|
2017-03-13 18:05:11 -05:00
|
|
|
json.hosting.rewrites = json.hosting.rewrites || [];
|
2018-01-18 12:44:09 -05:00
|
|
|
const rewrites = json.hosting.rewrites;
|
2017-03-13 18:05:11 -05:00
|
|
|
|
|
|
|
|
switch (rewrites.length) {
|
2015-09-30 12:04:53 -07:00
|
|
|
case 0:
|
2017-03-13 18:05:11 -05:00
|
|
|
rewrites.push(getRewrite('HEAD'));
|
2015-09-30 12:04:53 -07:00
|
|
|
case 1:
|
2017-03-13 18:05:11 -05:00
|
|
|
rewrites.push(getRewrite('latest'));
|
2015-09-30 12:04:53 -07:00
|
|
|
default:
|
2017-03-13 18:05:11 -05:00
|
|
|
rewrites.push(getRewrite(newVersion));
|
2015-09-30 12:04:53 -07:00
|
|
|
}
|
|
|
|
|
return JSON.stringify(json, null, 2);
|
|
|
|
|
function getRewrite (str) {
|
|
|
|
|
return {
|
|
|
|
|
source: '/' + str + '/**/!(*.@(js|html|css|json|svg|png|jpg|jpeg))',
|
|
|
|
|
destination: '/' + str + '/index.html'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeDocsJson () {
|
2018-01-18 12:44:09 -05:00
|
|
|
const config = require(options.cwd + '/docs.json');
|
2015-09-30 12:04:53 -07:00
|
|
|
config.versions.unshift(newVersion);
|
|
|
|
|
|
2019-01-11 18:15:27 -05:00
|
|
|
// only set to default if not a release candidate
|
2015-10-29 16:24:26 -07:00
|
|
|
config.latest = newVersion;
|
2015-09-30 12:04:53 -07:00
|
|
|
fs.writeFileSync(options.cwd + '/docs.json', JSON.stringify(config, null, 2));
|
|
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
}
|
2015-05-14 11:43:35 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** replaces localhost file paths with public URLs */
|
|
|
|
|
function replaceFilePaths () {
|
2019-01-11 18:15:27 -05:00
|
|
|
// handle docs.js
|
2018-01-18 12:44:09 -05:00
|
|
|
const filePath = path.join(__dirname, '/dist/docs/docs.js');
|
|
|
|
|
const file = fs.readFileSync(filePath);
|
|
|
|
|
const contents = file.toString()
|
2019-04-01 11:02:32 -05:00
|
|
|
.replace(/http:\/\/localhost:8080\/angular-material/g, 'https://gitcdn.xyz/cdn/angular/bower-material/v' + newVersion + '/angular-material')
|
2016-02-04 14:09:14 -06:00
|
|
|
.replace(/http:\/\/localhost:8080\/docs.css/g, 'https://material.angularjs.org/' + newVersion + '/docs.css');
|
2018-01-18 12:44:09 -05:00
|
|
|
fs.writeFileSync(filePath, contents);
|
2016-01-15 19:58:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** replaces base href in index.html for new version as well as latest */
|
|
|
|
|
function replaceBaseHref (folder) {
|
2019-01-11 18:15:27 -05:00
|
|
|
// handle index.html
|
2018-01-18 12:44:09 -05:00
|
|
|
const filePath = path.join(__dirname, '/code.material.angularjs.org/', folder, '/index.html');
|
|
|
|
|
const file = fs.readFileSync(filePath);
|
|
|
|
|
const contents = file.toString().replace(/base href="\//g, 'base href="/' + folder + '/');
|
|
|
|
|
fs.writeFileSync(filePath, contents);
|
2016-01-15 19:58:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** copies the changelog back over to master branch */
|
2015-05-14 15:54:26 -07:00
|
|
|
function updateMaster () {
|
|
|
|
|
pushCmds.push(
|
2019-05-31 12:45:54 -04:00
|
|
|
comment('update package.json in master'),
|
|
|
|
|
'git checkout master',
|
2020-07-23 19:02:44 -04:00
|
|
|
`git pull --rebase ${origin} master --strategy=recursive --strategy-option==theirs`,
|
2019-05-31 12:45:54 -04:00
|
|
|
`git checkout release/${newVersion} -- CHANGELOG.md`,
|
|
|
|
|
`node -e "const newVersion = '${newVersion}'; ${stringifyFunction(buildCommand)}"`,
|
|
|
|
|
'git add CHANGELOG.md',
|
|
|
|
|
'git add package.json',
|
|
|
|
|
`git commit -m "update version number in package.json to ${newVersion}"`,
|
|
|
|
|
`git push ${origin} master`
|
2015-05-14 15:54:26 -07:00
|
|
|
);
|
2016-03-01 21:07:26 -08:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
function buildCommand () {
|
|
|
|
|
require('fs').writeFileSync('package.json', JSON.stringify(getUpdatedJson(), null, 2));
|
|
|
|
|
function getUpdatedJson () {
|
2018-01-18 12:44:09 -05:00
|
|
|
const json = require('./package.json');
|
2016-03-01 21:07:26 -08:00
|
|
|
json.version = newVersion;
|
2015-05-14 15:54:26 -07:00
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-30 12:04:53 -07:00
|
|
|
|
2015-05-14 15:54:26 -07:00
|
|
|
function stringifyFunction (method) {
|
2015-05-15 05:34:54 -07:00
|
|
|
return method
|
2015-05-14 15:54:26 -07:00
|
|
|
.toString()
|
|
|
|
|
.split('\n')
|
|
|
|
|
.slice(1, -1)
|
|
|
|
|
.map(function (line) { return line.trim(); })
|
|
|
|
|
.join(' ')
|
2015-05-15 08:11:04 -07:00
|
|
|
.replace(/"/g, '\\"');
|
2015-05-14 11:43:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** utility method to output header */
|
2015-06-09 16:16:09 -07:00
|
|
|
function header () {
|
|
|
|
|
clear();
|
|
|
|
|
line();
|
2017-03-08 01:32:19 +02:00
|
|
|
log(center('AngularJS Material Release'));
|
2015-06-09 16:16:09 -07:00
|
|
|
line();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** outputs a centered message in the terminal */
|
2015-06-09 16:16:09 -07:00
|
|
|
function center (msg) {
|
2015-09-30 12:04:53 -07:00
|
|
|
msg = ' ' + msg.trim() + ' ';
|
2018-01-18 12:44:09 -05:00
|
|
|
const length = msg.length;
|
|
|
|
|
const spaces = Math.floor((lineWidth - length) / 2);
|
2015-06-09 16:16:09 -07:00
|
|
|
return Array(spaces + 1).join('-') + msg.green + Array(lineWidth - msg.length - spaces + 1).join('-');
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** outputs done text when a task is completed */
|
2015-05-14 15:54:26 -07:00
|
|
|
function done () {
|
2015-05-14 17:46:02 -07:00
|
|
|
log('done'.green);
|
2015-05-14 11:43:35 -07:00
|
|
|
}
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2019-06-13 01:13:51 -04:00
|
|
|
/**
|
|
|
|
|
* utility method for executing terminal commands while ignoring stderr
|
|
|
|
|
* @param {string|Array} cmd
|
|
|
|
|
* @param {Object=} userOptions
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2015-05-14 15:54:26 -07:00
|
|
|
function exec (cmd, userOptions) {
|
2015-05-15 05:34:54 -07:00
|
|
|
if (cmd instanceof Array) {
|
2015-05-15 08:08:33 -07:00
|
|
|
return cmd.map(function (cmd) { return exec(cmd, userOptions); });
|
2015-05-15 05:34:54 -07:00
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
try {
|
2018-01-18 12:44:09 -05:00
|
|
|
const options = Object.create(defaultOptions);
|
|
|
|
|
for (const key in userOptions) options[ key ] = userOptions[ key ];
|
2016-03-01 21:07:26 -08:00
|
|
|
return child_process.execSync(cmd + ' 2> /dev/null', options).toString().trim();
|
2015-05-14 15:54:26 -07:00
|
|
|
} catch (err) {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-14 13:39:47 -07:00
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** returns a commented message for use in bash scripts */
|
2015-05-14 15:54:26 -07:00
|
|
|
function comment (msg) {
|
|
|
|
|
return '\n# ' + msg + '\n';
|
2015-05-14 14:37:56 -07:00
|
|
|
}
|
2015-05-14 15:42:05 -07:00
|
|
|
|
2018-01-18 12:44:09 -05:00
|
|
|
/**
|
|
|
|
|
* prints the left side of a task while it is being performed
|
|
|
|
|
*/
|
2015-05-14 17:46:02 -07:00
|
|
|
function start (msg) {
|
2018-01-18 12:44:09 -05:00
|
|
|
const msgLength = strip(msg).length,
|
|
|
|
|
diff = lineWidth - 4 - msgLength;
|
2016-03-01 21:07:26 -08:00
|
|
|
write(msg + Array(diff + 1).join(' '));
|
2015-05-14 17:46:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** outputs to the terminal with string variable replacement */
|
2015-05-14 17:46:02 -07:00
|
|
|
function log (msg) {
|
2015-06-09 16:16:09 -07:00
|
|
|
msg = msg || '';
|
2016-03-01 21:07:26 -08:00
|
|
|
console.log(msg);
|
2015-05-14 17:46:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** writes a message without a newline */
|
2015-05-14 17:46:02 -07:00
|
|
|
function write (msg) {
|
2016-03-01 21:07:26 -08:00
|
|
|
process.stdout.write(msg);
|
2015-05-14 17:46:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 19:58:59 -08:00
|
|
|
/** prints a horizontal line to the terminal */
|
2015-05-14 17:46:02 -07:00
|
|
|
function line () {
|
|
|
|
|
log(Array(lineWidth + 1).join('-'));
|
|
|
|
|
}
|
2015-05-14 15:54:26 -07:00
|
|
|
})();
|