1
1
import { task } from 'gulp' ;
2
- import { join } from 'path' ;
3
- import { ngcBuildTask , copyTask , execNodeTask , serverTask } from '../util/task_helpers' ;
4
- import { copySync } from 'fs-extra' ;
5
2
import { buildConfig , sequenceTask , triggerLivereload , watchFiles } from 'material2-build-tools' ;
3
+ import { join } from 'path' ;
4
+ import { copyTask , execNodeTask , ngcBuildTask , serverTask } from '../util/task_helpers' ;
6
5
7
6
// There are no type definitions available for these imports.
8
7
const gulpConnect = require ( 'gulp-connect' ) ;
9
8
10
9
const { outputDir, packagesDir, projectDir} = buildConfig ;
11
10
12
- /** Path to the directory where all releases are created. */
13
- const releasesDir = join ( outputDir , 'releases' ) ;
14
-
15
11
const appDir = join ( packagesDir , 'e2e-app' ) ;
16
12
const e2eTestDir = join ( projectDir , 'e2e' ) ;
17
- const outDir = join ( outputDir , 'packages' , 'e2e-app' ) ;
18
13
19
- const PROTRACTOR_CONFIG_PATH = join ( projectDir , 'test/protractor.conf.js' ) ;
20
- const tsconfigPath = join ( outDir , 'tsconfig-build.json' ) ;
14
+ /**
15
+ * The output of the e2e app will preserve the directory structure because otherwise NGC is not
16
+ * able to generate factory files for the release output and node modules.
17
+ */
18
+ const outDir = join ( outputDir , 'src/e2e-app' ) ;
21
19
22
- /** Glob that matches all files that need to be copied to the output folder. */
23
- const assetsGlob = join ( appDir , '**/*.+(html|css| json|ts) ' ) ;
20
+ const PROTRACTOR_CONFIG_PATH = join ( projectDir , 'test/protractor.conf.js' ) ;
21
+ const tsconfigPath = join ( appDir , 'tsconfig-build. json' ) ;
24
22
25
23
/** Builds and serves the e2e-app and runs protractor once the e2e-app is ready. */
26
24
task ( 'e2e' , sequenceTask (
@@ -68,12 +66,11 @@ task('e2e-app:build', sequenceTask(
68
66
'material-moment-adapter:build-release' ,
69
67
'material-examples:build-release'
70
68
] ,
71
- [ 'e2e-app:copy-release' , 'e2e-app:copy-assets' ] ,
72
- 'e2e-app:build-ts'
69
+ [ 'e2e-app:copy-index-html' , 'e2e-app:build-ts' ]
73
70
) ) ;
74
71
75
- /** Task that copies all required assets to the output folder . */
76
- task ( 'e2e-app:copy-assets ' , copyTask ( assetsGlob , outDir ) ) ;
72
+ /** Task that copies the e2e-app index HTML file to the output. */
73
+ task ( 'e2e-app:copy-index-html ' , copyTask ( join ( appDir , 'index.html' ) , outDir ) ) ;
77
74
78
75
/** Task that builds the TypeScript sources. Those are compiled inside of the dist folder. */
79
76
task ( 'e2e-app:build-ts' , ngcBuildTask ( tsconfigPath ) ) ;
@@ -92,8 +89,23 @@ task(':test:protractor:setup', execNodeTask(
92
89
/** Runs protractor tests (assumes that server is already running. */
93
90
task ( ':test:protractor' , execNodeTask ( 'protractor' , [ PROTRACTOR_CONFIG_PATH ] ) ) ;
94
91
95
- /** Starts up the e2e app server. */
96
- task ( ':serve:e2eapp' , serverTask ( outDir , false ) ) ;
92
+ /** Starts up the e2e app server and rewrites the HTTP requests to properly work with AOT. */
93
+ task ( ':serve:e2eapp' , serverTask ( outDir , false , [
94
+ // Rewrite each request for .ngfactory files which are outside of the e2e-app to the **actual**
95
+ // path. This is necessary because NGC cannot generate factory files for the node modules
96
+ // and release output. If we work around it by adding multiple root directories, the directory
97
+ // structure would be messed up, so we need to go this way for now (until Ivy).
98
+ { from : '^/((?:dist|node_modules)/.*\.ngfactory\.js)$' , to : '/dist/$1' } ,
99
+ // Rewrite the node_modules/ and dist/ folder to the real paths. Otherwise we would need
100
+ // to copy the required modules to the serve output. If dist/ is explicitly requested, we
101
+ // should redirect to the actual dist path because by default we fall back to the e2e output.
102
+ { from : '^/node_modules/(.*)$' , to : '/node_modules/$1' } ,
103
+ { from : '^/dist/(.*)$' , to : '/dist/$1' } ,
104
+ // Rewrite every path that doesn't point to a specific file to the e2e output.
105
+ // This is necessary for Angular's routing using the HTML5 History API.
106
+ { from : '^/[^.]+$' , to : `/dist/src/e2e-app/index.html` } ,
107
+ { from : '^(.*)$' , to : `/dist/src/e2e-app/$1` } ,
108
+ ] ) ) ;
97
109
98
110
/** Terminates the e2e app server */
99
111
task ( ':serve:e2eapp:stop' , gulpConnect . serverClose ) ;
@@ -106,14 +118,3 @@ task('serve:e2eapp', sequenceTask('e2e-app:build', ':serve:e2eapp'));
106
118
* This should only be used when running e2e tests locally.
107
119
*/
108
120
task ( 'serve:e2eapp:watch' , [ 'serve:e2eapp' , 'material:watch' , ':watch:e2eapp' ] ) ;
109
-
110
- // As a workaround for https://github.com/angular/angular/issues/12249, we need to
111
- // copy the Material and CDK ESM output inside of the demo-app output.
112
- task ( 'e2e-app:copy-release' , ( ) => {
113
- copySync ( join ( releasesDir , 'cdk' ) , join ( outDir , 'cdk' ) ) ;
114
- copySync ( join ( releasesDir , 'material' ) , join ( outDir , 'material' ) ) ;
115
- copySync ( join ( releasesDir , 'cdk-experimental' ) , join ( outDir , 'cdk-experimental' ) ) ;
116
- copySync ( join ( releasesDir , 'material-experimental' ) , join ( outDir , 'material-experimental' ) ) ;
117
- copySync ( join ( releasesDir , 'material-examples' ) , join ( outDir , 'material-examples' ) ) ;
118
- copySync ( join ( releasesDir , 'material-moment-adapter' ) , join ( outDir , 'material-moment-adapter' ) ) ;
119
- } ) ;
0 commit comments