-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.mjs
49 lines (40 loc) · 1.46 KB
/
build.mjs
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
import { execSync, spawnSync } from "child_process";
import { existsSync, readdirSync } from "fs";
import { join } from "path";
import { argv, cwd, exit, platform } from "process";
// get all arguments
const args = argv.slice(2);
if (args.includes("--all")) {
const plugins = readdirSync("plugins").filter(file => existsSync(join("plugins", file, "manifest.json")));
for (const plugin of plugins) {
execSync(`pnpm build ${plugin}`, { stdio: "inherit" });
}
exit(0);
}
const plugin = args.find(arg => !arg.startsWith("--"));
if (!plugin) {
console.error("ERROR: No plugin specified");
console.error("Usage: pnpm build <plugin> [--watch] [--package=<package-name>]");
exit(1);
}
const packageName = args.find(arg => arg.startsWith("--package="))?.split("=")[1];
const watch = args.includes("--watch") || args.includes("-w");
const pluginDir = plugin.match(/(\\|\/)/) ? plugin : join("plugins", plugin);
const entry = readdirSync(pluginDir).find(file => file.startsWith("index."));
const entryPath = join(pluginDir, entry);
const rollupExec = platform === "win32" ? ".\\node_modules\\.bin\\rollup.cmd" : "node_modules/.bin/rollup";
const rollupArgs = ["-c", "--configPlugin", "typescript", watch && "--watch"].filter(Boolean);
const env = {
plugin,
pluginDir,
entryPath,
packageName
};
const proc = spawnSync(rollupExec, rollupArgs, {
stdio: "inherit",
cwd: cwd(),
env
});
if (proc.error) {
console.error(proc.error);
}