angular/packages/service-worker/cli/main.ts
Paul Gschwendtner e60058c88a build: update service-worker package to export worker script and schema (#43431)
Updates the service-worker package to export the worker script and
schema, so that these files can be resolved and included by consumers.

Additionally, the CLI bundle is updated to be using ESM as it
transitively relies on the `core` entry-point of the package which
already uses ESM. Also this is required because the script is part
of the the service-worker package which has `type: module` applied.

PR Close #43431
2021-10-01 18:28:44 +00:00

30 lines
864 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Config, Generator} from '@angular/service-worker/config';
import * as fs from 'fs';
import * as path from 'path';
import {NodeFilesystem} from './filesystem';
const cwd = process.cwd();
const distDir = path.join(cwd, process.argv[2]);
const config = path.join(cwd, process.argv[3]);
const baseHref = process.argv[4] || '/';
const configParsed = JSON.parse(fs.readFileSync(config).toString()) as Config;
const filesystem = new NodeFilesystem(distDir);
const gen = new Generator(filesystem, baseHref);
(async () => {
const control = await gen.process(configParsed);
await filesystem.write('/ngsw.json', JSON.stringify(control, null, 2));
})();