blob: 7174b7a680401dcd4a0ff290c4bc5bb8e49e0588 [file] [log] [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import fs from 'node:fs';
import path from 'node:path';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers';
import {writeIfChanged} from './ninja/write-if-changed.js';
const {template, outDirectory, entrypoints} = yargs(
hideBin(process.argv),
)
.parseSync();
if (!template) {
throw new Error(
'Must specify --template location with the location of the HTML entrypoint template.',
);
}
if (!outDirectory) {
throw new Error(
'Must specify --out-directory location where the outputs must live.',
);
}
if (!entrypoints) {
throw new Error('Must specify at least one entrypoint name.');
}
if (!Array.isArray(entrypoints)) {
throw new Error('Must specify multiple entrypoints as array');
}
const templateContent = fs.readFileSync(template, 'utf-8');
for (const entrypoint of entrypoints) {
const rewrittenTemplateContent = templateContent.replace(
new RegExp('%ENTRYPOINT_NAME%', 'g'),
entrypoint,
);
writeIfChanged(
path.join(outDirectory, `${entrypoint}.html`),
rewrittenTemplateContent,
);
}