Files
Capsule/scripts/package.mjs

31 lines
1.4 KiB
JavaScript

import { build, Platform, Arch } from 'electron-builder'
import { rm } from 'node:fs/promises'
import { createBuildConfig } from '../build/config.mjs'
import { writeReleaseManifest } from './releaseArtifacts.mjs'
const args = process.argv.slice(2)
if (args.some((arg) => !['--release', '--dir', '--test-updates', '--bootstrap'].includes(arg))) {
throw new Error('Usage: node scripts/package.mjs [--release | --test-updates [--bootstrap]] [--dir]')
}
const release = args.includes('--release')
const testUpdates = args.includes('--test-updates')
const bootstrap = args.includes('--bootstrap')
if (testUpdates && args.includes('--dir')) throw new Error('Test update builds must produce an installer.')
if (release && args.includes('--dir')) throw new Error('Release builds must produce an installer.')
// Never let a failed rebuild leave an older directory looking publishable.
if (release) {
await rm('dist/release/release-ready.json', { force: true })
} else {
process.env.CSC_IDENTITY_AUTO_DISCOVERY = 'false'
}
const config = createBuildConfig({ release, testUpdates, bootstrap })
if (testUpdates) await rm(`${config.directories.output}/release-ready.json`, { force: true })
await build({
config,
targets: Platform.WINDOWS.createTarget(args.includes('--dir') ? ['dir'] : ['nsis'], Arch.x64),
publish: 'never'
})
if (release || testUpdates) {
await writeReleaseManifest(config.directories.output, config.publish[0].url)
}