- senses build to dist/senses/<name>/index.js - workflows build to dist/workflows/<name>/index.js - scripts/build.mjs: clean dist/ before build, output to dist/ - .gitignore: simplified to just dist/ 小橘 <xiaoju@shazhou.work>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import * as esbuild from "esbuild";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const dist = path.join(root, "dist");
|
|
|
|
const opts = {
|
|
bundle: true,
|
|
platform: "node",
|
|
format: "esm",
|
|
packages: "external",
|
|
};
|
|
|
|
function listDirs(dir) {
|
|
if (!fs.existsSync(dir)) return [];
|
|
return fs
|
|
.readdirSync(dir)
|
|
.filter((name) => !name.startsWith(".") && !name.startsWith("_"))
|
|
.map((name) => ({ name, full: path.join(dir, name) }))
|
|
.filter(({ full }) => fs.statSync(full).isDirectory());
|
|
}
|
|
|
|
async function main() {
|
|
// Clean dist/
|
|
fs.rmSync(dist, { recursive: true, force: true });
|
|
|
|
for (const { name, full } of listDirs(path.join(root, "senses"))) {
|
|
const entry = path.join(full, "src", "index.ts");
|
|
if (!fs.existsSync(entry)) continue;
|
|
const outfile = path.join(dist, "senses", name, "index.js");
|
|
fs.mkdirSync(path.dirname(outfile), { recursive: true });
|
|
await esbuild.build({ ...opts, entryPoints: [entry], outfile });
|
|
}
|
|
|
|
for (const { name, full } of listDirs(path.join(root, "workflows"))) {
|
|
const entry = path.join(full, "index.ts");
|
|
if (!fs.existsSync(entry)) continue;
|
|
const outfile = path.join(dist, "workflows", name, "index.js");
|
|
fs.mkdirSync(path.dirname(outfile), { recursive: true });
|
|
await esbuild.build({ ...opts, entryPoints: [entry], outfile });
|
|
}
|
|
}
|
|
|
|
await main();
|