2023-03-07 00:23:16 +00:00
|
|
|
import { build } from "esbuild";
|
|
|
|
import { replace } from "esbuild-plugin-replace";
|
|
|
|
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({
|
|
|
|
entryPoints: ["./src/index.ts"],
|
|
|
|
outfile: "./dist/vendetta.js",
|
|
|
|
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),
|
|
|
|
replace({
|
|
|
|
"__vendettaVersion": commit,
|
2023-02-26 00:34:16 +00:00
|
|
|
}),
|
2023-01-01 21:10:09 +00:00
|
|
|
],
|
2023-03-07 00:23:16 +00:00
|
|
|
legalComments: "none",
|
2022-10-18 22:04:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await fs.appendFile("./dist/vendetta.js", "//# sourceURL=Vendetta");
|
|
|
|
console.log("Build successful!");
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Build failed...", e);
|
|
|
|
process.exit(1);
|
2023-03-07 00:23:16 +00:00
|
|
|
}
|