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.
|
|
|
|
require('./tools/check-environment')(
|
2016-05-25 22:54:34 -04:00
|
|
|
{requiredNpmVersion: '>=3.5.3 <4.0.0', requiredNodeVersion: '>=5.4.1 <6.0.0'});
|
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-06-22 14:28:40 -04:00
|
|
|
const srcsToFmt =
|
|
|
|
['tools/**/*.ts', 'modules/@angular/**/*.ts', '!tools/public_api_guard/**/*.d.ts'];
|
2015-11-27 02:45:40 -05:00
|
|
|
|
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-05-26 16:33:53 -04:00
|
|
|
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
|
2015-06-10 19:52:19 -04:00
|
|
|
});
|
|
|
|
|
2016-05-25 22:54:34 -04:00
|
|
|
gulp.task('format', () => {
|
|
|
|
const format = require('gulp-clang-format');
|
|
|
|
const clangFormat = require('clang-format');
|
|
|
|
return gulp.src(srcsToFmt, { base: '.' }).pipe(
|
|
|
|
format.format('file', clangFormat)).pipe(gulp.dest('.'));
|
|
|
|
});
|
|
|
|
|
2016-06-22 14:28:40 -04:00
|
|
|
const entrypoints = [
|
|
|
|
'dist/packages-dist/core/index.d.ts',
|
|
|
|
'dist/packages-dist/core/testing.d.ts',
|
|
|
|
'dist/packages-dist/common/index.d.ts',
|
|
|
|
'dist/packages-dist/common/testing.d.ts',
|
|
|
|
'dist/packages-dist/compiler/index.d.ts',
|
|
|
|
'dist/packages-dist/compiler/testing.d.ts',
|
|
|
|
'dist/packages-dist/upgrade/index.d.ts',
|
|
|
|
'dist/packages-dist/platform-browser/index.d.ts',
|
|
|
|
'dist/packages-dist/platform-browser/testing.d.ts',
|
|
|
|
'dist/packages-dist/platform-browser/testing_e2e.d.ts',
|
|
|
|
'dist/packages-dist/platform-browser-dynamic/index.d.ts',
|
|
|
|
'dist/packages-dist/platform-browser-dynamic/testing.d.ts',
|
|
|
|
'dist/packages-dist/platform-server/index.d.ts',
|
|
|
|
'dist/packages-dist/platform-server/testing.d.ts',
|
|
|
|
'dist/packages-dist/http/index.d.ts',
|
2016-06-22 17:56:10 -04:00
|
|
|
'dist/packages-dist/http/testing.d.ts',
|
|
|
|
'dist/packages-dist/forms/index.d.ts',
|
|
|
|
'dist/packages-dist/router/index.d.ts'
|
2016-06-22 14:28:40 -04:00
|
|
|
];
|
|
|
|
const publicApiDir = 'tools/public_api_guard';
|
|
|
|
const publicApiArgs = [
|
|
|
|
'--rootDir', 'dist/packages-dist',
|
|
|
|
'--stripExportPattern', '^__',
|
|
|
|
'--allowModuleIdentifiers', 'jasmine',
|
|
|
|
'--allowModuleIdentifiers', 'protractor',
|
|
|
|
'--allowModuleIdentifiers', 'angular'
|
|
|
|
].concat(entrypoints);
|
|
|
|
|
|
|
|
// Note that these two commands work on built d.ts files instead of the source
|
|
|
|
gulp.task('public-api:enforce', (done) => {
|
|
|
|
const child_process = require('child_process');
|
|
|
|
child_process
|
|
|
|
.spawn(
|
|
|
|
`${__dirname}/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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('public-api:update', (done) => {
|
|
|
|
const child_process = require('child_process');
|
|
|
|
child_process
|
|
|
|
.spawn(
|
|
|
|
`${__dirname}/node_modules/.bin/ts-api-guardian`,
|
|
|
|
['--outDir', publicApiDir].concat(publicApiArgs), {stdio: 'inherit'})
|
|
|
|
.on('close', (errorCode) => done(errorCode));
|
|
|
|
});
|
|
|
|
|
2016-05-26 16:33:53 -04:00
|
|
|
gulp.task('lint', ['format:enforce', 'tools:build'], () => {
|
|
|
|
const tslint = require('gulp-tslint');
|
|
|
|
// Built-in rules are at
|
|
|
|
// https://github.com/palantir/tslint#supported-rules
|
|
|
|
const tslintConfig = require('./tslint.json');
|
|
|
|
return gulp.src(['modules/@angular/**/*.ts', '!modules/@angular/*/test/**'])
|
|
|
|
.pipe(tslint({
|
|
|
|
tslint: require('tslint').default,
|
|
|
|
configuration: tslintConfig,
|
|
|
|
rulesDirectory: 'dist/tools/tslint'
|
|
|
|
}))
|
|
|
|
.pipe(tslint.report('prose', {emitError: true}));
|
|
|
|
});
|
|
|
|
|
2016-05-25 22:54:34 -04:00
|
|
|
gulp.task('tools:build', (done) => { tsc('tools/', done); });
|
|
|
|
|
2015-04-27 18:24:32 -04:00
|
|
|
|
2016-05-24 15:33:14 -04:00
|
|
|
gulp.task('serve', () => {
|
|
|
|
let connect = require('gulp-connect');
|
|
|
|
let 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-05-25 22:54:34 -04:00
|
|
|
middleware: (connect, opt) => [cors()]
|
2016-04-29 00:57:16 -04:00
|
|
|
});
|
2015-04-24 13:15:52 -04:00
|
|
|
});
|
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
|
2016-05-24 15:33:14 -04:00
|
|
|
function tsc(projectPath, done) {
|
|
|
|
let child_process = require('child_process');
|
2015-02-20 20:44:23 -05:00
|
|
|
|
2016-05-25 22:54:34 -04:00
|
|
|
child_process
|
|
|
|
.spawn(
|
2016-06-20 18:25:55 -04:00
|
|
|
path.normalize(`${__dirname}/node_modules/.bin/tsc`) + (/^win/.test(os.platform()) ? '.cmd' : ''),
|
|
|
|
['-p', path.join(__dirname, projectPath)],
|
2016-05-25 22:54:34 -04:00
|
|
|
{stdio: 'inherit'})
|
|
|
|
.on('close', (errorCode) => done(errorCode));
|
2015-08-27 13:39:39 -04:00
|
|
|
}
|