apprev/build.mjs
2025-05-23 19:23:53 -04:00

57 lines
1.3 KiB
JavaScript

import { build } from "esbuild";
import { spawn } from "child_process";
import { execSync } from "child_process";
/**
* @type {esbuild.Plugin}
*/
const makeAllPackagesExternalPlugin = {
name: "make-all-packages-external",
setup(build) {
const filter = /(oceanic\.js|sqlite3)/; // Whitelist of dumb packages
build.onResolve({ filter }, (args) => ({
path: args.path,
external: true
}));
}
};
await build({
entryPoints: ["src/index.ts"],
bundle: true,
plugins: [makeAllPackagesExternalPlugin],
platform: "node",
target: "esnext",
logLevel: "info",
outfile: "dist/index.js",
minify: !process.argv.includes("start"),
treeShaking: true, // shake it off shake it offff
jsx: "transform",
inject: ["components-jsx/runtime.ts"],
jsxFactory: "createElement",
jsxFragment: "Fragment"
});
setInterval(() => {}, 100);
if (process.argv.includes("start")) {
try {
execSync(
`ps aux | grep '[n]ode.*dist/index.js --i-am-apprev' | awk '{print $2}' | xargs -r kill -9`,
{ stdio: "ignore" }
);
} catch {
console.error(
"Failed to kill old bot. Duplicate instances may run.\nIf you are on Windows use WSL/Linux"
);
}
const proc = spawn(
"node",
["--env-file=.env", "dist/index.js", "--i-am-apprev"],
{
stdio: "inherit"
}
);
proc.on("exit", (code) => process.exit(code));
proc.on("close", (code) => process.exit(code));
}