1
1
import { normalize } from 'path' ;
2
2
import { getGlobalVariable } from '../../utils/env' ;
3
- import {
4
- appendToFile ,
5
- expectFileToMatch ,
6
- prependToFile ,
7
- writeFile ,
8
- } from '../../utils/fs' ;
3
+ import { appendToFile , expectFileToMatch , prependToFile , writeFile } from '../../utils/fs' ;
9
4
import { exec , ng , silentNpm } from '../../utils/process' ;
10
5
import { updateJsonFile } from '../../utils/project' ;
11
6
import { readNgVersion } from '../../utils/version' ;
12
7
13
- export default function ( ) {
8
+ export default function ( ) {
14
9
let platformServerVersion = readNgVersion ( ) ;
15
10
let httpVersion = readNgVersion ( ) ;
16
11
@@ -24,25 +19,33 @@ export default function () {
24
19
return Promise . resolve ( ) ;
25
20
}
26
21
27
- return Promise . resolve ( )
28
- . then ( ( ) => updateJsonFile ( 'package.json' , packageJson => {
29
- const dependencies = packageJson [ 'dependencies' ] ;
30
- dependencies [ '@angular/platform-server' ] = platformServerVersion ;
31
- // ServerModule depends on @angular /http regardless the app's dependency.
32
- dependencies [ '@angular/http' ] = httpVersion ;
33
- } ) )
34
- . then ( ( ) => updateJsonFile ( 'angular.json' , workspaceJson => {
35
- const appArchitect = workspaceJson . projects [ 'test-project' ] . architect ;
36
- appArchitect [ 'server' ] = {
37
- builder : '@angular-devkit/build-angular:server' ,
38
- options : {
39
- outputPath : 'dist/test-project-server' ,
40
- main : 'src/main.server.ts' ,
41
- tsConfig : 'tsconfig.server.json' ,
42
- } ,
43
- } ;
44
- } ) )
45
- . then ( ( ) => writeFile ( './tsconfig.server.json' , `
22
+ return (
23
+ Promise . resolve ( )
24
+ . then ( ( ) =>
25
+ updateJsonFile ( 'package.json' , packageJson => {
26
+ const dependencies = packageJson [ 'dependencies' ] ;
27
+ dependencies [ '@angular/platform-server' ] = platformServerVersion ;
28
+ // ServerModule depends on @angular /http regardless the app's dependency.
29
+ dependencies [ '@angular/http' ] = httpVersion ;
30
+ } ) ,
31
+ )
32
+ . then ( ( ) =>
33
+ updateJsonFile ( 'angular.json' , workspaceJson => {
34
+ const appArchitect = workspaceJson . projects [ 'test-project' ] . architect ;
35
+ appArchitect [ 'server' ] = {
36
+ builder : '@angular-devkit/build-angular:server' ,
37
+ options : {
38
+ outputPath : 'dist/test-project-server' ,
39
+ main : 'src/main.server.ts' ,
40
+ tsConfig : 'tsconfig.server.json' ,
41
+ } ,
42
+ } ;
43
+ } ) ,
44
+ )
45
+ . then ( ( ) =>
46
+ writeFile (
47
+ './tsconfig.server.json' ,
48
+ `
46
49
{
47
50
"extends": "./tsconfig.app.json",
48
51
"compilerOptions": {
@@ -55,8 +58,13 @@ export default function () {
55
58
"entryModule": "src/app/app.server.module#AppServerModule"
56
59
}
57
60
}
58
- ` ) )
59
- . then ( ( ) => writeFile ( './src/main.server.ts' , `
61
+ ` ,
62
+ ) ,
63
+ )
64
+ . then ( ( ) =>
65
+ writeFile (
66
+ './src/main.server.ts' ,
67
+ `
60
68
import { enableProdMode } from '@angular/core';
61
69
62
70
import { environment } from './environments/environment';
@@ -66,8 +74,13 @@ export default function () {
66
74
}
67
75
68
76
export { AppServerModule } from './app/app.server.module';
69
- ` ) )
70
- . then ( ( ) => writeFile ( './src/app/app.server.module.ts' , `
77
+ ` ,
78
+ ) ,
79
+ )
80
+ . then ( ( ) =>
81
+ writeFile (
82
+ './src/app/app.server.module.ts' ,
83
+ `
71
84
import { NgModule } from '@angular/core';
72
85
import { BrowserModule } from '@angular/platform-browser';
73
86
import { ServerModule } from '@angular/platform-server';
@@ -84,35 +97,41 @@ export default function () {
84
97
bootstrap: [AppComponent],
85
98
})
86
99
export class AppServerModule {}
87
- ` ) )
88
- . then ( ( ) => silentNpm ( 'install' ) )
89
- // This part of the test requires a non-aot build, which isn't available anymore.
90
- // .then(() => ng('run', 'test-project:server'))
91
- // // files were created successfully
92
- // .then(() => expectFileToMatch('dist/test-project-server/main.js',
93
- // /exports.*AppServerModule/))
94
- // .then(() => writeFile('./index.js', `
95
- // require('zone.js/dist/zone-node');
96
- // require('reflect-metadata');
97
- // const fs = require('fs');
98
- // const \{ AppServerModule \} = require('./dist/test-project-server/main');
99
- // const \{ renderModule \} = require('@angular/platform-server');
100
+ ` ,
101
+ ) ,
102
+ )
103
+ . then ( ( ) => silentNpm ( 'install' ) )
104
+ // This part of the test requires a non-aot build, which isn't available anymore.
105
+ // .then(() => ng('run', 'test-project:server'))
106
+ // // files were created successfully
107
+ // .then(() => expectFileToMatch('dist/test-project-server/main.js',
108
+ // /exports.*AppServerModule/))
109
+ // .then(() => writeFile('./index.js', `
110
+ // require('zone.js/dist/zone-node');
111
+ // require('reflect-metadata');
112
+ // const fs = require('fs');
113
+ // const \{ AppServerModule \} = require('./dist/test-project-server/main');
114
+ // const \{ renderModule \} = require('@angular/platform-server');
100
115
101
- // renderModule(AppServerModule, \{
102
- // url: '/',
103
- // document: '<app-root></app-root>'
104
- // \}).then(html => \{
105
- // fs.writeFileSync('dist/test-project-server/index.html', html);
106
- // \});
107
- // `))
108
- // .then(() => exec(normalize('node'), 'index.js'))
109
- // .then(() => expectFileToMatch('dist/test-project-server/index.html',
110
- // new RegExp('<h2 _ngcontent-c0="">Here are some links to help you start: </h2>')))
111
- . then ( ( ) => ng ( 'run' , 'test-project:server' ) )
112
- // files were created successfully
113
- . then ( ( ) => expectFileToMatch ( 'dist/test-project-server/main.js' ,
114
- / e x p o r t s .* A p p S e r v e r M o d u l e N g F a c t o r y / ) )
115
- . then ( ( ) => writeFile ( './index.js' , `
116
+ // renderModule(AppServerModule, \{
117
+ // url: '/',
118
+ // document: '<app-root></app-root>'
119
+ // \}).then(html => \{
120
+ // fs.writeFileSync('dist/test-project-server/index.html', html);
121
+ // \});
122
+ // `))
123
+ // .then(() => exec(normalize('node'), 'index.js'))
124
+ // .then(() => expectFileToMatch('dist/test-project-server/index.html',
125
+ // new RegExp('<h2 _ngcontent-c0="">Here are some links to help you start: </h2>')))
126
+ . then ( ( ) => ng ( 'run' , 'test-project:server' ) )
127
+ // files were created successfully
128
+ . then ( ( ) =>
129
+ expectFileToMatch ( 'dist/test-project-server/main.js' , / e x p o r t s .* A p p S e r v e r M o d u l e N g F a c t o r y / ) ,
130
+ )
131
+ . then ( ( ) =>
132
+ writeFile (
133
+ './index.js' ,
134
+ `
116
135
require('zone.js/dist/zone-node');
117
136
require('reflect-metadata');
118
137
const fs = require('fs');
@@ -125,19 +144,35 @@ export default function () {
125
144
\}).then(html => \{
126
145
fs.writeFileSync('dist/test-project-server/index.html', html);
127
146
\});
128
- ` ) )
129
- . then ( ( ) => exec ( normalize ( 'node' ) , 'index.js' ) )
130
- . then ( ( ) => expectFileToMatch ( 'dist/test-project-server/index.html' ,
131
- / < h 2 .* > H e r e a r e s o m e l i n k s t o h e l p y o u s t a r t : < \/ h 2 > / ) )
132
- . then ( ( ) => expectFileToMatch ( './dist/test-project-server/main.js' ,
133
- / r e q u i r e \( [ " ' ] @ a n g u l a r \/ [ ^ " ' ] * [ " ' ] \) / ) )
147
+ ` ,
148
+ ) ,
149
+ )
150
+ . then ( ( ) => exec ( normalize ( 'node' ) , 'index.js' ) )
151
+ . then ( ( ) =>
152
+ expectFileToMatch (
153
+ 'dist/test-project-server/index.html' ,
154
+ / < h 2 .* > H e r e a r e s o m e l i n k s t o h e l p y o u s t a r t : < \/ h 2 > / ,
155
+ ) ,
156
+ )
157
+ . then ( ( ) =>
158
+ expectFileToMatch (
159
+ './dist/test-project-server/main.js' ,
160
+ / r e q u i r e \( [ " ' ] @ a n g u l a r \/ [ ^ " ' ] * [ " ' ] \) / ,
161
+ ) ,
162
+ )
134
163
135
- // Check externals.
136
- . then ( ( ) => prependToFile ( './src/app/app.server.module.ts' , `
164
+ // Check externals.
165
+ . then ( ( ) =>
166
+ prependToFile (
167
+ './src/app/app.server.module.ts' ,
168
+ `
137
169
import 'zone.js/dist/zone-node';
138
170
import 'reflect-metadata';
139
- ` )
140
- . then ( ( ) => appendToFile ( './src/app/app.server.module.ts' , `
171
+ ` ,
172
+ ) . then ( ( ) =>
173
+ appendToFile (
174
+ './src/app/app.server.module.ts' ,
175
+ `
141
176
import * as fs from 'fs';
142
177
import { renderModule } from '@angular/platform-server';
143
178
@@ -147,5 +182,9 @@ export default function () {
147
182
\}).then(html => \{
148
183
fs.writeFileSync('dist/test-project-server/index.html', html);
149
184
\});
150
- ` ) ) )
151
- }
185
+ ` ,
186
+ ) ,
187
+ ) ,
188
+ )
189
+ ) ;
190
+ }
0 commit comments