-
Notifications
You must be signed in to change notification settings - Fork 0
/
after-pack.js
69 lines (60 loc) · 2.4 KB
/
after-pack.js
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
const fs = require('fs');
const path = require('path');
exports.default = function(context) {
console.log('After-pack script started');
console.log('Build path:', context.appOutDir);
// Path to your Conda Python interpreter
const pythonPath = process.env.PYTHON_PATH || '/opt/anaconda3/envs/quiz/bin/python';
// Try to find the main.js file
const possiblePaths = [
path.join(context.appOutDir, 'StreamSage.app', 'Contents', 'Resources', 'app', 'src', 'main.js'),
path.join(context.appOutDir, 'StreamSage.app', 'Contents', 'Resources', 'app', 'main.js'),
path.join(context.appOutDir, 'StreamSage.app', 'Contents', 'Resources', 'app.asar', 'src', 'main.js'),
path.join(context.appOutDir, 'StreamSage.app', 'Contents', 'Resources', 'app.asar', 'main.js'),
path.join(context.appOutDir, 'Resources', 'app', 'src', 'main.js'),
path.join(context.appOutDir, 'Resources', 'app', 'main.js'),
path.join(context.appOutDir, 'Resources', 'app.asar', 'src', 'main.js'),
path.join(context.appOutDir, 'Resources', 'app.asar', 'main.js')
];
let mainJsPath;
for (const p of possiblePaths) {
console.log('Checking path:', p);
if (fs.existsSync(p)) {
mainJsPath = p;
console.log('Found main.js at:', mainJsPath);
break;
}
}
if (!mainJsPath) {
console.error('Could not find main.js in any of the expected locations');
console.log('Listing contents of build directory:');
listDirectoryContents(context.appOutDir);
return;
}
// Update the Python path in the packaged app
let mainJs = fs.readFileSync(mainJsPath, 'utf8');
const originalMainJs = mainJs;
mainJs = mainJs.replace(
/const pythonPath = app\.isPackaged\s*\?[^:]+:\s*['"]([^'"]+)['"]/,
`const pythonPath = app.isPackaged ? path.join(process.resourcesPath, 'python') : '${pythonPath.replace(/\\/g, '\\\\')}'`
);
if (mainJs !== originalMainJs) {
fs.writeFileSync(mainJsPath, mainJs);
console.log('Updated Python path in main.js');
} else {
console.log('No changes needed in main.js');
}
console.log('After-pack script completed');
};
function listDirectoryContents(dir) {
fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
console.log('Directory:', fullPath);
listDirectoryContents(fullPath);
} else {
console.log('File:', fullPath);
}
});
}