2016-10-04 23:39:20 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2015-04-25 17:45:08 -04:00
|
|
|
'use strict';
|
|
|
|
|
2015-11-14 11:10:31 -05:00
|
|
|
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
|
|
|
|
// This is to ensure that we catch env issues before we error while requiring other dependencies.
|
2016-09-10 14:56:40 -04:00
|
|
|
require('./tools/check-environment')({
|
|
|
|
requiredNpmVersion: '>=3.5.3 <4.0.0',
|
2016-09-19 14:37:44 -04:00
|
|
|
requiredNodeVersion: '>=5.4.1 <7.0.0',
|
2016-09-10 14:56:40 -04:00
|
|
|
});
|
2015-11-14 11:10:31 -05:00
|
|
|
|
2016-05-25 22:54:34 -04:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const path = require('path');
|
2016-06-20 18:25:55 -04:00
|
|
|
const os = require('os');
|
2015-11-27 02:45:40 -05:00
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// clang-format entry points
|
|
|
|
const srcsToFmt = [
|
2016-10-04 23:39:20 -04:00
|
|
|
'modules/@angular/**/*.{js,ts}',
|
|
|
|
'modules/benchmarks/**/*.{js,ts}',
|
|
|
|
'modules/e2e_util/**/*.{js,ts}',
|
|
|
|
'modules/playground/**/*.{js,ts}',
|
|
|
|
'tools/**/*.{js,ts}',
|
2016-09-10 14:56:40 -04:00
|
|
|
'!tools/public_api_guard/**/*.d.ts',
|
2016-10-04 23:39:20 -04:00
|
|
|
'./*.{js,ts}',
|
|
|
|
'!shims_for_IE.js',
|
2016-09-10 14:56:40 -04:00
|
|
|
];
|
2015-11-27 02:45:40 -05:00
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Check source code for formatting errors (clang-format)
|
2016-05-26 16:33:53 -04:00
|
|
|
gulp.task('format:enforce', () => {
|
2016-05-25 22:54:34 -04:00
|
|
|
const format = require('gulp-clang-format');
|
|
|
|
const clangFormat = require('clang-format');
|
|
|
|
return gulp.src(srcsToFmt).pipe(
|
2016-10-04 23:39:20 -04:00
|
|
|
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
|
2015-06-10 19:52:19 -04:00
|
|
|
});
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Format the source code with clang-format (see .clang-format)
|
2016-05-25 22:54:34 -04:00
|
|
|
gulp.task('format', () => {
|
|
|
|
const format = require('gulp-clang-format');
|
|
|
|
const clangFormat = require('clang-format');
|
2016-10-04 23:39:20 -04:00
|
|
|
return gulp.src(srcsToFmt, {base: '.'})
|
|
|
|
.pipe(format.format('file', clangFormat))
|
|
|
|
.pipe(gulp.dest('.'));
|
2016-05-25 22:54:34 -04:00
|
|
|
});
|
|
|
|
|
2016-06-22 14:28:40 -04:00
|
|
|
const entrypoints = [
|
|
|
|
'dist/packages-dist/core/index.d.ts',
|
2016-08-30 21:07:40 -04:00
|
|
|
'dist/packages-dist/core/testing/index.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
'dist/packages-dist/common/index.d.ts',
|
2016-08-30 21:07:40 -04:00
|
|
|
'dist/packages-dist/common/testing/index.d.ts',
|
2016-06-27 15:27:23 -04:00
|
|
|
// The API surface of the compiler is currently unstable - all of the important APIs are exposed
|
|
|
|
// via @angular/core, @angular/platform-browser or @angular/platform-browser-dynamic instead.
|
|
|
|
//'dist/packages-dist/compiler/index.d.ts',
|
|
|
|
//'dist/packages-dist/compiler/testing.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
'dist/packages-dist/upgrade/index.d.ts',
|
2016-10-20 22:35:35 -04:00
|
|
|
'dist/packages-dist/upgrade/static.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
'dist/packages-dist/platform-browser/index.d.ts',
|
2016-08-30 21:07:40 -04:00
|
|
|
'dist/packages-dist/platform-browser/testing/index.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
'dist/packages-dist/platform-browser-dynamic/index.d.ts',
|
2016-08-30 21:07:40 -04:00
|
|
|
'dist/packages-dist/platform-browser-dynamic/testing/index.d.ts',
|
2016-08-30 14:15:25 -04:00
|
|
|
'dist/packages-dist/platform-webworker/index.d.ts',
|
|
|
|
'dist/packages-dist/platform-webworker-dynamic/index.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
'dist/packages-dist/platform-server/index.d.ts',
|
2016-08-30 21:07:40 -04:00
|
|
|
'dist/packages-dist/platform-server/testing/index.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
'dist/packages-dist/http/index.d.ts',
|
2016-08-30 21:07:40 -04:00
|
|
|
'dist/packages-dist/http/testing/index.d.ts',
|
2016-06-22 17:56:10 -04:00
|
|
|
'dist/packages-dist/forms/index.d.ts',
|
2016-09-10 14:56:40 -04:00
|
|
|
'dist/packages-dist/router/index.d.ts',
|
2016-06-22 14:28:40 -04:00
|
|
|
];
|
2016-07-05 23:52:35 -04:00
|
|
|
const publicApiDir = path.normalize('tools/public_api_guard');
|
2016-06-22 14:28:40 -04:00
|
|
|
const publicApiArgs = [
|
2016-10-04 23:39:20 -04:00
|
|
|
'--rootDir',
|
|
|
|
'dist/packages-dist',
|
|
|
|
'--stripExportPattern',
|
|
|
|
'^__',
|
|
|
|
'--allowModuleIdentifiers',
|
|
|
|
'jasmine',
|
|
|
|
'--allowModuleIdentifiers',
|
|
|
|
'protractor',
|
|
|
|
'--allowModuleIdentifiers',
|
|
|
|
'angular',
|
|
|
|
'--onStabilityMissing',
|
|
|
|
'error',
|
2016-06-22 14:28:40 -04:00
|
|
|
].concat(entrypoints);
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Build angular
|
2016-07-07 18:39:53 -04:00
|
|
|
gulp.task('build.sh', (done) => {
|
|
|
|
const childProcess = require('child_process');
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
childProcess.exec(path.join(__dirname, 'build.sh'), done);
|
2016-07-07 18:39:53 -04:00
|
|
|
});
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Enforce that the public API matches the golden files
|
2016-06-22 14:28:40 -04:00
|
|
|
// Note that these two commands work on built d.ts files instead of the source
|
|
|
|
gulp.task('public-api:enforce', (done) => {
|
2016-07-07 18:39:53 -04:00
|
|
|
const childProcess = require('child_process');
|
|
|
|
|
|
|
|
childProcess
|
2016-10-04 23:39:20 -04:00
|
|
|
.spawn(
|
|
|
|
path.join(__dirname, platformScriptPath(`/node_modules/.bin/ts-api-guardian`)),
|
|
|
|
['--verifyDir', publicApiDir].concat(publicApiArgs), {stdio: 'inherit'})
|
|
|
|
.on('close', (errorCode) => {
|
|
|
|
if (errorCode !== 0) {
|
|
|
|
done(new Error(
|
|
|
|
'Public API differs from golden file. Please run `gulp public-api:update`.'));
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
2016-06-22 14:28:40 -04:00
|
|
|
});
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Generate the public API golden files
|
2016-07-07 18:39:53 -04:00
|
|
|
gulp.task('public-api:update', ['build.sh'], (done) => {
|
|
|
|
const childProcess = require('child_process');
|
|
|
|
|
|
|
|
childProcess
|
2016-10-04 23:39:20 -04:00
|
|
|
.spawn(
|
|
|
|
path.join(__dirname, platformScriptPath(`/node_modules/.bin/ts-api-guardian`)),
|
|
|
|
['--outDir', publicApiDir].concat(publicApiArgs), {stdio: 'inherit'})
|
|
|
|
.on('close', done);
|
2016-06-22 14:28:40 -04:00
|
|
|
});
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Check the coding standards and programming errors
|
2017-01-24 17:44:19 -05:00
|
|
|
gulp.task('lint', ['format:enforce', 'tools:build'], () => {
|
2016-05-26 16:33:53 -04:00
|
|
|
const tslint = require('gulp-tslint');
|
|
|
|
// Built-in rules are at
|
2016-10-23 16:35:53 -04:00
|
|
|
// https://palantir.github.io/tslint/rules/
|
2016-05-26 16:33:53 -04:00
|
|
|
const tslintConfig = require('./tslint.json');
|
2016-10-04 23:39:20 -04:00
|
|
|
return gulp
|
|
|
|
.src([
|
|
|
|
// todo(vicb): add .js files when supported
|
|
|
|
// see https://github.com/palantir/tslint/pull/1515
|
2016-10-23 16:35:53 -04:00
|
|
|
'./modules/**/*.ts',
|
|
|
|
'./tools/**/*.ts',
|
2016-10-04 23:39:20 -04:00
|
|
|
'./*.ts',
|
2016-10-23 16:35:53 -04:00
|
|
|
|
|
|
|
// Ignore TypeScript mocks because it's not managed by us
|
|
|
|
'!./tools/@angular/tsc-wrapped/test/typescript.mocks.ts',
|
|
|
|
|
|
|
|
// Ignore generated files due to lack of copyright header
|
|
|
|
// todo(alfaproject): make generated files lintable
|
|
|
|
'!**/*.d.ts',
|
|
|
|
'!**/*.ngfactory.ts',
|
2016-10-04 23:39:20 -04:00
|
|
|
])
|
|
|
|
.pipe(tslint({
|
|
|
|
tslint: require('tslint').default,
|
|
|
|
configuration: tslintConfig,
|
|
|
|
formatter: 'prose',
|
|
|
|
}))
|
|
|
|
.pipe(tslint.report({emitError: true}));
|
2016-05-26 16:33:53 -04:00
|
|
|
});
|
|
|
|
|
2017-01-19 19:24:47 -05:00
|
|
|
gulp.task('validate-commit-messages', () => {
|
|
|
|
const validateCommitMessage = require('./tools/validate-commit-message');
|
|
|
|
const childProcess = require('child_process');
|
|
|
|
|
|
|
|
// We need to fetch origin explicitly because it might be stale.
|
|
|
|
// I couldn't find a reliable way to do this without fetch.
|
|
|
|
childProcess.exec(
|
|
|
|
'git fetch origin master && git log --reverse --format=%s HEAD ^origin/master',
|
|
|
|
(error, stdout, stderr) => {
|
|
|
|
if (error) {
|
|
|
|
console.log(stderr);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let someCommitsInvalid = false;
|
|
|
|
let commitsByLine = stdout.trim().split(/\n/);
|
|
|
|
|
|
|
|
console.log(`Examining ${commitsByLine.length} commits between HEAD and master`);
|
|
|
|
|
|
|
|
if (commitsByLine.length == 0) {
|
|
|
|
console.log('There are zero new commits between this HEAD and master');
|
|
|
|
}
|
|
|
|
|
|
|
|
someCommitsInvalid = !commitsByLine.every(validateCommitMessage);
|
|
|
|
|
|
|
|
if (someCommitsInvalid) {
|
|
|
|
console.log('Please fix the failing commit messages before continuing...');
|
|
|
|
console.log(
|
|
|
|
'Commit message guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-25 22:54:34 -04:00
|
|
|
gulp.task('tools:build', (done) => { tsc('tools/', done); });
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Check for circular dependency in the source code
|
2016-06-30 16:34:32 -04:00
|
|
|
gulp.task('check-cycle', (done) => {
|
2016-07-07 18:39:53 -04:00
|
|
|
const madge = require('madge');
|
2016-06-30 16:34:32 -04:00
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
const dependencyObject = madge(['dist/all/'], {
|
2016-06-30 16:34:32 -04:00
|
|
|
format: 'cjs',
|
|
|
|
extensions: ['.js'],
|
2016-10-04 23:39:20 -04:00
|
|
|
onParseFile: function(data) { data.src = data.src.replace(/\/\* circular \*\//g, '//'); }
|
2016-06-30 16:34:32 -04:00
|
|
|
});
|
2016-09-10 14:56:40 -04:00
|
|
|
const circularDependencies = dependencyObject.circular().getArray();
|
2016-06-30 16:34:32 -04:00
|
|
|
if (circularDependencies.length > 0) {
|
|
|
|
console.log('Found circular dependencies!');
|
|
|
|
console.log(circularDependencies);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
2015-04-27 18:24:32 -04:00
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Serve the built files
|
2016-05-24 15:33:14 -04:00
|
|
|
gulp.task('serve', () => {
|
2016-09-10 14:56:40 -04:00
|
|
|
const connect = require('gulp-connect');
|
|
|
|
const cors = require('cors');
|
2015-11-27 02:45:40 -05:00
|
|
|
|
2016-05-24 15:33:14 -04:00
|
|
|
connect.server({
|
|
|
|
root: `${__dirname}/dist`,
|
|
|
|
port: 8000,
|
|
|
|
livereload: false,
|
|
|
|
open: false,
|
2016-09-10 14:56:40 -04:00
|
|
|
middleware: (connect, opt) => [cors()],
|
2016-04-29 00:57:16 -04:00
|
|
|
});
|
2015-04-24 13:15:52 -04:00
|
|
|
});
|
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Serve the examples
|
2016-09-07 19:04:33 -04:00
|
|
|
gulp.task('serve-examples', () => {
|
2016-09-10 14:56:40 -04:00
|
|
|
const connect = require('gulp-connect');
|
|
|
|
const cors = require('cors');
|
2016-09-07 19:04:33 -04:00
|
|
|
|
|
|
|
connect.server({
|
2016-10-04 23:39:20 -04:00
|
|
|
root: `${__dirname}/dist/examples`,
|
|
|
|
port: 8001,
|
|
|
|
livereload: false,
|
|
|
|
open: false,
|
|
|
|
middleware: (connect, opt) => [cors()],
|
2016-09-07 19:04:33 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
|
2016-09-10 14:56:40 -04:00
|
|
|
// Update the changelog with the latest changes
|
2016-06-23 19:23:15 -04:00
|
|
|
gulp.task('changelog', () => {
|
|
|
|
const conventionalChangelog = require('gulp-conventional-changelog');
|
|
|
|
|
|
|
|
return gulp.src('CHANGELOG.md')
|
2016-10-04 23:39:20 -04:00
|
|
|
.pipe(conventionalChangelog({preset: 'angular', releaseCount: 1}, {
|
|
|
|
// Conventional Changelog Context
|
|
|
|
// We have to manually set version number so it doesn't get prefixed with `v`
|
|
|
|
// See https://github.com/conventional-changelog/conventional-changelog-core/issues/10
|
|
|
|
currentTag: require('./package.json').version
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./'));
|
2016-06-23 19:23:15 -04:00
|
|
|
});
|
|
|
|
|
2016-05-24 15:33:14 -04:00
|
|
|
function tsc(projectPath, done) {
|
2016-07-07 18:39:53 -04:00
|
|
|
const childProcess = require('child_process');
|
2015-02-20 20:44:23 -05:00
|
|
|
|
2016-07-07 18:39:53 -04:00
|
|
|
childProcess
|
2016-05-25 22:54:34 -04:00
|
|
|
.spawn(
|
2016-09-10 14:56:40 -04:00
|
|
|
path.normalize(platformScriptPath(`${__dirname}/node_modules/.bin/tsc`)),
|
2016-10-04 23:39:20 -04:00
|
|
|
['-p', path.join(__dirname, projectPath)], {stdio: 'inherit'})
|
2016-09-10 14:56:40 -04:00
|
|
|
.on('close', done);
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns the script path for the current platform
|
|
|
|
function platformScriptPath(path) {
|
|
|
|
return /^win/.test(os.platform()) ? `${path}.cmd` : path;
|
2015-08-27 13:39:39 -04:00
|
|
|
}
|