mirror of
https://gh-proxy.org/https://github.com/klinsmaya/workdsh.git
synced 2026-11-08 01:17:05 +08:00
80 lines
2.7 KiB
JavaScript
80 lines
2.7 KiB
JavaScript
/** Build an unsigned unpacked application for the current host platform. */
|
|
|
|
import { spawnSync } from 'node:child_process'
|
|
import { createRequire } from 'node:module'
|
|
import { dirname, resolve } from 'node:path'
|
|
import { existsSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { electronBuilderEnvironment } from './electron-builder-environment.ts'
|
|
import { withoutWindowsSigningSecrets } from './package-win.ts'
|
|
import { withoutMacReleaseSecrets } from './release-preflight.ts'
|
|
|
|
const require = createRequire(import.meta.url)
|
|
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)))
|
|
const builderCli = require.resolve('electron-builder/cli.js')
|
|
const electronDist = resolve(dirname(require.resolve('electron/package.json')), 'dist')
|
|
|
|
/** Electron Builder overrides that make the directory build unconditionally unsigned. */
|
|
export const UNSIGNED_DIRECTORY_BUILD_ARGS = Object.freeze([
|
|
'--dir',
|
|
'--publish',
|
|
'never',
|
|
'--config.forceCodeSigning=false',
|
|
'--config.mac.identity=null',
|
|
'--config.mac.notarize=false',
|
|
'--config.win.signExecutable=false',
|
|
])
|
|
|
|
/**
|
|
* Remove every release credential recognized by the native release entry points.
|
|
* @param {NodeJS.ProcessEnv} environment
|
|
* @returns {NodeJS.ProcessEnv}
|
|
*/
|
|
export function unsignedDirectoryBuildEnvironment(environment) {
|
|
return electronBuilderEnvironment({
|
|
...withoutWindowsSigningSecrets(withoutMacReleaseSecrets(environment)),
|
|
CSC_IDENTITY_AUTO_DISCOVERY: 'false',
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Build an unsigned, unpacked application for the current host platform.
|
|
* @param {{
|
|
* env?: NodeJS.ProcessEnv,
|
|
* cwd?: string,
|
|
* electronBuilderCli?: string,
|
|
* electronDistPath?: string,
|
|
* nodeExecutable?: string,
|
|
* run?: typeof spawnSync,
|
|
* }} [options]
|
|
*/
|
|
export function packageDirectory(options = {}) {
|
|
const run = options.run ?? spawnSync
|
|
const nodeExecutable = options.nodeExecutable ?? process.execPath
|
|
const electronBuilderCli = options.electronBuilderCli ?? builderCli
|
|
const configuredElectronDist = options.electronDistPath ?? electronDist
|
|
const result = run(
|
|
nodeExecutable,
|
|
[
|
|
electronBuilderCli,
|
|
...UNSIGNED_DIRECTORY_BUILD_ARGS,
|
|
...(existsSync(configuredElectronDist) ? [`--config.electronDist=${configuredElectronDist}`] : []),
|
|
],
|
|
{
|
|
cwd: options.cwd ?? packageRoot,
|
|
env: unsignedDirectoryBuildEnvironment(options.env ?? process.env),
|
|
stdio: 'inherit',
|
|
},
|
|
)
|
|
|
|
if (result.error !== undefined) throw result.error
|
|
if (result.status !== 0) {
|
|
throw new Error(`electron-builder --dir exited with ${String(result.status)}`)
|
|
}
|
|
}
|
|
|
|
const invokedPath = process.argv[1]
|
|
if (invokedPath !== undefined && fileURLToPath(import.meta.url) === resolve(invokedPath)) {
|
|
packageDirectory()
|
|
}
|