2017-09-28 23:18:12 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-09-28 23:18:12 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-22 21:13:39 +00:00
|
|
|
import {Config, Generator} from '@angular/service-worker/config';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
2017-09-28 23:18:12 +00:00
|
|
|
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] || '/';
|
|
|
|
|
|
2021-02-04 22:16:15 +00:00
|
|
|
const configParsed = JSON.parse(fs.readFileSync(config).toString()) as Config;
|
2017-09-28 23:18:12 +00:00
|
|
|
|
|
|
|
|
const filesystem = new NodeFilesystem(distDir);
|
|
|
|
|
const gen = new Generator(filesystem, baseHref);
|
|
|
|
|
|
2020-04-13 23:40:21 +00:00
|
|
|
(async () => {
|
2017-09-28 23:18:12 +00:00
|
|
|
const control = await gen.process(configParsed);
|
|
|
|
|
await filesystem.write('/ngsw.json', JSON.stringify(control, null, 2));
|
2020-05-19 19:08:49 +00:00
|
|
|
})();
|