| 
									
										
										
										
											2015-04-25 14:45:08 -07:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 08:10:31 -08: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 19:54:34 -07:00
										 |  |  |     {requiredNpmVersion: '>=3.5.3 <4.0.0', requiredNodeVersion: '>=5.4.1 <6.0.0'}); | 
					
						
							| 
									
										
										
										
											2015-11-14 08:10:31 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07:00
										 |  |  | const gulp = require('gulp'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2016-06-21 00:25:55 +02:00
										 |  |  | const os = require('os'); | 
					
						
							| 
									
										
										
										
											2015-11-26 23:45:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  | const srcsToFmt = | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |     ['tools/**/*.ts', 'modules/@angular/**/*.ts', '!tools/public_api_guard/**/*.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  |     'modules/playground/**/*.ts', 'modules/benchmarks/**/*.ts', 'modules/e2e_util/**/*.ts']; | 
					
						
							| 
									
										
										
										
											2015-11-26 23:45:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07:00
										 |  |  | gulp.task('format:enforce', () => { | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07:00
										 |  |  |   const format = require('gulp-clang-format'); | 
					
						
							|  |  |  |   const clangFormat = require('clang-format'); | 
					
						
							|  |  |  |   return gulp.src(srcsToFmt).pipe( | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07:00
										 |  |  |     format.checkFormat('file', clangFormat, {verbose: true, fail: true})); | 
					
						
							| 
									
										
										
										
											2015-06-10 16:52:19 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07: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 11:28:40 -07:00
										 |  |  | const entrypoints = [ | 
					
						
							|  |  |  |   'dist/packages-dist/core/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |   'dist/packages-dist/core/testing/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  |   'dist/packages-dist/common/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |   'dist/packages-dist/common/testing/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-06-27 12:27:23 -07: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 11:28:40 -07:00
										 |  |  |   'dist/packages-dist/upgrade/index.d.ts', | 
					
						
							|  |  |  |   'dist/packages-dist/platform-browser/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |   'dist/packages-dist/platform-browser/testing/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  |   'dist/packages-dist/platform-browser-dynamic/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |   'dist/packages-dist/platform-browser-dynamic/testing/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 11:15:25 -07:00
										 |  |  |   'dist/packages-dist/platform-webworker/index.d.ts', | 
					
						
							|  |  |  |   'dist/packages-dist/platform-webworker-dynamic/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  |   'dist/packages-dist/platform-server/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |   'dist/packages-dist/platform-server/testing/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  |   'dist/packages-dist/http/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |   'dist/packages-dist/http/testing/index.d.ts', | 
					
						
							| 
									
										
										
										
											2016-06-22 14:56:10 -07:00
										 |  |  |   'dist/packages-dist/forms/index.d.ts', | 
					
						
							|  |  |  |   'dist/packages-dist/router/index.d.ts' | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  | ]; | 
					
						
							| 
									
										
										
										
											2016-07-06 05:52:35 +02:00
										 |  |  | const publicApiDir = path.normalize('tools/public_api_guard'); | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  | const publicApiArgs = [ | 
					
						
							|  |  |  |   '--rootDir', 'dist/packages-dist', | 
					
						
							|  |  |  |   '--stripExportPattern', '^__', | 
					
						
							|  |  |  |   '--allowModuleIdentifiers', 'jasmine', | 
					
						
							|  |  |  |   '--allowModuleIdentifiers', 'protractor', | 
					
						
							| 
									
										
										
										
											2016-06-27 10:02:02 -07:00
										 |  |  |   '--allowModuleIdentifiers', 'angular', | 
					
						
							| 
									
										
										
										
											2016-06-27 12:27:23 -07:00
										 |  |  |   '--onStabilityMissing', 'error' | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  | ].concat(entrypoints); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 15:39:53 -07:00
										 |  |  | gulp.task('build.sh', (done) => { | 
					
						
							|  |  |  |   const childProcess = require('child_process'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   childProcess.exec(path.join(__dirname, 'build.sh'), error => done(error)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07: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 15:39:53 -07:00
										 |  |  |   const childProcess = require('child_process'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   childProcess | 
					
						
							|  |  |  |     .spawn( | 
					
						
							|  |  |  |       path.join(__dirname, `/node_modules/.bin/ts-api-guardian${/^win/.test(os.platform()) ? '.cmd' : ''}`), | 
					
						
							|  |  |  |       ['--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 11:28:40 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 15:39:53 -07:00
										 |  |  | gulp.task('public-api:update', ['build.sh'], (done) => { | 
					
						
							|  |  |  |   const childProcess = require('child_process'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   childProcess | 
					
						
							|  |  |  |     .spawn( | 
					
						
							|  |  |  |       path.join(__dirname, `/node_modules/.bin/ts-api-guardian${/^win/.test(os.platform()) ? '.cmd' : ''}`), | 
					
						
							|  |  |  |       ['--outDir', publicApiDir].concat(publicApiArgs), {stdio: 'inherit'}) | 
					
						
							|  |  |  |     .on('close', (errorCode) => done(errorCode)); | 
					
						
							| 
									
										
										
										
											2016-06-22 11:28:40 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07: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'); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |   return gulp.src(['modules/@angular/**/*.ts', 'modules/benchpress/**/*.ts']) | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07:00
										 |  |  |     .pipe(tslint({ | 
					
						
							|  |  |  |       tslint: require('tslint').default, | 
					
						
							|  |  |  |       configuration: tslintConfig, | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |       rulesDirectory: 'dist/tools/tslint', | 
					
						
							|  |  |  |       formatter: 'prose' | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07:00
										 |  |  |     })) | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  |     .pipe(tslint.report({emitError: true})); | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07:00
										 |  |  | gulp.task('tools:build', (done) => { tsc('tools/', done); }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-30 13:34:32 -07:00
										 |  |  | gulp.task('check-cycle', (done) => { | 
					
						
							| 
									
										
										
										
											2016-07-07 15:39:53 -07:00
										 |  |  |   const madge = require('madge'); | 
					
						
							| 
									
										
										
										
											2016-06-30 13:34:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   var dependencyObject = madge(['dist/all/'], { | 
					
						
							|  |  |  |     format: 'cjs', | 
					
						
							|  |  |  |     extensions: ['.js'], | 
					
						
							|  |  |  |     onParseFile: function(data) { data.src = data.src.replace(/\/\* circular \*\//g, "//"); } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   var circularDependencies = dependencyObject.circular().getArray(); | 
					
						
							|  |  |  |   if (circularDependencies.length > 0) { | 
					
						
							|  |  |  |     console.log('Found circular dependencies!'); | 
					
						
							|  |  |  |     console.log(circularDependencies); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   done(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2015-04-27 15:24:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-24 12:33:14 -07:00
										 |  |  | gulp.task('serve', () => { | 
					
						
							|  |  |  |   let connect = require('gulp-connect'); | 
					
						
							|  |  |  |   let cors = require('cors'); | 
					
						
							| 
									
										
										
										
											2015-11-26 23:45:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-24 12:33:14 -07:00
										 |  |  |   connect.server({ | 
					
						
							|  |  |  |     root: `${__dirname}/dist`, | 
					
						
							|  |  |  |     port: 8000, | 
					
						
							|  |  |  |     livereload: false, | 
					
						
							|  |  |  |     open: false, | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07:00
										 |  |  |     middleware: (connect, opt) => [cors()] | 
					
						
							| 
									
										
										
										
											2016-04-28 21:57:16 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-04-24 10:15:52 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 16:04:33 -07:00
										 |  |  | gulp.task('serve-examples', () => { | 
					
						
							|  |  |  |   let connect = require('gulp-connect'); | 
					
						
							|  |  |  |   let cors = require('cors'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   connect.server({ | 
					
						
							|  |  |  |       root: `${__dirname}/dist/examples`, | 
					
						
							|  |  |  |       port: 8001, | 
					
						
							|  |  |  |       livereload: false, | 
					
						
							|  |  |  |       open: false, | 
					
						
							|  |  |  |       middleware: (connect, opt) => [cors()] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-27 00:46:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 16:23:15 -07:00
										 |  |  | gulp.task('changelog', () => { | 
					
						
							|  |  |  |   const conventionalChangelog = require('gulp-conventional-changelog'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return gulp.src('CHANGELOG.md') | 
					
						
							|  |  |  |     .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-05-24 12:33:14 -07:00
										 |  |  | function tsc(projectPath, done) { | 
					
						
							| 
									
										
										
										
											2016-07-07 15:39:53 -07:00
										 |  |  |   const childProcess = require('child_process'); | 
					
						
							| 
									
										
										
										
											2015-02-20 17:44:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 15:39:53 -07:00
										 |  |  |   childProcess | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07:00
										 |  |  |       .spawn( | 
					
						
							| 
									
										
										
										
											2016-06-21 00:25:55 +02:00
										 |  |  |           path.normalize(`${__dirname}/node_modules/.bin/tsc`) + (/^win/.test(os.platform()) ? '.cmd' : ''), | 
					
						
							|  |  |  |           ['-p', path.join(__dirname, projectPath)], | 
					
						
							| 
									
										
										
										
											2016-05-25 19:54:34 -07:00
										 |  |  |           {stdio: 'inherit'}) | 
					
						
							|  |  |  |       .on('close', (errorCode) => done(errorCode)); | 
					
						
							| 
									
										
										
										
											2015-08-27 10:39:39 -07:00
										 |  |  | } |