forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-electron.mjs
More file actions
65 lines (56 loc) · 1.81 KB
/
build-electron.mjs
File metadata and controls
65 lines (56 loc) · 1.81 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
import { build } from 'esbuild';
import fs from 'fs';
import path from 'path';
// Replace symlinks in standalone with real copies so electron-builder can package them
function resolveStandaloneSymlinks() {
const standaloneModules = '.next/standalone/.next/node_modules';
if (!fs.existsSync(standaloneModules)) return;
const entries = fs.readdirSync(standaloneModules);
for (const entry of entries) {
const fullPath = path.join(standaloneModules, entry);
const stat = fs.lstatSync(fullPath);
if (stat.isSymbolicLink()) {
const target = fs.readlinkSync(fullPath);
const resolved = path.resolve(standaloneModules, target);
if (fs.existsSync(resolved)) {
fs.rmSync(fullPath, { recursive: true, force: true });
fs.cpSync(resolved, fullPath, { recursive: true });
console.log(`Resolved symlink: ${entry} -> ${target}`);
}
}
}
}
async function buildElectron() {
// Clean dist-electron/ before every build to prevent stale artifacts
// from leaking into app.asar (caused v0.34 crash on upgrade).
if (fs.existsSync('dist-electron')) {
fs.rmSync('dist-electron', { recursive: true });
console.log('Cleaned dist-electron/');
}
fs.mkdirSync('dist-electron', { recursive: true });
const shared = {
bundle: true,
platform: 'node',
target: 'node18',
external: ['electron'],
sourcemap: true,
minify: false,
};
await build({
...shared,
entryPoints: ['electron/main.ts'],
outfile: 'dist-electron/main.js',
});
await build({
...shared,
entryPoints: ['electron/preload.ts'],
outfile: 'dist-electron/preload.js',
});
console.log('Electron build complete');
// Fix standalone symlinks after next build
resolveStandaloneSymlinks();
}
buildElectron().catch((err) => {
console.error(err);
process.exit(1);
});