1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright Google LLC All Rights Reserved.
|
5 | *
|
6 | * Use of this source code is governed by an MIT-style license that can be
|
7 | * found in the LICENSE file at https://angular.io/license
|
8 | */
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const core_1 = require("@angular-devkit/core");
|
11 | const schematics_1 = require("@angular-devkit/schematics");
|
12 | const utility_1 = require("@schematics/angular/utility");
|
13 | const json_file_1 = require("@schematics/angular/utility/json-file");
|
14 | const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
|
15 | const project_targets_1 = require("@schematics/angular/utility/project-targets");
|
16 | const ts = require("typescript");
|
17 | const utils_1 = require("../utils");
|
18 | const SERVE_SSR_TARGET_NAME = 'serve-ssr';
|
19 | const PRERENDER_TARGET_NAME = 'prerender';
|
20 | function addScriptsRule(options) {
|
21 | return async (host) => {
|
22 | const pkgPath = '/package.json';
|
23 | const buffer = host.read(pkgPath);
|
24 | if (buffer === null) {
|
25 | throw new schematics_1.SchematicsException('Could not find package.json');
|
26 | }
|
27 | const serverDist = await (0, utils_1.getOutputPath)(host, options.project, 'server');
|
28 | const pkg = JSON.parse(buffer.toString());
|
29 | pkg.scripts = {
|
30 | ...pkg.scripts,
|
31 | 'dev:ssr': `ng run ${options.project}:${SERVE_SSR_TARGET_NAME}`,
|
32 | 'serve:ssr': `node ${serverDist}/main.js`,
|
33 | 'build:ssr': `ng build && ng run ${options.project}:server`,
|
34 | 'prerender': `ng run ${options.project}:${PRERENDER_TARGET_NAME}`,
|
35 | };
|
36 | host.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
|
37 | };
|
38 | }
|
39 | function updateWorkspaceConfigRule(options) {
|
40 | return () => {
|
41 | return (0, utility_1.updateWorkspace)((workspace) => {
|
42 | const projectName = options.project;
|
43 | const project = workspace.projects.get(projectName);
|
44 | if (!project) {
|
45 | return;
|
46 | }
|
47 | const serverTarget = project.targets.get('server');
|
48 | serverTarget.options.main = (0, core_1.join)((0, core_1.normalize)(project.root), (0, utils_1.stripTsExtension)(options.serverFileName) + '.ts');
|
49 | const serveSSRTarget = project.targets.get(SERVE_SSR_TARGET_NAME);
|
50 | if (serveSSRTarget) {
|
51 | return;
|
52 | }
|
53 | project.targets.add({
|
54 | name: SERVE_SSR_TARGET_NAME,
|
55 | builder: '@nguniversal/builders:ssr-dev-server',
|
56 | defaultConfiguration: 'development',
|
57 | options: {},
|
58 | configurations: {
|
59 | development: {
|
60 | browserTarget: `${projectName}:build:development`,
|
61 | serverTarget: `${projectName}:server:development`,
|
62 | },
|
63 | production: {
|
64 | browserTarget: `${projectName}:build:production`,
|
65 | serverTarget: `${projectName}:server:production`,
|
66 | },
|
67 | },
|
68 | });
|
69 | const prerenderTarget = project.targets.get(PRERENDER_TARGET_NAME);
|
70 | if (prerenderTarget) {
|
71 | return;
|
72 | }
|
73 | project.targets.add({
|
74 | name: PRERENDER_TARGET_NAME,
|
75 | builder: '@nguniversal/builders:prerender',
|
76 | defaultConfiguration: 'production',
|
77 | options: {
|
78 | routes: ['/'],
|
79 | },
|
80 | configurations: {
|
81 | production: {
|
82 | browserTarget: `${projectName}:build:production`,
|
83 | serverTarget: `${projectName}:server:production`,
|
84 | },
|
85 | development: {
|
86 | browserTarget: `${projectName}:build:development`,
|
87 | serverTarget: `${projectName}:server:development`,
|
88 | },
|
89 | },
|
90 | });
|
91 | });
|
92 | };
|
93 | }
|
94 | function updateServerTsConfigRule(options) {
|
95 | return async (host) => {
|
96 | const project = await (0, utils_1.getProject)(host, options.project);
|
97 | const serverTarget = project.targets.get('server');
|
98 | if (!serverTarget || !serverTarget.options) {
|
99 | return;
|
100 | }
|
101 | const tsConfigPath = serverTarget.options.tsConfig;
|
102 | if (!tsConfigPath || typeof tsConfigPath !== 'string') {
|
103 | // No tsconfig path
|
104 | return;
|
105 | }
|
106 | const tsConfig = new json_file_1.JSONFile(host, tsConfigPath);
|
107 | const filesAstNode = tsConfig.get(['files']);
|
108 | const serverFilePath = (0, utils_1.stripTsExtension)(options.serverFileName) + '.ts';
|
109 | if (Array.isArray(filesAstNode) && !filesAstNode.some(({ text }) => text === serverFilePath)) {
|
110 | tsConfig.modify(['files'], [...filesAstNode, serverFilePath]);
|
111 | }
|
112 | };
|
113 | }
|
114 | function routingInitialNavigationRule(options) {
|
115 | return async (host) => {
|
116 | const project = await (0, utils_1.getProject)(host, options.project);
|
117 | const serverTarget = project.targets.get('server');
|
118 | if (!serverTarget || !serverTarget.options) {
|
119 | return;
|
120 | }
|
121 | const tsConfigPath = serverTarget.options.tsConfig;
|
122 | if (!tsConfigPath || typeof tsConfigPath !== 'string' || !host.exists(tsConfigPath)) {
|
123 | // No tsconfig path
|
124 | return;
|
125 | }
|
126 | const parseConfigHost = {
|
127 | useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
128 | readDirectory: ts.sys.readDirectory,
|
129 | fileExists: function (fileName) {
|
130 | return host.exists(fileName);
|
131 | },
|
132 | readFile: function (fileName) {
|
133 | return host.read(fileName).toString();
|
134 | },
|
135 | };
|
136 | const { config } = ts.readConfigFile(tsConfigPath, parseConfigHost.readFile);
|
137 | const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, (0, core_1.dirname)((0, core_1.normalize)(tsConfigPath)));
|
138 | const tsHost = ts.createCompilerHost(parsed.options, true);
|
139 | // Strip BOM as otherwise TSC methods (Ex: getWidth) will return an offset,
|
140 | // which breaks the CLI UpdateRecorder.
|
141 | // See: https://github.com/angular/angular/pull/30719
|
142 | tsHost.readFile = function (fileName) {
|
143 | return host
|
144 | .read(fileName)
|
145 | .toString()
|
146 | .replace(/^\uFEFF/, '');
|
147 | };
|
148 | tsHost.directoryExists = function (directoryName) {
|
149 | // When the path is file getDir will throw.
|
150 | try {
|
151 | const dir = host.getDir(directoryName);
|
152 | return !!(dir.subdirs.length || dir.subfiles.length);
|
153 | }
|
154 | catch {
|
155 | return false;
|
156 | }
|
157 | };
|
158 | tsHost.fileExists = function (fileName) {
|
159 | return host.exists(fileName);
|
160 | };
|
161 | tsHost.realpath = function (path) {
|
162 | return path;
|
163 | };
|
164 | tsHost.getCurrentDirectory = function () {
|
165 | return host.root.path;
|
166 | };
|
167 | const program = ts.createProgram(parsed.fileNames, parsed.options, tsHost);
|
168 | const typeChecker = program.getTypeChecker();
|
169 | const sourceFiles = program
|
170 | .getSourceFiles()
|
171 | .filter((f) => !f.isDeclarationFile && !program.isSourceFileFromExternalLibrary(f));
|
172 | const printer = ts.createPrinter();
|
173 | const routerModule = 'RouterModule';
|
174 | const routerSource = '@angular/router';
|
175 | sourceFiles.forEach((sourceFile) => {
|
176 | const routerImport = (0, utils_1.findImport)(sourceFile, routerSource, routerModule);
|
177 | if (!routerImport) {
|
178 | return;
|
179 | }
|
180 | let routerModuleNode;
|
181 | ts.forEachChild(sourceFile, function visitNode(node) {
|
182 | if (ts.isCallExpression(node) &&
|
183 | ts.isPropertyAccessExpression(node.expression) &&
|
184 | ts.isIdentifier(node.expression.expression) &&
|
185 | node.expression.name.text === 'forRoot') {
|
186 | const imp = (0, utils_1.getImportOfIdentifier)(typeChecker, node.expression.expression);
|
187 | if (imp && imp.name === routerModule && imp.importModule === routerSource) {
|
188 | routerModuleNode = node;
|
189 | }
|
190 | }
|
191 | ts.forEachChild(node, visitNode);
|
192 | });
|
193 | if (routerModuleNode) {
|
194 | const print = printer.printNode(ts.EmitHint.Unspecified, (0, utils_1.addInitialNavigation)(routerModuleNode), sourceFile);
|
195 | const recorder = host.beginUpdate(sourceFile.fileName);
|
196 | recorder.remove(routerModuleNode.getStart(), routerModuleNode.getWidth());
|
197 | recorder.insertRight(routerModuleNode.getStart(), print);
|
198 | host.commitUpdate(recorder);
|
199 | }
|
200 | });
|
201 | };
|
202 | }
|
203 | function addDependencies() {
|
204 | return (_host) => {
|
205 | return (0, schematics_1.chain)([
|
206 | (0, utility_1.addDependency)('@nguniversal/builders', '^16.0.2', {
|
207 | type: utility_1.DependencyType.Dev,
|
208 | }),
|
209 | (0, utility_1.addDependency)('@nguniversal/express-engine', '^16.0.2', {
|
210 | type: utility_1.DependencyType.Default,
|
211 | }),
|
212 | (0, utility_1.addDependency)('express', '^4.15.2', {
|
213 | type: utility_1.DependencyType.Default,
|
214 | }),
|
215 | (0, utility_1.addDependency)('@types/express', '^4.17.0', {
|
216 | type: utility_1.DependencyType.Dev,
|
217 | }),
|
218 | ]);
|
219 | };
|
220 | }
|
221 | function addServerFile(options, isStandalone) {
|
222 | return async (host) => {
|
223 | const project = await (0, utils_1.getProject)(host, options.project);
|
224 | const browserDistDirectory = await (0, utils_1.getOutputPath)(host, options.project, 'build');
|
225 | return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
226 | (0, schematics_1.template)({
|
227 | ...core_1.strings,
|
228 | ...options,
|
229 | stripTsExtension: utils_1.stripTsExtension,
|
230 | browserDistDirectory,
|
231 | isStandalone,
|
232 | }),
|
233 | (0, schematics_1.move)(project.root),
|
234 | ]));
|
235 | };
|
236 | }
|
237 | function default_1(options) {
|
238 | return async (host) => {
|
239 | const project = await (0, utils_1.getProject)(host, options.project);
|
240 | const universalOptions = {
|
241 | ...options,
|
242 | skipInstall: true,
|
243 | };
|
244 | const clientBuildTarget = project.targets.get('build');
|
245 | if (!clientBuildTarget) {
|
246 | throw (0, project_targets_1.targetBuildNotFoundError)();
|
247 | }
|
248 | const clientBuildOptions = (clientBuildTarget.options ||
|
249 | {});
|
250 | const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, clientBuildOptions.main);
|
251 | delete universalOptions.serverFileName;
|
252 | delete universalOptions.serverPort;
|
253 | return (0, schematics_1.chain)([
|
254 | project.targets.has('server')
|
255 | ? (0, schematics_1.noop)()
|
256 | : (0, schematics_1.externalSchematic)('@schematics/angular', 'universal', universalOptions),
|
257 | addScriptsRule(options),
|
258 | updateServerTsConfigRule(options),
|
259 | updateWorkspaceConfigRule(options),
|
260 | isStandalone ? (0, schematics_1.noop)() : routingInitialNavigationRule(options),
|
261 | addServerFile(options, isStandalone),
|
262 | addDependencies(),
|
263 | ]);
|
264 | };
|
265 | }
|
266 | exports.default = default_1;
|
267 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9tb2R1bGVzL2V4cHJlc3MtZW5naW5lL3NjaGVtYXRpY3MvaW5zdGFsbC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOztBQUVILCtDQUF5RTtBQUN6RSwyREFZb0M7QUFFcEMseURBQTZGO0FBQzdGLHFFQUFpRTtBQUNqRSwyRUFBMkU7QUFDM0UsaUZBQXVGO0FBRXZGLGlDQUFpQztBQUVqQyxvQ0FPa0I7QUFJbEIsTUFBTSxxQkFBcUIsR0FBRyxXQUFXLENBQUM7QUFDMUMsTUFBTSxxQkFBcUIsR0FBRyxXQUFXLENBQUM7QUFFMUMsU0FBUyxjQUFjLENBQUMsT0FBNEI7SUFDbEQsT0FBTyxLQUFLLEVBQUUsSUFBSSxFQUFFLEVBQUU7UUFDcEIsTUFBTSxPQUFPLEdBQUcsZUFBZSxDQUFDO1FBQ2hDLE1BQU0sTUFBTSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDbEMsSUFBSSxNQUFNLEtBQUssSUFBSSxFQUFFO1lBQ25CLE1BQU0sSUFBSSxnQ0FBbUIsQ0FBQyw2QkFBNkIsQ0FBQyxDQUFDO1NBQzlEO1FBRUQsTUFBTSxVQUFVLEdBQUcsTUFBTSxJQUFBLHFCQUFhLEVBQUMsSUFBSSxFQUFFLE9BQU8sQ0FBQyxPQUFPLEVBQUUsUUFBUSxDQUFDLENBQUM7UUFDeEUsTUFBTSxHQUFHLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLENBQUMsUUFB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