小橘 f7cf1a1cb2 refactor: single-package workspace with root esbuild build
Merge workflow and sense devDependencies into root, remove per-package package.json and workflow tsconfigs, add scripts/build.mjs for consistent outputs.

Fixes #22
2026-04-30 09:03:05 +00:00

51 lines
1.3 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 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("."))
.map((name) => path.join(dir, name))
.filter((p) => fs.statSync(p).isDirectory());
}
async function main() {
for (const dir of listDirs(path.join(root, "senses"))) {
const entry = path.join(dir, "src", "index.ts");
if (!fs.existsSync(entry)) continue;
await esbuild.build({
...opts,
entryPoints: [entry],
outfile: path.join(dir, "index.js"),
});
}
for (const dir of listDirs(path.join(root, "workflows"))) {
const base = path.basename(dir);
if (base.startsWith("_")) continue;
const entry = path.join(dir, "index.ts");
if (!fs.existsSync(entry)) continue;
const outDir = path.join(dir, "dist");
fs.mkdirSync(outDir, { recursive: true });
await esbuild.build({
...opts,
entryPoints: [entry],
outfile: path.join(outDir, "index.js"),
});
}
}
await main();