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();