forked from jacomyal/sigma.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·59 lines (48 loc) · 1.5 KB
/
build.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
const fs = require("fs-extra");
const path = require("path");
const rimraf = require("rimraf");
const { eachSeries } = require("async");
const kotatsu = require("kotatsu");
const outputDir = process.argv[2];
if (!outputDir) {
console.error("Missing output directory!");
process.exit(1);
}
rimraf.sync(outputDir);
fs.mkdirSync(outputDir, { recursive: true });
const examples = require("./examples.json");
function buildExample(name, callback) {
console.log();
console.log(`Building ${name}...`);
const inputSubFolder = path.resolve(__dirname, name);
const outputSubFolder = path.resolve(outputDir, name);
fs.mkdirSync(outputSubFolder);
fs.mkdirSync(path.resolve(outputSubFolder, "build"));
fs.copyFileSync(path.resolve(inputSubFolder, "index.html"), path.resolve(outputSubFolder, "index.html"));
if (fs.existsSync(path.resolve(inputSubFolder, "public"))) {
fs.mkdirSync(path.resolve(outputSubFolder, "public"));
fs.copySync(path.resolve(inputSubFolder, "public"), path.resolve(outputSubFolder, "public"));
}
kotatsu.build(
"front",
{
entry: path.resolve(inputSubFolder, "index.ts"),
config: require("./webpack.config"),
output: path.resolve(outputSubFolder, "build/bundle.js"),
production: true,
},
callback,
);
}
eachSeries(
examples,
(example, next) => {
buildExample(example.name, next);
},
(err) => {
if (err) return console.error(err);
console.log();
console.log("Finished building examples!");
},
);