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