|
|
#!/usr/bin/env node |
|
|
|
|
|
const { execSync } = require( 'child_process' ); |
|
|
const fs = require( 'fs' ); |
|
|
const path = require( 'path' ); |
|
|
const yaml = require( 'js-yaml' ); |
|
|
|
|
|
const PROJECT_DIR = path.join( __dirname, '..' ); |
|
|
const BUILD_DIR = path.join( PROJECT_DIR, 'release' ); |
|
|
const ELECTRON_BUILDER_ARGS = process.env.ELECTRON_BUILDER_ARGS || ''; |
|
|
const isReleaseBuild = process.env.RELEASE_BUILD === 'true'; |
|
|
|
|
|
|
|
|
const arches = isReleaseBuild ? [ 'x64', 'arm64' ] : [ 'arm64' ]; |
|
|
|
|
|
for ( let i = 0; i < arches.length; i++ ) { |
|
|
const arch = arches[ i ]; |
|
|
console.log( ` • Building artifacts for arch ${ arch }...` ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pythonExe = process.env.PYTHON || '/Library/Developer/CommandLineTools/usr/bin/python3'; |
|
|
|
|
|
try { |
|
|
|
|
|
execSync( `PYTHON="${ pythonExe }" npx electron-rebuild --force --arch=${ arch }`, { |
|
|
stdio: 'inherit', |
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
execSync( |
|
|
`npx electron-builder build ${ ELECTRON_BUILDER_ARGS } -c.npmRebuild=false --${ arch } --publish never`, |
|
|
{ |
|
|
stdio: 'inherit', |
|
|
} |
|
|
); |
|
|
|
|
|
if ( isReleaseBuild ) { |
|
|
|
|
|
execSync( `mv latest-mac.yml latest-mac-${ arch }.yml`, { cwd: BUILD_DIR } ); |
|
|
} |
|
|
} catch ( e ) { |
|
|
console.error( `Build error: `, e ); |
|
|
process.exit( 1 ); |
|
|
} |
|
|
|
|
|
console.log( ` • OK built ${ arch } artifacts ${ '\n' }` ); |
|
|
} |
|
|
|
|
|
if ( isReleaseBuild ) { |
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mergeYaml(); |
|
|
} catch ( e ) { |
|
|
console.error( `Error generating artifact YML: `, e ); |
|
|
process.exit( 1 ); |
|
|
} |
|
|
} |
|
|
|
|
|
console.log( ' • OK built all artifacts\n\n' ); |
|
|
|
|
|
function mergeYaml() { |
|
|
const x64YAML = path.join( BUILD_DIR, 'latest-mac-x64.yml' ); |
|
|
const arm64YAML = path.join( BUILD_DIR, 'latest-mac-arm64.yml' ); |
|
|
|
|
|
const x64 = yaml.load( fs.readFileSync( x64YAML ), 'utf8' ); |
|
|
const arm64 = yaml.load( fs.readFileSync( arm64YAML ), 'utf8' ); |
|
|
|
|
|
x64.files = x64.files.concat( arm64.files ); |
|
|
|
|
|
const merged = yaml.dump( x64, { indent: 2, lineWidth: -1 } ); |
|
|
fs.writeFileSync( path.join( BUILD_DIR, 'latest-mac.yml' ), merged ); |
|
|
|
|
|
fs.unlinkSync( x64YAML ); |
|
|
fs.unlinkSync( arm64YAML ); |
|
|
|
|
|
console.log( ' • OK updated latest-mac.yml: \n', x64 ); |
|
|
} |
|
|
|