-
-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathbuild-all.mjs
More file actions
76 lines (64 loc) · 2.13 KB
/
Copy pathbuild-all.mjs
File metadata and controls
76 lines (64 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { mkdirSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { spawnSync } from 'node:child_process'
const root = process.cwd()
const toolDir = resolve(root, '.build-tools')
let resolvedPython = ''
function run(command, args, options = {}) {
console.info(`\n> ${[command, ...args].join(' ')}`)
const env = {
...process.env,
CSC_IDENTITY_AUTO_DISCOVERY: 'true',
ELECTRON_MIRROR: process.env.ELECTRON_MIRROR || 'https://npmmirror.com/mirrors/electron/',
npm_config_electron_mirror: process.env.npm_config_electron_mirror || process.env.ELECTRON_MIRROR || 'https://npmmirror.com/mirrors/electron/',
PATH: `${toolDir}:${process.env.PATH || ''}`,
...options.env,
}
if (resolvedPython) {
env.PYTHON_PATH = resolvedPython
}
const result = spawnSync(command, args, {
cwd: root,
stdio: 'inherit',
shell: false,
env,
})
if (result.status !== 0) {
process.exit(result.status || 1)
}
}
function canUsePython(command) {
return spawnSync(command, ['-c', 'import plistlib; import xml.parsers.expat'], { stdio: 'ignore' }).status === 0
}
function resolveAbs(command) {
const r = spawnSync('/bin/sh', ['-c', `command -v ${command}`], { encoding: 'utf8' })
return r.status === 0 ? r.stdout.trim() : ''
}
function ensurePythonShim() {
const candidates = [
'/usr/bin/python3',
process.env.PYTHON,
'python3',
'python',
].filter(Boolean)
let python = ''
for (const candidate of candidates) {
if (!canUsePython(candidate)) continue
python = candidate.startsWith('/') ? candidate : resolveAbs(candidate)
if (python) break
}
if (!python) return
resolvedPython = python
mkdirSync(toolDir, { recursive: true })
const script = `#!/bin/sh\nexec "${python}" "$@"\n`
for (const name of ['python', 'python3']) {
writeFileSync(resolve(toolDir, name), script, { mode: 0o755 })
}
}
ensurePythonShim()
run('node', ['version.mjs'])
run('pnpm', ['exec', 'vue-tsc', '--noEmit'])
run('pnpm', ['exec', 'vite', 'build'])
run('node', ['build-linux.mjs'])
run('pnpm', ['exec', 'electron-builder', '--win'])
run('pnpm', ['exec', 'electron-builder', '--mac'])