Skip to content

Commit 115f0fa

Browse files
vicbalexeagle
authored andcommitted
refactor(gulpfile): cleanup, add comments
1 parent 734b8b8 commit 115f0fa

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

gulpfile.js

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,34 @@
22

33
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
44
// This is to ensure that we catch env issues before we error while requiring other dependencies.
5-
require('./tools/check-environment')(
6-
{requiredNpmVersion: '>=3.5.3 <4.0.0', requiredNodeVersion: '>=5.4.1 <6.0.0'});
7-
5+
require('./tools/check-environment')({
6+
requiredNpmVersion: '>=3.5.3 <4.0.0',
7+
requiredNodeVersion: '>=5.4.1 <6.0.0',
8+
});
89

910
const gulp = require('gulp');
1011
const path = require('path');
1112
const os = require('os');
1213

13-
const srcsToFmt =
14-
['tools/**/*.ts', 'modules/@angular/**/*.ts', '!tools/public_api_guard/**/*.d.ts',
15-
'modules/playground/**/*.ts', 'modules/benchmarks/**/*.ts', 'modules/e2e_util/**/*.ts'];
14+
// clang-format entry points
15+
const srcsToFmt = [
16+
'modules/@angular/**/*.ts',
17+
'modules/benchmarks/**/*.ts',
18+
'modules/e2e_util/**/*.ts',
19+
'modules/playground/**/*.ts',
20+
'tools/**/*.ts',
21+
'!tools/public_api_guard/**/*.d.ts',
22+
];
1623

