39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
|
import { URL } from "node:url";
|
||
|
import path from "node:path";
|
||
|
import caxa from "caxa";
|
||
|
import { rollup } from "rollup";
|
||
|
import loadConfigFile from "rollup/loadConfigFile";
|
||
|
import { executorLibraryDir, binName, scriptName } from "./executor-config.js";
|
||
|
// Fix import
|
||
|
const { default: caxaPackage } = caxa;
|
||
|
// Rollup Config
|
||
|
const rollupConfigPath = path.resolve(executorLibraryDir, "rollup.config.js");
|
||
|
|
||
|
// Build functions
|
||
|
async function packageBin() {
|
||
|
console.log("Packaging bundle into binary");
|
||
|
return caxaPackage({
|
||
|
input: "dist/bundles/",
|
||
|
output: `bin/${binName}`,
|
||
|
command: ["{{caxa}}/node_modules/.bin/node", `{{caxa}}/${scriptName}`],
|
||
|
uncompressionMessage: "Unpacking, please wait...",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async function rollupBundle() {
|
||
|
console.log("Rolling up executor into bundle");
|
||
|
const { options, warnings } = await loadConfigFile(rollupConfigPath);
|
||
|
if (warnings.count !== 0)
|
||
|
console.log(`Rollup has ${warnings.count} warnings`);
|
||
|
warnings.flush();
|
||
|
|
||
|
for (const optionsObj of options) {
|
||
|
const bundle = await rollup(optionsObj);
|
||
|
await Promise.all(optionsObj.output.map(bundle.write));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
await rollupBundle();
|
||
|
await packageBin();
|
||
|
console.log("Done");
|