quick build
This commit is contained in:
parent
04cc2ccc2d
commit
a8a8607456
2 changed files with 87 additions and 0 deletions
|
|
@ -23,6 +23,7 @@
|
|||
"scripts": {
|
||||
"test": "jest",
|
||||
"build": "node build.js",
|
||||
"quick-build": "node build.js --target darwin-arm64",
|
||||
"build:darwin-x64": "node build.js --os darwin-x64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
|
|
|
|||
86
binary/quick-build.js
Normal file
86
binary/quick-build.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
const esbuild = require("esbuild");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const {
|
||||
execCmdSync,
|
||||
validateFilesPresent,
|
||||
autodetectPlatformAndArch,
|
||||
} = require("../scripts/util");
|
||||
|
||||
// Paths
|
||||
const bin = path.join(__dirname, "bin");
|
||||
const esbuildOutputFile = "out/index.js";
|
||||
let targets = [
|
||||
"darwin-x64",
|
||||
"darwin-arm64",
|
||||
"linux-x64",
|
||||
"linux-arm64",
|
||||
"win32-x64",
|
||||
];
|
||||
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
if (process.argv[i - 1] === "--target") {
|
||||
targets = [process.argv[i]];
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
for (const target of targets) {
|
||||
const exe = target.startsWith("win") ? ".exe" : "";
|
||||
const targetDir = path.join(bin, target);
|
||||
fs.rmSync(path.join(targetDir, `continue-binary${exe}`), { force: true });
|
||||
}
|
||||
|
||||
// Validate files to ensure prerequisites are available
|
||||
const filesToValidate = [
|
||||
"src/index.ts",
|
||||
"../core/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js",
|
||||
"../core/llm/tiktokenWorkerPool.mjs",
|
||||
"../core/llm/llamaTokenizerWorkerPool.mjs",
|
||||
];
|
||||
validateFilesPresent(filesToValidate);
|
||||
|
||||
// Quick Build
|
||||
(async () => {
|
||||
console.log("[info] Building with esbuild...");
|
||||
await esbuild.build({
|
||||
entryPoints: ["src/index.ts"],
|
||||
bundle: true,
|
||||
outfile: esbuildOutputFile,
|
||||
external: [
|
||||
"esbuild",
|
||||
"./xhr-sync-worker.js",
|
||||
"llamaTokenizerWorkerPool.mjs",
|
||||
"tiktokenWorkerPool.mjs",
|
||||
"vscode",
|
||||
"./index.node",
|
||||
],
|
||||
format: "cjs",
|
||||
platform: "node",
|
||||
sourcemap: true,
|
||||
minify: true,
|
||||
treeShaking: true,
|
||||
loader: { ".node": "file" },
|
||||
inject: ["./importMetaUrl.js"],
|
||||
define: { "import.meta.url": "importMetaUrl" },
|
||||
});
|
||||
|
||||
console.log("[info] Building binaries with pkg...");
|
||||
for (const target of targets) {
|
||||
const targetDir = path.join(bin, target);
|
||||
fs.mkdirSync(targetDir, { recursive: true });
|
||||
console.log(`[info] Building ${target}...`);
|
||||
execCmdSync(
|
||||
`npx pkg --no-bytecode --public-packages "*" --public pkgJson/${target} --out-path ${targetDir}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Validate only continue-binary files
|
||||
const pathsToVerify = targets.map((target) => {
|
||||
const exe = target.startsWith("win") ? ".exe" : "";
|
||||
return path.join(bin, target, `continue-binary${exe}`);
|
||||
});
|
||||
validateFilesPresent(pathsToVerify);
|
||||
|
||||
console.log("[info] Quick build completed!");
|
||||
})();
|
||||
Loading…
Add table
Reference in a new issue