forked from lploc94/intent_patch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreflight.js
More file actions
100 lines (86 loc) · 2.49 KB
/
Copy pathpreflight.js
File metadata and controls
100 lines (86 loc) · 2.49 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
const fs = require('fs');
const { execSync } = require('child_process');
const { log, fatal, runCmd } = require('./utils');
const { INTENT_APP, INTENT_ASAR } = require('./constants');
function which(cmd) {
try {
execSync(`command -v ${cmd}`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] });
return true;
} catch { return false; }
}
function checkAsarApi() {
try {
const asar = require('@electron/asar');
if (typeof asar.extractAll !== 'function' ||
typeof asar.createPackage !== 'function' ||
typeof asar.extractFile !== 'function') {
throw new Error('Incomplete asar API');
}
return 'library';
} catch {
try {
runCmd('npx asar --version');
log('Using npx asar as fallback (library unavailable)', 'WARN');
return 'cli';
} catch {
fatal('@electron/asar not available as library or CLI');
}
}
}
function preflightChecks(skipInstall = false) {
console.log('\n=== Phase 0: Preflight Checks ===');
let ok = true;
// Node.js version
const ver = process.version;
const major = parseInt(ver.slice(1).split('.')[0], 10);
if (major < 18) {
log(`Node.js ${ver} too old, need >=18`, 'FAIL');
ok = false;
} else {
log(`Node.js ${ver}`, 'OK');
}
// @electron/asar
const asarMode = checkAsarApi();
log(`@electron/asar available (${asarMode})`, 'OK');
if (!skipInstall) {
// codesign
if (which('codesign')) {
log('codesign available', 'OK');
} else {
log('codesign not found', 'FAIL');
ok = false;
}
// PlistBuddy
if (fs.existsSync('/usr/libexec/PlistBuddy')) {
log('PlistBuddy available', 'OK');
} else {
log('PlistBuddy not found', 'FAIL');
ok = false;
}
// Intent app
if (fs.existsSync(INTENT_APP) && fs.statSync(INTENT_APP).isDirectory()) {
log(`Intent app found at ${INTENT_APP}`, 'OK');
} else {
log(`Intent app not found at ${INTENT_APP}`, 'FAIL');
ok = false;
}
// app.asar
if (fs.existsSync(INTENT_ASAR)) {
log('app.asar exists', 'OK');
} else {
log('app.asar not found in Intent bundle', 'FAIL');
ok = false;
}
// Check TTY for sudo
if (!process.stdin.isTTY) {
log('No interactive terminal detected (sudo may fail)', 'WARN');
}
}
if (!ok) {
fatal('Preflight checks failed. Fix the issues above and retry.');
}
log('All preflight checks passed.', 'OK');
return asarMode;
}
module.exports = { preflightChecks, checkAsarApi };