|
| 1 | +import { normalize } from 'path'; |
| 2 | +import { getGlobalVariable } from '../../../utils/env'; |
| 3 | +import { expectFileToMatch, replaceInFile, writeFile } from '../../../utils/fs'; |
| 4 | +import { installPackage } from '../../../utils/packages'; |
| 5 | +import { exec, ng } from '../../../utils/process'; |
| 6 | +import { updateJsonFile } from '../../../utils/project'; |
| 7 | + |
| 8 | +const snapshots = require('../../../ng-snapshot/package.json'); |
| 9 | + |
| 10 | +export default async function () { |
| 11 | + await ng('generate', 'application', 'test-project-two', '--standalone', '--skip-install'); |
| 12 | + await ng('generate', 'universal', '--project', 'test-project-two'); |
| 13 | + |
| 14 | + const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots']; |
| 15 | + if (isSnapshotBuild) { |
| 16 | + const packagesToInstall: string[] = []; |
| 17 | + await updateJsonFile('package.json', (packageJson) => { |
| 18 | + const dependencies = packageJson['dependencies']; |
| 19 | + // Iterate over all of the packages to update them to the snapshot version. |
| 20 | + for (const [name, version] of Object.entries<string>(snapshots.dependencies)) { |
| 21 | + if (name in dependencies && dependencies[name] !== version) { |
| 22 | + packagesToInstall.push(version); |
| 23 | + } |
| 24 | + } |
| 25 | + }); |
| 26 | + |
| 27 | + for (const pkg of packagesToInstall) { |
| 28 | + await installPackage(pkg); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + await writeFile( |
| 33 | + './projects/test-project-two/server.ts', |
| 34 | + ` import 'zone.js/node'; |
| 35 | + import * as fs from 'fs'; |
| 36 | + import { renderApplication } from '@angular/platform-server'; |
| 37 | + import bootstrap from './src/main.server'; |
| 38 | +
|
| 39 | + renderApplication(bootstrap, { |
| 40 | + url: '/', |
| 41 | + document: '<app-root></app-root>' |
| 42 | + }).then(html => { |
| 43 | + fs.writeFileSync('dist/test-project-two/server/index.html', html); |
| 44 | + }) |
| 45 | + `, |
| 46 | + ); |
| 47 | + |
| 48 | + await replaceInFile( |
| 49 | + './projects/test-project-two/tsconfig.server.json', |
| 50 | + 'src/main.server.ts', |
| 51 | + 'server.ts', |
| 52 | + ); |
| 53 | + await replaceInFile('angular.json', 'src/main.server.ts', 'server.ts'); |
| 54 | + |
| 55 | + await ng('run', 'test-project-two:server', '--optimization', 'false'); |
| 56 | + await exec(normalize('node'), 'dist/test-project-two/server/main.js'); |
| 57 | + await expectFileToMatch( |
| 58 | + 'dist/test-project-two/server/index.html', |
| 59 | + /<p.*>Here are some links to help you get started:<\/p>/, |
| 60 | + ); |
| 61 | + |
| 62 | + // works with optimization |
| 63 | + await ng('run', 'test-project-two:server', '--optimization'); |
| 64 | + await exec(normalize('node'), 'dist/test-project-two/server/main.js'); |
| 65 | + await expectFileToMatch( |
| 66 | + 'dist/test-project-two/server/index.html', |
| 67 | + /<p.*>Here are some links to help you get started:<\/p>/, |
| 68 | + ); |
| 69 | +} |
0 commit comments