Files
LoveLiveMusicPlayer-Next/scripts/run-electron-builder.mjs
2026-08-08 22:45:23 +08:00

40 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 加载项目根目录 .env 后启动 electron-builder不覆盖已有环境变量
*/
import { existsSync, readFileSync } from 'fs'
import { spawnSync } from 'child_process'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const envPath = join(root, '.env')
if (existsSync(envPath)) {
for (const raw of readFileSync(envPath, 'utf8').split(/\r?\n/)) {
const line = raw.trim()
if (!line || line.startsWith('#')) continue
const eq = line.indexOf('=')
if (eq <= 0) continue
const key = line.slice(0, eq).trim()
let val = line.slice(eq + 1).trim()
if (
(val.startsWith('"') && val.endsWith('"')) ||
(val.startsWith("'") && val.endsWith("'"))
) {
val = val.slice(1, -1)
}
if (process.env[key] === undefined) process.env[key] = val
}
console.log('[env] loaded', envPath)
} else {
console.warn('[env] 未找到 .env公证需要 APPLE_ID / APPLE_APP_SPECIFIC_PASSWORD / APPLE_TEAM_ID')
}
const cli = join(root, 'node_modules/electron-builder/cli.js')
const r = spawnSync(process.execPath, [cli, ...process.argv.slice(2)], {
stdio: 'inherit',
env: process.env,
cwd: root
})
process.exit(r.status ?? 1)