setup-binaries.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env node
  2. /**
  3. * setup-binaries.js — Idempotent Neutralinojs binary setup.
  4. *
  5. * Ensures the bin/ folder contains platform binaries matching the version
  6. * pinned in neutralino.config.json (cli.binaryVersion). Downloads them
  7. * via `neu update` only when missing or when the pinned version changes.
  8. *
  9. * A version marker (bin/.version) tracks the installed version so that
  10. * repeated builds and dev runs skip the download entirely.
  11. *
  12. * Run from the desktop-app/ directory:
  13. * node setup-binaries.js
  14. */
  15. const fs = require("fs");
  16. const path = require("path");
  17. const { execSync } = require("child_process");
  18. const CONFIG_FILE = path.resolve(__dirname, "neutralino.config.json");
  19. const BIN_DIR = path.resolve(__dirname, "bin");
  20. const VERSION_MARKER = path.join(BIN_DIR, ".version");
  21. /** Neu CLI package — same version used across all npm scripts */
  22. const NEU_CLI = "@neutralinojs/neu@11.7.0";
  23. const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
  24. const expectedVersion = config.cli.binaryVersion;
  25. if (!expectedVersion) {
  26. console.error("✗ cli.binaryVersion not set in neutralino.config.json");
  27. process.exit(1);
  28. }
  29. /** Check if binaries are already present and match the expected version */
  30. if (fs.existsSync(VERSION_MARKER)) {
  31. const installed = fs.readFileSync(VERSION_MARKER, "utf-8").trim();
  32. if (installed === expectedVersion) {
  33. console.log(
  34. `✓ Neutralinojs binaries v${expectedVersion} already present — skipping download`,
  35. );
  36. process.exit(0);
  37. }
  38. console.log(
  39. `↻ Version changed (${installed} → ${expectedVersion}) — re-downloading`,
  40. );
  41. }
  42. /** Download binaries + client library via neu update */
  43. console.log(`⬇ Downloading Neutralinojs v${expectedVersion} binaries...`);
  44. execSync(`npx -y ${NEU_CLI} update`, {
  45. cwd: __dirname,
  46. stdio: "inherit",
  47. });
  48. /** Write version marker so subsequent runs are no-ops */
  49. fs.mkdirSync(BIN_DIR, { recursive: true });
  50. fs.writeFileSync(VERSION_MARKER, expectedVersion, "utf-8");
  51. console.log(`✓ Neutralinojs binaries v${expectedVersion} ready`);