(appName: string, enableServiceWorker: boolean, baseHref: string, maxBuffer: number | string)
| 1 | import { exec } from 'child_process'; |
| 2 | |
| 3 | export async function buildAngularCli(appName: string, enableServiceWorker: boolean, baseHref: string, maxBuffer: number | string) { |
| 4 | let isInstalled = await serviceWorkerIsInstalled(); |
| 5 | if (enableServiceWorker && !isInstalled) { |
| 6 | throw new Error('\n\nError: --build-with-service-worker requires @angular/service-worker to be installed locally: \n' + |
| 7 | 'try running "npm install @angular/service-worker" then run "angular-playground --build" \n' + |
| 8 | 'see docs: https://github.com/angular/angular-cli/wiki/build#service-worker\n\n'); |
| 9 | } |
| 10 | |
| 11 | console.log('Building for production with sandboxes...'); |
| 12 | |
| 13 | const options = Number.isInteger(+maxBuffer) ? { maxBuffer: +maxBuffer } : {}; |
| 14 | // Cannot build w/ AOT due to runtime compiler dependency |
| 15 | const flags = [ |
| 16 | `-c=production`, |
| 17 | '--aot=false', |
| 18 | `--base-href=${baseHref}`, |
| 19 | `--service-worker=${enableServiceWorker}`, |
| 20 | ]; |
| 21 | exec(`ng build ${appName} ${flags.join(' ')}`, |
| 22 | options, |
| 23 | (err, stdout, stderr) => { |
| 24 | if (err) throw err; |
| 25 | console.log(stdout); |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | async function serviceWorkerIsInstalled(): Promise<boolean> { |
| 30 | return new Promise<boolean>((resolve, reject) => { |
no test coverage detected