-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.js
43 lines (38 loc) · 1.03 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
// import
const { join } = require("path");
const mkdirp = require("mkdirp");
const rimraf = require("rmfr");
const { promises: fs } = require("fs");
const getarg = require("get-cli-arg").default;
// prepare
const template = getarg("template") || "eco";
const total = Number(getarg("total") || 1000);
const templatePath = join(__dirname, "templates");
const renderPath = join(__dirname, "src", "render");
const outPath = join(__dirname, "out");
// handle
async function main() {
// read the file
let templateSource = await fs.readFile(
join(templatePath, "template.html." + template),
"utf8"
);
// ensure path
await rimraf(outPath);
await mkdirp(outPath);
await rimraf(renderPath);
await mkdirp(renderPath);
await Promise.all(
Array(total)
.fill(null)
.map(async (_, i) => {
const templateOutPath = join(renderPath, i + ".html." + template);
const templateOutSource = templateSource
.toString()
.replace(/NUMBER/g, i);
await fs.writeFile(templateOutPath, templateOutSource);
})
);
}
main();