Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit e7f67e3

Browse files
update(builds): add release scripts
1 parent fa0c80e commit e7f67e3

File tree

6 files changed

+475
-242
lines changed

6 files changed

+475
-242
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@angular/core": "~2.4.0",
4343
"@angular/platform-browser": "~2.4.0",
4444
"@angular/platform-browser-dynamic": "~2.4.0",
45+
"@types/gulp-util": "^3.0.30",
4546
"ace-builds": "^1.2.5",
4647
"core-js": "^2.4.1",
4748
"es-module-loader": "^1.3.5",
@@ -86,6 +87,7 @@
8687
"browserstacktunnel-wrapper": "^2.0.0",
8788
"clang-format": "^1.0.45",
8889
"concurrently": "^2.2.0",
90+
"conventional-changelog": "^1.1.0",
8991
"copy-webpack-plugin": "^4.0.0",
9092
"css-loader": "^0.25.0",
9193
"extract-text-webpack-plugin": "^1.0.1",
@@ -98,6 +100,7 @@
98100
"gulp-clang-format": "^1.0.23",
99101
"gulp-clean": "^0.3.2",
100102
"gulp-cli": "^1.2.2",
103+
"gulp-conventional-changelog": "^1.1.0",
101104
"gulp-server-livereload": "^1.8.2",
102105
"gulp-shell": "^0.5.2",
103106
"gulp-sourcemaps": "^1.6.0",

release

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

release.js

