const fs = require('fs'); const os = require('os'); const path = require('path'); const {execFileSync} = require('child_process'); const esbuild = require('esbuild'); const {version: packageVersion} = require('../package.json'); function normalizeBuildVersion(value) { const version = (value || packageVersion || '0.0.0').toString().trim(); return version.startsWith('v') ? version : `v${version}`; } async function main() { const distDir = path.resolve(__dirname, '..', 'dist'); if (!fs.existsSync(distDir)) { fs.mkdirSync(distDir, {recursive: true}); } const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsa-sea-')); const bundlePath = path.join(tempDir, 'index.cjs'); const seaBlobPath = path.join(tempDir, 'sea-prep.blob'); const seaConfigPath = path.join(tempDir, 'sea-config.json'); const buildVersion = normalizeBuildVersion(process.env.BUILD_VERSION); const outputFile = path.join(distDir, `gSheets-Rate-Assistant-${buildVersion}.exe`); await esbuild.build({ entryPoints: [path.resolve(__dirname, '..', 'index.js')], bundle: true, platform: 'node', format: 'cjs', target: 'node26', outfile: bundlePath, logLevel: 'info', }); fs.writeFileSync(seaConfigPath, JSON.stringify({ main: bundlePath, output: outputFile, mainFormat: 'commonjs', disableExperimentalSEAWarning: true, useCodeCache: false, useSnapshot: false, }, null, 2)); execFileSync(process.execPath, ['--build-sea', seaConfigPath], {stdio: 'inherit'}); } main().catch(error => { console.error(error && error.stack ? error.stack : error); process.exit(1); });