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