Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
- Removed @napi-rs/canvas and pdf-to-img dependencies from package.json and bun.lock to streamline the project. - Added PDF.js data directory configuration in the Linux service file and build scripts. - Introduced a new pdfToImg module for rendering PDF pages to images, enhancing PDF conversion capabilities. - Updated pdfUtils to utilize the new pdfToImg function, improving efficiency and modularity.
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import path from "node:path";
|
|
|
|
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const packageJson = JSON.parse(
|
|
readFileSync(path.join(rootDir, "package.json"), "utf8"),
|
|
);
|
|
|
|
let buildNumber =
|
|
process.env.BUILD_NUMBER || process.env.VITE_BUILD_NUMBER || "dev";
|
|
try {
|
|
const buildInfo = JSON.parse(
|
|
readFileSync(path.join(rootDir, "src/buildInfo.json"), "utf8"),
|
|
);
|
|
buildNumber = buildInfo.buildNumber ?? buildNumber;
|
|
} catch {}
|
|
|
|
const outputDir = path.join(rootDir, "app_dist/linux");
|
|
const outputFile = path.join(outputDir, "farmcontrol-server");
|
|
|
|
await Bun.$`mkdir -p ${outputDir}`;
|
|
|
|
const result = await Bun.build({
|
|
entrypoints: [path.join(rootDir, "src/headless.js")],
|
|
outdir: path.join(rootDir, "build/linux-bundle"),
|
|
target: "bun",
|
|
format: "esm",
|
|
define: {
|
|
"process.env.FC_PACKAGE_VERSION": JSON.stringify(packageJson.version),
|
|
"process.env.FC_BUILD_NUMBER": JSON.stringify(buildNumber),
|
|
},
|
|
});
|
|
|
|
if (!result.success) {
|
|
console.error("Bun build failed");
|
|
for (const log of result.logs) {
|
|
console.error(log);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
|
|
const compileResult = Bun.spawn([
|
|
"bun",
|
|
"build",
|
|
"--compile",
|
|
"--target=bun-linux-x64",
|
|
path.join(rootDir, "build/linux-bundle/headless.js"),
|
|
"--outfile",
|
|
outputFile,
|
|
], {
|
|
cwd: rootDir,
|
|
stdout: "inherit",
|
|
stderr: "inherit",
|
|
});
|
|
|
|
const exitCode = await compileResult.exited;
|
|
if (exitCode !== 0) {
|
|
process.exit(exitCode);
|
|
}
|
|
|
|
const pdfjsDataDir = path.join(outputDir, "pdfjs-data");
|
|
const pdfjsDistDir = path.join(rootDir, "node_modules/pdfjs-dist");
|
|
await Bun.$`mkdir -p ${pdfjsDataDir}`;
|
|
await Bun.$`cp -r ${path.join(pdfjsDistDir, "standard_fonts")} ${path.join(pdfjsDataDir, "standard_fonts")}`;
|
|
await Bun.$`cp -r ${path.join(pdfjsDistDir, "cmaps")} ${path.join(pdfjsDataDir, "cmaps")}`;
|
|
|
|
console.log(`Linux binary written to ${outputFile}`);
|
|
console.log(`PDF.js data copied to ${pdfjsDataDir}`);
|