-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.mjs
More file actions
78 lines (65 loc) · 1.79 KB
/
build.mjs
File metadata and controls
78 lines (65 loc) · 1.79 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
import { spawnSync } from "node:child_process";
import { resolve, basename } from "node:path";
import { jsxDir, srcEntries, svgDir } from "./shared.mjs";
import fg from "fast-glob";
import { writeFileSync } from "node:fs";
gen();
function gen() {
for (const set of srcEntries) {
const svgPath = resolve(svgDir, set);
const jsxPath = resolve(jsxDir, set);
// Gen icons
console.info(`[${set}]`, "generating icons");
const iconsRes = spawnSync("npx", [
"@svgr/cli",
svgPath,
"--out-dir",
// jsx,
jsxPath,
]);
if (iconsRes.status !== 0) {
console.error(iconsRes.stderr?.toString?.());
process.exit(iconsRes.status);
}
// Compile jsx
console.info(`[${set}]`, "compiling jsx");
const compileRes = spawnSync("npx", [
"tsup",
// jsx,
jsxPath,
"--out-dir",
set,
"--format",
"esm",
"--dts",
"--minify",
"--clean",
"--external",
"react",
"--external",
"react-dom",
"--external",
"react/jsx-runtime",
]);
if (compileRes.status !== 0) {
console.error(compileRes.stderr?.toString?.());
process.exit(compileRes.status);
}
// HACK: force override `{set}/index.d.ts`
// did not know why the first file ignored
console.info(`[${set}]`, "overriding `index.d.ts`");
const dtsFiles = fg.sync("**/*.d.ts", {
cwd: set,
ignore: ["index.d.ts"],
});
const dtsString =
dtsFiles
.map((filename) => {
const dtsExtname = ".d.ts";
const name = basename(filename, dtsExtname);
return `export { default as ${name} } from './${name}.js';`;
})
.join("\n") + `\nimport 'react'`;
writeFileSync(resolve(set, "index.d.ts"), dtsString, "utf8");
}
}