24+
// Check source code for formatting errors (clang-format)
1725
gulp.task('format:enforce', () => {
1826
const format = require('gulp-clang-format');
1927
const clangFormat = require('clang-format');
2028
return gulp.src(srcsToFmt).pipe(
2129
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
2230
});
2331

32+
// Format the source code with clang-format (see .clang-format)
2433
gulp.task('format', () => {
2534
const format = require('gulp-clang-format');
2635
const clangFormat = require('clang-format');
@@ -49,7 +58,7 @@ const entrypoints = [
4958
'dist/packages-dist/http/index.d.ts',
5059
'dist/packages-dist/http/testing/index.d.ts',
5160
'dist/packages-dist/forms/index.d.ts',
52-
'dist/packages-dist/router/index.d.ts'
61+
'dist/packages-dist/router/index.d.ts',
5362
];
5463
const publicApiDir = path.normalize('tools/public_api_guard');
5564
const publicApiArgs = [
@@ -58,22 +67,24 @@ const publicApiArgs = [
5867
'--allowModuleIdentifiers', 'jasmine',
5968
'--allowModuleIdentifiers', 'protractor',
6069
'--allowModuleIdentifiers', 'angular',
61-
'--onStabilityMissing', 'error'
70+
'--onStabilityMissing', 'error',
6271
].concat(entrypoints);
6372

73+
// Build angular
6474
gulp.task('build.sh', (done) => {
6575
const childProcess = require('child_process');
6676

67-
childProcess.exec(path.join(__dirname, 'build.sh'), error => done(error));
77+
childProcess.exec(path.join(__dirname, 'build.sh'), done);
6878
});
6979

80+
// Enforce that the public API matches the golden files
7081
// Note that these two commands work on built d.ts files instead of the source
7182
gulp.task('public-api:enforce', (done) => {
7283
const childProcess = require('child_process');
7384

7485
childProcess
7586
.spawn(
76-
path.join(__dirname, `/node_modules/.bin/ts-api-guardian${/^win/.test(os.platform()) ? '.cmd' : ''}`),
87+
path.join(__dirname, pfScriptPath(`/node_modules/.bin/ts-api-guardian`)),
7788
['--verifyDir', publicApiDir].concat(publicApiArgs), {stdio: 'inherit'})
7889
.on('close', (errorCode) => {
7990
if (errorCode !== 0) {
@@ -85,17 +96,19 @@ gulp.task('public-api:enforce', (done) => {
8596
});
8697
});
8798

99+
// Generate the public API golden files
88100
gulp.task('public-api:update', ['build.sh'], (done) => {
89101
const childProcess = require('child_process');
90102

91103
childProcess
92104
.spawn(
93-
path.join(__dirname, `/node_modules/.bin/ts-api-guardian${/^win/.test(os.platform()) ? '.cmd' : ''}`),
105+
path.join(__dirname, pfScriptPath(`/node_modules/.bin/ts-api-guardian`)),
94106
['--outDir', publicApiDir].concat(publicApiArgs), {stdio: 'inherit'})
95-
.on('close', (errorCode) => done(errorCode));
107+
.on('close', done);
96108
});
97109

98-
gulp.task('lint', ['format:enforce', 'tools:build'], () => {
110+
// Check the coding standards and programming errors
111+
gulp.task('lint', [ 'format:enforce', 'tools:build'], () => {
99112
const tslint = require('gulp-tslint');
100113
// Built-in rules are at
101114
// https://github.com/palantir/tslint#supported-rules
@@ -105,22 +118,23 @@ gulp.task('lint', ['format:enforce', 'tools:build'], () => {
105118
tslint: require('tslint').default,
106119
configuration: tslintConfig,
107120
rulesDirectory: 'dist/tools/tslint',
108-
formatter: 'prose'
121+
formatter: 'prose',
109122
}))
110123
.pipe(tslint.report({emitError: true}));
111124
});
112125

113126
gulp.task('tools:build', (done) => { tsc('tools/', done); });
114127

128+
// Check for circular dependency in the source code
115129
gulp.task('check-cycle', (done) => {
116130
const madge = require('madge');
117131

118-
var dependencyObject = madge(['dist/all/'], {
132+
const dependencyObject = madge(['dist/all/'], {
119133
format: 'cjs',
120134
extensions: ['.js'],
121135
onParseFile: function(data) { data.src = data.src.replace(/\/\* circular \*\//g, "//"); }
122136
});
123-
var circularDependencies = dependencyObject.circular().getArray();
137+
const circularDependencies = dependencyObject.circular().getArray();
124138
if (circularDependencies.length > 0) {
125139
console.log('Found circular dependencies!');
126140
console.log(circularDependencies);
@@ -129,33 +143,36 @@ gulp.task('check-cycle', (done) => {
129143
done();
130144
});
131145

146+
// Serve the built files
132147
gulp.task('serve', () => {
133-
let connect = require('gulp-connect');
134-
let cors = require('cors');
148+
const connect = require('gulp-connect');
149+
const cors = require('cors');
135150

136151
connect.server({
137152
root: `${__dirname}/dist`,
138153
port: 8000,
139154
livereload: false,
140155
open: false,
141-
middleware: (connect, opt) => [cors()]
156+
middleware: (connect, opt) => [cors()],
142157
});
143158
});
144159

160+
// Serve the examples
145161
gulp.task('serve-examples', () => {
146-
let connect = require('gulp-connect');
147-
let cors = require('cors');
162+
const connect = require('gulp-connect');
163+
const cors = require('cors');
148164

149165
connect.server({
150166
root: `${__dirname}/dist/examples`,
151167
port: 8001,
152168
livereload: false,
153169
open: false,
154-
middleware: (connect, opt) => [cors()]
170+
middleware: (connect, opt) => [cors()],
155171
});
156172
});
157173

158174

175+
// Update the changelog with the latest changes
159176
gulp.task('changelog', () => {
160177
const conventionalChangelog = require('gulp-conventional-changelog');
161178

@@ -177,8 +194,13 @@ function tsc(projectPath, done) {
177194

178195
childProcess
179196
.spawn(
180-
path.normalize(`${__dirname}/node_modules/.bin/tsc`) + (/^win/.test(os.platform()) ? '.cmd' : ''),
197+
path.normalize(platformScriptPath(`${__dirname}/node_modules/.bin/tsc`)),
181198
['-p', path.join(__dirname, projectPath)],
182199
{stdio: 'inherit'})
183-
.on('close', (errorCode) => done(errorCode));
200+
.on('close', done);
201+
}
202+
203+
// returns the script path for the current platform
204+
function platformScriptPath(path) {
205+
return /^win/.test(os.platform()) ? `${path}.cmd` : path;
184206
}

0 commit comments

Comments
 (0)