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-02-26 00:34:16 +00:00
|
|
|
import { rollup } from "rollup";
|
|
|
|
import { swc } from "rollup-plugin-swc3";
|
|
|
|
import { typescriptPaths } from "rollup-plugin-typescript-paths";
|
|
|
|
import esbuild from "rollup-plugin-esbuild";
|
|
|
|
import replace from "@rollup/plugin-replace";
|
|
|
|
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
|
|
|
|
|
|
const exec = promisify(_exec);
|
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-02-26 00:34:16 +00:00
|
|
|
const bundle = await rollup({
|
|
|
|
input: "src/index.ts",
|
|
|
|
onwarn: () => {},
|
2023-01-01 21:10:09 +00:00
|
|
|
plugins: [
|
2023-01-10 23:30:46 +00:00
|
|
|
replace({
|
2023-02-26 00:34:16 +00:00
|
|
|
__vendettaVersion: commit,
|
|
|
|
preventAssignment: true,
|
|
|
|
}),
|
|
|
|
typescriptPaths(),
|
|
|
|
nodeResolve({ extensions: [".tsx", ".ts", ".jsx", ".js", ".json"] }),
|
|
|
|
swc({
|
|
|
|
env: {
|
|
|
|
targets: "defaults",
|
|
|
|
include: [
|
|
|
|
"transform-classes",
|
|
|
|
"transform-arrow-functions",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
esbuild({ minify: true }),
|
2023-01-01 21:10:09 +00:00
|
|
|
],
|
2022-10-18 22:04:55 +00:00
|
|
|
});
|
|
|
|
|
2023-02-26 00:34:16 +00:00
|
|
|
await bundle.write({
|
|
|
|
format: "iife",
|
|
|
|
file: "dist/vendetta.js",
|
|
|
|
compact: true,
|
|
|
|
});
|
|
|
|
await bundle.close();
|
|
|
|
|
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-02-26 00:34:16 +00:00
|
|
|
}
|