({ project }: SSROptions, isUsingApplicationBuilder: boolean)
| 114 | } |
| 115 | |
| 116 | function addScriptsRule({ project }: SSROptions, isUsingApplicationBuilder: boolean): Rule { |
| 117 | return async (host) => { |
| 118 | const pkgPath = '/package.json'; |
| 119 | const pkg = host.readJson(pkgPath) as { scripts?: Record<string, string> } | null; |
| 120 | if (pkg === null) { |
| 121 | throw new SchematicsException('Could not find package.json'); |
| 122 | } |
| 123 | |
| 124 | if (isUsingApplicationBuilder) { |
| 125 | const { base, server } = await getApplicationBuilderOutputPaths(host, project); |
| 126 | pkg.scripts ??= {}; |
| 127 | pkg.scripts[`serve:ssr:${project}`] = `node ${join(base, server)}/server.mjs`; |
| 128 | } else { |
| 129 | const serverDist = await getLegacyOutputPaths(host, project, 'server'); |
| 130 | pkg.scripts = { |
| 131 | ...pkg.scripts, |
| 132 | 'dev:ssr': `ng run ${project}:${SERVE_SSR_TARGET_NAME}`, |
| 133 | 'serve:ssr': `node ${serverDist}/main.js`, |
| 134 | 'build:ssr': `ng build && ng run ${project}:server`, |
| 135 | 'prerender': `ng run ${project}:${PRERENDER_TARGET_NAME}`, |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | host.overwrite(pkgPath, JSON.stringify(pkg, null, 2)); |
| 140 | }; |
| 141 | } |
| 142 | |
| 143 | function updateApplicationBuilderTsConfigRule(options: SSROptions): Rule { |
| 144 | return async (host) => { |
no test coverage detected