2023-03-07 00:23:16 +00:00
|
|
|
import { build } from "esbuild";
|
|
|
|
import alias from "esbuild-plugin-alias";
|
|
|
|
import swc from "@swc/core";
|
2023-01-10 23:30:46 +00:00
|
|
|
import { promisify } from "util";
|
|
|
|
import { exec as _exec } from "child_process";
|
2022-10-18 22:04:55 +00:00
|
|
|
import fs from "fs/promises";
|
2023-03-07 00:23:16 +00:00
|
|
|
import path from "path";
|
2023-02-26 00:34:16 +00:00
|
|
|
const exec = promisify(_exec);
|
2023-03-07 00:23:16 +00:00
|
|
|
|
|
|
|
const tsconfig = JSON.parse(await fs.readFile("./tsconfig.json"));
|
|
|
|
const aliases = Object.fromEntries(Object.entries(tsconfig.compilerOptions.paths).map(([alias, [target]]) => [alias, path.resolve(target)]));
|
2023-01-10 23:30:46 +00:00
|
|
|
const commit = (await exec("git rev-parse HEAD")).stdout.trim().substring(0, 7) || "custom";
|
2022-10-18 22:04:55 +00:00
|
|
|
|
|
|
|
try {
|
2023-03-07 00:23:16 +00:00
|
|
|
await build({
|
2023-04-05 19:54:14 +00:00
|
|
|
entryPoints: ["./src/entry.ts"],
|
2024-02-08 16:58:41 +00:00
|
|
|
outfile: "./dist/revenge.js",
|
2023-03-07 00:23:16 +00:00
|
|
|
minify: true,
|
|
|
|
bundle: true,
|
|
|
|
format: "iife",
|
|
|
|
target: "esnext",
|
2023-01-01 21:10:09 +00:00
|
|
|
plugins: [
|
2023-03-07 00:23:16 +00:00
|
|
|
{
|
|
|
|
name: "swc",
|
|
|
|
setup: (build) => {
|
|
|
|
build.onLoad({ filter: /\.[jt]sx?/ }, async (args) => {
|
|
|
|
// This actually works for dependencies as well!!
|
|
|
|
const result = await swc.transformFile(args.path, {
|
|
|
|
jsc: {
|
|
|
|
externalHelpers: true,
|
|
|
|
},
|
|
|
|
env: {
|
|
|
|
targets: "defaults",
|
|
|
|
include: [
|
|
|
|
"transform-classes",
|
|
|
|
"transform-arrow-functions",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return { contents: result.code };
|
|
|
|
});
|
2023-02-26 00:34:16 +00:00
|
|
|
},
|
2023-03-07 00:23:16 +00:00
|
|
|
},
|
|
|
|
alias(aliases),
|
2023-01-01 21:10:09 +00:00
|
|
|
],
|
2023-03-07 07:54:25 +00:00
|
|
|
define: {
|
2024-02-08 19:04:56 +00:00
|
|
|
__revengeVersion: `"${commit}"`,
|
2023-03-07 07:54:25 +00:00
|
|
|
},
|
2023-03-15 16:36:12 +00:00
|
|
|
footer: {
|
2024-02-08 16:58:41 +00:00
|
|
|
js: "//# sourceURL=Revenge",
|
2023-03-15 16:36:12 +00:00
|
|
|
},
|
2023-03-07 00:23:16 +00:00
|
|
|
legalComments: "none",
|
2022-10-18 22:04:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Build successful!");
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Build failed...", e);
|
|
|
|
process.exit(1);
|
2023-03-31 14:46:55 +00:00
|
|
|
}
|