-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.js
More file actions
83 lines (76 loc) · 2.21 KB
/
build.js
File metadata and controls
83 lines (76 loc) · 2.21 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
const here = path.dirname(new URL(import.meta.url).pathname);
console.info("Preparing docs...");
run("yarn", ["workspace", "docs", "prebuild"]);
console.info("Running typescript...");
run("yarn", ["tsc", "-b"]);
console.info("Creating changesets...");
run("yarn", ["changeset", "version", "--snapshot", "not-released-yet"]);
console.info("Building docs...");
run("yarn", ["workspace", "docs", "build"]);
console.info("Building opendesign...");
run("yarn", ["workspace", "opendesign", "vite", "build"]);
if (fs.existsSync(".git")) {
console.info("Cleaning up changesets...");
run("git", [
"checkout",
"@",
".changeset",
...packageFiles("CHANGELOG.md"),
...packageFiles("package.json"),
]);
}
const editor = path.join(here, "packages", "opendesign", "dist", "editor");
const docs = path.join(here, "packages", "docs", "dist");
const dist = path.join(here, "dist");
console.info("Creating shared dist...");
fs.rmSync(dist, { force: true, recursive: true });
fs.mkdirSync(dist);
copy(docs, dist);
fs.renameSync(path.join(dist, "index.html"), path.join(dist, "changelog.html"));
copy(editor, dist);
/**
* @param {string} from
* @param {string} to
*/
function copy(from, to) {
for (const f of fs.readdirSync(from)) {
const stat = statIfExists(path.join(to, f));
if (stat?.isDirectory()) {
copy(path.join(from, f), path.join(to, f));
} else {
fs.renameSync(path.join(from, f), path.join(to, f));
}
}
}
/**
* @param {string} p
*/
function statIfExists(p) {
try {
return fs.statSync(p);
} catch (e) {
if (e.code === "ENOENT") return null;
throw e;
}
}
/**
*
* @param {string} cmd
* @param {readonly string[]} args
*/
function run(cmd, args) {
const res = spawnSync(cmd, args, { stdio: ["ignore", "inherit", "inherit"] });
if (res.status !== 0)
throw new Error("Command failed: " + cmd + " " + args.join(" "));
}
function packageFiles(file) {
const list = [];
for (const dir of fs.readdirSync(path.join(here, "packages"))) {
const filePath = path.join(here, "packages", dir, file);
if (fs.existsSync(filePath)) list.push(filePath);
}
return list;
}