adapte macos
This commit is contained in:
36
scripts/patch-electron-dev-name.mjs
Normal file
36
scripts/patch-electron-dev-name.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 开发态跑的是 node_modules 里的 Electron.app,菜单栏名称来自 Info.plist。
|
||||
* 把 CFBundleName / CFBundleDisplayName 改成产品名(仅 macOS;npm i 后需再跑一次)。
|
||||
*/
|
||||
import { createRequire } from 'module'
|
||||
import { execFileSync } from 'child_process'
|
||||
import { existsSync } from 'fs'
|
||||
import { dirname, join } from 'path'
|
||||
import { platform } from 'os'
|
||||
|
||||
const APP_NAME = 'LoveLiveMusicPlayer'
|
||||
|
||||
if (platform() !== 'darwin') {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
let electronBinary
|
||||
try {
|
||||
electronBinary = require('electron')
|
||||
} catch {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const plist = join(dirname(String(electronBinary)), '..', 'Info.plist')
|
||||
if (!existsSync(plist)) {
|
||||
console.warn('[patch-electron] Info.plist 未找到:', plist)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
for (const key of ['CFBundleName', 'CFBundleDisplayName']) {
|
||||
execFileSync('plutil', ['-replace', key, '-string', APP_NAME, plist])
|
||||
}
|
||||
// 促使 Launch Services 刷新缓存
|
||||
execFileSync('touch', [join(dirname(plist), '..')])
|
||||
console.log(`[patch-electron] 开发态应用名 → ${APP_NAME}`)
|
||||
39
scripts/run-electron-builder.mjs
Normal file
39
scripts/run-electron-builder.mjs
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 加载项目根目录 .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)
|
||||
Reference in New Issue
Block a user