|
| 1 | +import { appendToFile, moveDirectory, prependToFile, replaceInFile, writeFile } from '../../utils/fs'; |
| 2 | +import { ng } from '../../utils/process'; |
| 3 | + |
| 4 | + |
| 5 | +export default async function () { |
| 6 | + // Store the production build for artifact storage on CircleCI |
| 7 | + if (process.env['CIRCLECI']) { |
| 8 | + |
| 9 | + // Add initial app routing. |
| 10 | + // This is done automatically on a new app with --routing but must be done manually on |
| 11 | + // existing apps. |
| 12 | + const appRoutingModulePath = 'src/app/app-routing.module.ts'; |
| 13 | + await writeFile(appRoutingModulePath, ` |
| 14 | + import { NgModule } from '@angular/core'; |
| 15 | + import { Routes, RouterModule } from '@angular/router'; |
| 16 | +
|
| 17 | + const routes: Routes = []; |
| 18 | +
|
| 19 | + @NgModule({ |
| 20 | + imports: [RouterModule.forRoot(routes)], |
| 21 | + exports: [RouterModule] |
| 22 | + }) |
| 23 | + export class AppRoutingModule { } |
| 24 | + `); |
| 25 | + await prependToFile('src/app/app.module.ts', |
| 26 | + `import { AppRoutingModule } from './app-routing.module';`); |
| 27 | + await replaceInFile('src/app/app.module.ts', `imports: [`, `imports: [ AppRoutingModule,`); |
| 28 | + await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>'); |
| 29 | + |
| 30 | + // Add a lazy module. |
| 31 | + await ng('generate', 'module', 'lazy', '--route=lazy', '--module=app.module'); |
| 32 | + |
| 33 | + // Build without hashing and with named chunks to keep have consistent file names. |
| 34 | + await ng('build', '--prod', '--output-hashing=none', '--named-chunks=true'); |
| 35 | + |
| 36 | + // Upload to the store_artifacts dir listed in .circleci/config.yml |
| 37 | + await moveDirectory('dist', '/tmp/dist'); |
| 38 | + } |
| 39 | +} |
0 commit comments