blob: efbb62d6d74524143a9404705e160df534a5b5bf [file] [log] [blame]
Tim van der Lippe96e05622020-09-15 10:42:011// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const fs = require('fs');
6const path = require('path');
7const {argv} = require('yargs');
Tim van der Lippe28af9fb2022-01-13 14:42:408const {writeIfChanged} = require('./ninja/write-if-changed.js');
Tim van der Lippe96e05622020-09-15 10:42:019
Tim van der Lippe96e05622020-09-15 10:42:0110const {template} = argv;
11
12if (!template) {
13 throw new Error('Must specify --template location with the location of the HTML entrypoint template.');
14}
15
16const {outDirectory} = argv;
17
18if (!outDirectory) {
19 throw new Error('Must specify --out-directory location where the outputs must live.');
20}
21
Tim van der Lippe0f7a51b2021-07-12 15:31:5722const {entrypoints} = argv;
23
24if (!entrypoints) {
25 throw new Error('Must specify at least one entrypoint name.');
26}
27
28if (!Array.isArray(entrypoints)) {
29 throw new Error('Must specify multiple entrypoints as array');
30}
31
Tim van der Lippe96e05622020-09-15 10:42:0132const templateContent = fs.readFileSync(template, 'utf-8');
33
Tim van der Lippe0f7a51b2021-07-12 15:31:5734for (const entrypoint of entrypoints) {
Tim van der Lippe7b347ca2021-04-09 15:59:2135 const rewrittenTemplateContent = templateContent.replace(new RegExp('%ENTRYPOINT_NAME%', 'g'), entrypoint);
Tim van der Lippe28af9fb2022-01-13 14:42:4036 writeIfChanged(path.join(outDirectory, `${entrypoint}.html`), rewrittenTemplateContent);
Tim van der Lippe96e05622020-09-15 10:42:0137}