11import { task , watch } from 'gulp' ;
2- import * as path from 'path' ;
3-
4- import { SOURCE_ROOT , DIST_E2EAPP , PROJECT_ROOT } from '../build-config' ;
5- import {
6- tsBuildTask , copyTask , buildAppTask , execNodeTask , sequenceTask , serverTask
7- } from '../util/task_helpers' ;
2+ import { join } from 'path' ;
3+ import { SOURCE_ROOT , DIST_E2EAPP , PROJECT_ROOT , DIST_RELEASES } from '../build-config' ;
4+ import { ngcBuildTask , copyTask , execNodeTask , sequenceTask , serverTask } from '../util/task_helpers' ;
5+ import { copySync } from 'fs-extra' ;
86
97// There are no type definitions available for these imports.
108const gulpConnect = require ( 'gulp-connect' ) ;
119
12- const appDir = path . join ( SOURCE_ROOT , 'e2e-app' ) ;
10+ const appDir = join ( SOURCE_ROOT , 'e2e-app' ) ;
1311const outDir = DIST_E2EAPP ;
1412
15- const PROTRACTOR_CONFIG_PATH = path . join ( PROJECT_ROOT , 'test/protractor.conf.js' ) ;
16- const tsconfigPath = path . join ( appDir , 'tsconfig-build.json' ) ;
13+ const PROTRACTOR_CONFIG_PATH = join ( PROJECT_ROOT , 'test/protractor.conf.js' ) ;
14+ const tsconfigPath = join ( outDir , 'tsconfig-build.json' ) ;
1715
18- task ( ':watch:e2eapp' , ( ) => {
19- watch ( path . join ( appDir , '**/*.ts' ) , [ ':build:e2eapp:ts' ] ) ;
20- watch ( path . join ( appDir , '**/*.html' ) , [ ':build:e2eapp:assets' ] ) ;
21- } ) ;
16+ /** Glob that matches all files that need to be copied to the output folder. */
17+ const assetsGlob = join ( appDir , '**/*.+(html|css|json|ts)' ) ;
18+
19+ /**
20+ * Builds and serves the e2e-app and runs protractor once the e2e-app is ready.
21+ */
22+ task ( 'e2e' , sequenceTask (
23+ [ ':test:protractor:setup' , 'serve:e2eapp' ] ,
24+ ':test:protractor' ,
25+ ':serve:e2eapp:stop' ,
26+ 'screenshots' ,
27+ ) ) ;
2228
23- /** Builds e2e app ts to js. */
24- task ( ':build:e2eapp:ts' , tsBuildTask ( tsconfigPath ) ) ;
29+ /** Task that builds the e2e-app in AOT mode. */
30+ task ( 'e2e-app:build' , sequenceTask (
31+ 'clean' ,
32+ [ 'material:build-release' , 'cdk:build-release' ] ,
33+ [ 'e2e-app:copy-release' , 'e2e-app:copy-assets' ] ,
34+ 'e2e-app:build-ts'
35+ ) ) ;
2536
26- /** Copies e2e app assets (html, css) to build output. */
27- task ( ':build:e2eapp: assets' , copyTask ( appDir , outDir ) ) ;
37+ /** Task that copies all required assets to the output folder . */
38+ task ( 'e2e-app:copy- assets' , copyTask ( assetsGlob , outDir ) ) ;
2839
29- /** Builds the entire e2e app. */
30- task ( 'build:e2eapp' , buildAppTask ( 'e2eapp' ) ) ;
40+ /** Task that builds the TypeScript sources. Those are compiled inside of the dist folder. */
41+ task ( 'e2e-app:build-ts' , ngcBuildTask ( tsconfigPath ) ) ;
42+
43+ task ( ':watch:e2eapp' , ( ) => {
44+ watch ( join ( appDir , '**/*.ts' ) , [ 'e2e-app:build' ] ) ;
45+ watch ( join ( appDir , '**/*.html' ) , [ 'e2e-app:copy-assets' ] ) ;
46+ } ) ;
3147
3248/** Ensures that protractor and webdriver are set up to run. */
3349task ( ':test:protractor:setup' , execNodeTask ( 'protractor' , 'webdriver-manager' , [ 'update' ] ) ) ;
@@ -42,21 +58,18 @@ task(':serve:e2eapp', serverTask(outDir, false));
4258task ( ':serve:e2eapp:stop' , gulpConnect . serverClose ) ;
4359
4460/** Builds and serves the e2e app. */
45- task ( 'serve:e2eapp' , sequenceTask ( 'build:e2eapp ' , ':serve:e2eapp' ) ) ;
61+ task ( 'serve:e2eapp' , sequenceTask ( 'e2e-app:build ' , ':serve:e2eapp' ) ) ;
4662
4763/**
4864 * [Watch task] Builds and serves e2e app, rebuilding whenever the sources change.
4965 * This should only be used when running e2e tests locally.
5066 */
5167task ( 'serve:e2eapp:watch' , [ 'serve:e2eapp' , 'material:watch' , ':watch:e2eapp' ] ) ;
5268
53- /**
54- * Builds and serves the e2e-app and runs protractor once the e2e-app is ready.
55- */
56- task ( 'e2e' , sequenceTask (
57- [ ':test:protractor:setup' , 'serve:e2eapp' ] ,
58- ':test:protractor' ,
59- ':serve:e2eapp:stop' ,
60- 'screenshots' ,
61- ) ) ;
69+ // As a workaround for https://github.com/angular/angular/issues/12249, we need to
70+ // copy the Material and CDK ESM output inside of the demo-app output.
71+ task ( 'e2e-app:copy-release' , ( ) => {
72+ copySync ( join ( DIST_RELEASES , 'material' ) , join ( outDir , 'material' ) ) ;
73+ copySync ( join ( DIST_RELEASES , 'cdk' ) , join ( outDir , 'cdk' ) ) ;
74+ } ) ;
6275
0 commit comments