+30-118
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
(function () {
22
'use strict';
33

4+
const SOURCE_REPO = 'flex-layout';
5+
const SOURCE_REPO_TITLE = 'Angular Flex-Layout';
6+
const BUILD_REPO = 'flex-layout-builds';
7+
48
var colors = require('colors');
59
var strip = require('cli-color/strip');
610
var fs = require('fs');
@@ -12,9 +16,9 @@
1216
var pushCmds = [ 'rm abort push' ];
1317
var cleanupCmds = [];
1418
var defaultOptions = { encoding: 'utf-8' };
15-
var origin = 'git@github.com:angular/material.git';
19+
var origin = 'git@github.com:angular/flex-layout.git';
1620
var lineWidth = 80;
17-
var lastMajorVer = JSON.parse(exec('curl https://material.angularjs.org/docs.json')).latest;
21+
var lastMajorVer = "2.0.0.-beta.1"; //JSON.parse(exec(`curl ${URL_VERSIONS}`)).latest;
1822
var newVersion;
1923
var dryRun;
2024

@@ -40,10 +44,8 @@
4044
createChangelog();
4145
commitChanges();
4246
tagRelease();
43-
cloneRepo('bower-material');
44-
updateBowerVersion();
45-
cloneRepo('code.material.angularjs.org');
46-
updateSite();
47+
cloneRepo(BUILD_REPO);
48+
generateLatestBuild();
4749
updateMaster();
4850
writeScript('abort', abortCmds.concat(cleanupCmds));
4951
if (!dryRun) writeScript('push', pushCmds.concat(cleanupCmds));
@@ -83,11 +85,24 @@
8385
/** writes the new version to package.json */
8486
function updateVersion () {
8587
start(`Updating ${"package.json".cyan} version from ${oldVersion.cyan} to ${newVersion.cyan}...`);
88+
89+
// Update the repo-root package.json
8690
pkg.version = newVersion;
8791
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
92+
93+
// update the package.json deploy to npm
94+
let npmPackagePath = './tools/scripts/release/npm_assets/package.json';
95+
pkg = require(npmPackagePath);
96+
pkg.version = newVersion;
97+
fs.writeFileSync(npmPackagePath, JSON.stringify(pkg, null, 2));
98+
8899
done();
100+
89101
abortCmds.push('git checkout package.json');
102+
abortCmds.push(`gig checkout ${npmPackagePath}`);
103+
90104
pushCmds.push('git add package.json');
105+
pushCmds.push(`git add ${npmPackagePath}`);
91106
}
92107

93108
/** generates the changelog from the commits since the last release */
@@ -208,39 +223,27 @@
208223
exec('chmod +x ' + name);
209224
}
210225

211-
/** updates the version for bower-material in package.json and bower.json */
212-
function updateBowerVersion () {
213-
start('Updating bower version...');
214-
var options = { cwd: './bower-material' },
215-
bower = require(options.cwd + '/bower.json'),
216-
pkg = require(options.cwd + '/package.json');
217-
//-- update versions in config files
218-
bower.version = pkg.version = newVersion;
219-
fs.writeFileSync(options.cwd + '/package.json', JSON.stringify(pkg, null, 2));
220-
fs.writeFileSync(options.cwd + '/bower.json', JSON.stringify(bower, null, 2));
221-
done();
222-
start('Building bower files...');
223-
//-- build files for bower
226+
/** updates the version for flex-layout-builds in package.json */
227+
function generateLatestBuild () {
228+
start('Building deployed files...');
224229
exec([
225230
'rm -rf dist',
226-
'gulp build',
227-
'gulp build-all-modules --mode=default',
228-
'gulp build-all-modules --mode=closure',
229-
'rm -rf dist/demos'
231+
'gulp build:release'
230232
]);
231233
done();
232-
start('Copy files into bower repo...');
233-
//-- copy files over to bower repo
234+
235+
start(`Copy files into ${BUILD_REPO} repo...`);
234236
exec([
235237
'cp -Rf ../dist/* ./',
236238
'git add -A',
237239
`git commit -m "release: version ${newVersion}"`,
238240
'rm -rf ../dist'
239241
], options);
240242
done();
243+
241244
//-- add steps to push script
242245
pushCmds.push(
243-
comment('push to bower (master and tag) and publish to npm'),
246+
comment('push to builds (master and tag) and publish to npm'),
244247
'cd ' + options.cwd,
245248
'cp ../CHANGELOG.md .',
246249
'git add CHANGELOG.md',
@@ -254,97 +257,6 @@
254257
);
255258
}
256259

257-
/** builds the website for the new version */
258-
function updateSite () {
259-
start('Adding new version of the docs site...');
260-
var options = { cwd: './code.material.angularjs.org' };
261-
writeDocsJson();
262-
263-
//-- build files for bower
264-
exec([
265-
'rm -rf dist',
266-
'gulp docs'
267-
]);
268-
replaceFilePaths();
269-
270-
//-- copy files over to site repo
271-
exec([
272-
`cp -Rf ../dist/docs ${newVersion}`,
273-
'rm -rf latest && cp -Rf ../dist/docs latest',
274-
'git add -A',
275-
`git commit -m "release: version ${newVersion}"`,
276-
'rm -rf ../dist'
277-
], options);
278-
replaceBaseHref(newVersion);
279-
replaceBaseHref('latest');
280-
281-
//-- update firebase.json file
282-
writeFirebaseJson();
283-
exec([ 'git commit --amend --no-edit -a' ], options);
284-
done();
285-
286-
//-- add steps to push script
287-
pushCmds.push(
288-
comment('push the site'),
289-
'cd ' + options.cwd,
290-
'git pull --rebase --strategy=ours',
291-
'git push',
292-
'cd ..'
293-
);
294-
295-
function writeFirebaseJson () {
296-
fs.writeFileSync(options.cwd + '/firebase.json', getFirebaseJson());
297-
function getFirebaseJson () {
298-
var json = require(options.cwd + '/firebase.json');
299-
json.rewrites = json.rewrites || [];
300-
switch (json.rewrites.length) {
301-
case 0:
302-
json.rewrites.push(getRewrite('HEAD'));
303-
case 1:
304-
json.rewrites.push(getRewrite('latest'));
305-
default:
306-
json.rewrites.push(getRewrite(newVersion));
307-
}
308-
return JSON.stringify(json, null, 2);
309-
function getRewrite (str) {
310-
return {
311-
source: '/' + str + '/**/!(*.@(js|html|css|json|svg|png|jpg|jpeg))',
312-
destination: '/' + str + '/index.html'
313-
};
314-
}
315-
}
316-
}
317-
318-
function writeDocsJson () {
319-
var config = require(options.cwd + '/docs.json');
320-
config.versions.unshift(newVersion);
321-
322-
//-- only set to default if not a release candidate
323-
config.latest = newVersion;
324-
fs.writeFileSync(options.cwd + '/docs.json', JSON.stringify(config, null, 2));
325-
}
326-
}
327-
328-
/** replaces localhost file paths with public URLs */
329-
function replaceFilePaths () {
330-
//-- handle docs.js
331-
var path = __dirname + '/dist/docs/docs.js';
332-
var file = fs.readFileSync(path);
333-
var contents = file.toString()
334-
.replace(/http:\/\/localhost:8080\/angular-material/g, 'https://cdn.gitcdn.link/cdn/angular/bower-material/v' + newVersion + '/angular-material')
335-
.replace(/http:\/\/localhost:8080\/docs.css/g, 'https://material.angularjs.org/' + newVersion + '/docs.css');
336-
fs.writeFileSync(path, contents);
337-
338-
}
339-
340-
/** replaces base href in index.html for new version as well as latest */
341-
function replaceBaseHref (folder) {
342-
//-- handle index.html
343-
var path = __dirname + '/code.material.angularjs.org/' + folder + '/index.html';
344-
var file = fs.readFileSync(path);
345-
var contents = file.toString().replace(/base href="\//g, 'base href="/' + folder + '/');
346-
fs.writeFileSync(path, contents);
347-
}
348260

349261
/** copies the changelog back over to master branch */
350262
function updateMaster () {
@@ -384,7 +296,7 @@
384296
function header () {
385297
clear();
386298
line();
387-
log(center('Angular Material Release'));
299+
log(center(`${SOURCE_REPO_TITLE} Release v${newVersion}`));
388300
line();
389301
}
390302

tools/gulp/gulpfile.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './tasks/changelog';
12
import './tasks/ci';
23
import './tasks/clean';
34
import './tasks/components';

tools/gulp/tasks/changelog.ts

+28-31
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
var fs = require('fs');
2-
var changelog = require('conventional-changelog');
3-
var addStream = require('add-stream');
4-
var spawnSync = require('child_process').spawnSync;
5-
var chalk = require('gulp-util').colors;
6-
var log = require('gulp-util').log;
7-
var path = require('path');
8-
var args = require('minimist')(process.argv.slice(2));
1+
import {src, task, dest} from 'gulp';
2+
import {spawnSync} from 'child_process';
3+
import path = require('path');
4+
import minimist = require('minimist');
5+
import gulpUtils = require('gulp-util');
96

10-
var SHA = args.sha;
11-
var ROOT = path.normalize(__dirname + '/../../..');
7+
let changelog = require('gulp-conventional-changelog');
128

13-
console.log(`Root = ${ROOT}`);
9+
const args = minimist(process.argv.slice(2));
10+
const chalk = gulpUtils.colors;
11+
const log = gulpUtils.log;
1412

15-
var VERSION = args.version || require(path.join(ROOT,'package.json')).version;
13+
const SHA = args['sha'] || args['SHA'];
14+
const ROOT = path.normalize(__dirname + '/../../..');
15+
const VERSION = args['version'] || require(path.join(ROOT,'package.json')).version;
1616

17-
exports.task = function () {
17+
/**
18+
* Expected `gulp changelog --sha=ad58e11`
19+
*/
20+
task('changelog', function() {
1821

1922
var changelogPath = path.join(ROOT, 'CHANGELOG.md');
20-
var inputStream = fs.createReadStream(changelogPath);
2123
var previousTag = getLatestTag();
2224
var currentTag = 'v' + VERSION;
23-
25+
var contextOptions = {
26+
version: VERSION,
27+
previousTag: previousTag.name,
28+
currentTag: currentTag
29+
};
2430
/* Validate different fork points for the changelog generation */
2531
if (previousTag.name === currentTag && !SHA) {
2632
log(chalk.yellow('Warning: You are generating a changelog by comparing the same versions.'));
@@ -31,24 +37,15 @@ exports.task = function () {
3137
log('Generating changelog from tag ' + previousTag.name + ' (' + shortSha + ')');
3238
}
3339

34-
var contextOptions = {
35-
version: VERSION,
36-
previousTag: previousTag.name,
37-
currentTag: currentTag
38-
};
39-
40-
/* Create our changelog and append the current changelog stream. */
41-
var changelogStream = changelog({ preset: 'angular' }, contextOptions, {
40+
return src(changelogPath, {
41+
buffer:false
42+
}).pipe(changelog({
43+
preset: 'angular'
44+
}, contextOptions, {
4245
from: SHA || previousTag.sha
43-
}).pipe(addStream(inputStream));
44-
45-
46-
/* Wait for the changelog to be ready and overwrite it. */
47-
inputStream.on('end', function() {
48-
changelogStream.pipe(fs.createWriteStream(changelogPath));
49-
});
46+
}).pipe(dest(ROOT)));
5047

51-
};
48+
});
5249

5350
/**
5451
* Resolves the latest tag over all branches from the repository metadata.

0 commit comments

Comments
 (0)