/* * sync-build-version.js — make `buildNumber` mean something. * * package.json carried TWO build numbers: a top-level `buildNumber` that was * dutifully bumped every release and read by absolutely nothing, and * `build.buildVersion` — the one electron-builder writes to CFBundleVersion — * hardcoded at "51" since 3.4.0. So the installed app reported build 51 while * the release was build 55, and the DMG filename was the only honest clue * anywhere. Runs as `predist`, so bumping buildNumber alone is now enough. */ 'use strict'; const fs = require('fs'); const path = require('path'); const p = path.join(__dirname, '..', 'package.json'); const raw = fs.readFileSync(p, 'utf8'); const pkg = JSON.parse(raw); const want = String(pkg.buildNumber || '').trim(); if (!want) { console.error('package.json has no buildNumber — refusing to build a build with no number'); process.exit(1); } if (!/^\d+$/.test(want)) { console.error('buildNumber must be digits, got "' + want + '"'); process.exit(1); } const have = String((pkg.build && pkg.build.buildVersion) || ''); if (have === want) { console.log('build number ' + want + ' (CFBundleVersion already matches)'); process.exit(0); } /* Rewrite the one value textually rather than re-serialising the whole file, so this never reformats a config the operator's settings depend on. */ const re = /("buildVersion"\s*:\s*")([^"]*)(")/; if (!re.test(raw)) { console.error('could not find build.buildVersion in package.json'); process.exit(1); } fs.writeFileSync(p, raw.replace(re, '$1' + want + '$3')); console.log('CFBundleVersion ' + (have || '(unset)') + ' -> ' + want);