|
1 | 1 | import * as gulp from 'gulp';
|
2 | 2 | import * as gulpLoadPlugins from 'gulp-load-plugins';
|
| 3 | +import * as merge from 'merge-stream'; |
| 4 | +import * as util from 'gulp-util'; |
3 | 5 | import { join } from 'path';
|
4 | 6 |
|
5 | 7 | import Config from '../../config';
|
6 | 8 | import { makeTsProject } from '../../utils';
|
| 9 | +import { TypeScriptTask } from '../typescript_task'; |
7 | 10 |
|
8 | 11 | const plugins = <any>gulpLoadPlugins();
|
9 | 12 |
|
| 13 | +let typedBuildCounter = Config.TYPED_COMPILE_INTERVAL; // Always start with the typed build. |
| 14 | + |
10 | 15 | /**
|
11 | 16 | * Executes the build process, transpiling the TypeScript files (excluding the spec and e2e-spec files) for the test
|
12 | 17 | * environment.
|
13 | 18 | */
|
14 |
| -export = () => { |
15 |
| - let tsProject = makeTsProject(); |
16 |
| - let src = [ |
17 |
| - Config.TOOLS_DIR + '/manual_typings/**/*.d.ts', |
18 |
| - join(Config.APP_SRC, '**/*.spec.ts') |
19 |
| - ]; |
20 |
| - let result = gulp.src(src) |
21 |
| - .pipe(plugins.plumber()) |
22 |
| - .pipe(plugins.sourcemaps.init()) |
23 |
| - .pipe(tsProject()); |
24 |
| - |
25 |
| - return result.js |
26 |
| - .pipe(plugins.sourcemaps.write()) |
27 |
| - .pipe(gulp.dest(Config.APP_DEST)); |
| 19 | +export = |
| 20 | + class BuildJsTest extends TypeScriptTask { |
| 21 | + run() { |
| 22 | + let tsProject: any; |
| 23 | + let typings = gulp.src( [ |
| 24 | + Config.TOOLS_DIR + '/manual_typings/**/*.d.ts' |
| 25 | + ] ); |
| 26 | + let src = [ |
| 27 | + join(Config.APP_SRC, '**/*.spec.ts') |
| 28 | + ]; |
| 29 | + |
| 30 | + let projectFiles = gulp.src(src); |
| 31 | + let result: any; |
| 32 | + let isFullCompile = true; |
| 33 | + |
| 34 | + // Only do a typed build every X builds, otherwise do a typeless build to speed things up |
| 35 | + if (typedBuildCounter < Config.TYPED_COMPILE_INTERVAL) { |
| 36 | + isFullCompile = false; |
| 37 | + tsProject = makeTsProject({isolatedModules: true}); |
| 38 | + projectFiles = projectFiles.pipe(plugins.cached()); |
| 39 | + util.log('Performing typeless TypeScript compile of specs.'); |
| 40 | + } else { |
| 41 | + tsProject = makeTsProject(); |
| 42 | + projectFiles = merge(typings, projectFiles); |
| 43 | + } |
| 44 | + |
| 45 | + //noinspection TypeScriptUnresolvedFunction |
| 46 | + result = projectFiles |
| 47 | + .pipe(plugins.plumber()) |
| 48 | + .pipe(plugins.sourcemaps.init()) |
| 49 | + .pipe(tsProject()) |
| 50 | + .on('error', () => { |
| 51 | + typedBuildCounter = Config.TYPED_COMPILE_INTERVAL; |
| 52 | + }); |
| 53 | + |
| 54 | + if (isFullCompile) { |
| 55 | + typedBuildCounter = 0; |
| 56 | + } else { |
| 57 | + typedBuildCounter++; |
| 58 | + } |
| 59 | + |
| 60 | + return result.js |
| 61 | + .pipe(plugins.sourcemaps.write()) |
| 62 | + // Use for debugging with Webstorm/IntelliJ |
| 63 | + // https://github.com/mgechev/angular2-seed/issues/1220 |
| 64 | + // .pipe(plugins.sourcemaps.write('.', { |
| 65 | + // includeContent: false, |
| 66 | + // sourceRoot: (file: any) => |
| 67 | + // relative(file.path, PROJECT_ROOT + '/' + APP_SRC).replace(sep, '/') + '/' + APP_SRC |
| 68 | + // })) |
| 69 | + .pipe(gulp.dest(Config.APP_DEST)); |
| 70 | + } |
28 | 71 | };
|
0 commit comments