forked from Orkas-AI/Orkas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.cjs
More file actions
76 lines (67 loc) · 2.88 KB
/
Copy pathbootstrap.cjs
File metadata and controls
76 lines (67 loc) · 2.88 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
// Electron entry shim: register tsx so the main process can
// `require('./src/main')` and resolve to src/main/index.ts (Node folder →
// index.ts rule + tsx/cjs transpilation). Keeps __dirname semantics identical
// to running plain JS — no compile step in dev.
//
// Two hooks:
// - `tsx/cjs` (sync require hook) handles src/main/**/*.ts on the require()
// code path.
// - `tsx/esm` (ESM loader, registered via node:module) handles dynamic
// `import()` specifiers that resolve to .ts files — notably the
// `import('#core-agent')` subpath import that targets core-agent source.
'use strict';
const fs = require('node:fs');
const path = require('node:path');
for (const arg of process.argv.slice(1)) {
if (typeof arg !== 'string') continue;
if (arg.startsWith('--orkas-profile=')) {
process.env.ORKAS_PROFILE = arg.slice('--orkas-profile='.length);
} else if (arg.startsWith('--orkas-api-base-url=')) {
process.env.ORKAS_API_BASE_URL = arg.slice('--orkas-api-base-url='.length);
} else if (arg.startsWith('--orkas-voice-api-base=')) {
process.env.ORKAS_VOICE_API_BASE = arg.slice('--orkas-voice-api-base='.length);
}
}
function configurePackagedEsbuildBinary() {
if (!process.versions.electron || !process.resourcesPath || process.env.ESBUILD_BINARY_PATH) {
return;
}
const platformPackages = {
'darwin:arm64': ['@esbuild', 'darwin-arm64', 'bin', 'esbuild'],
'darwin:x64': ['@esbuild', 'darwin-x64', 'bin', 'esbuild'],
'linux:arm64': ['@esbuild', 'linux-arm64', 'bin', 'esbuild'],
'linux:x64': ['@esbuild', 'linux-x64', 'bin', 'esbuild'],
'win32:arm64': ['@esbuild', 'win32-arm64', 'esbuild.exe'],
'win32:ia32': ['@esbuild', 'win32-ia32', 'esbuild.exe'],
'win32:x64': ['@esbuild', 'win32-x64', 'esbuild.exe'],
};
const parts = platformPackages[`${process.platform}:${process.arch}`];
if (!parts) return;
const bin = path.join(
process.resourcesPath,
'app.asar.unpacked',
'node_modules',
...parts,
);
if (fs.existsSync(bin)) {
process.env.ESBUILD_BINARY_PATH = bin;
}
}
function configureWindowsVcRuntimePath() {
if (process.platform !== 'win32') return;
const platformKey = `${process.platform}-${process.arch}`;
const candidates = [
process.resourcesPath && path.join(process.resourcesPath, 'runtime', 'vc', platformKey),
path.join(__dirname, 'resources', 'runtime', 'vc', platformKey),
].filter(Boolean);
const runtimeDir = candidates.find((dir) => fs.existsSync(path.join(dir, 'vcruntime140.dll')));
if (!runtimeDir) return;
const entries = String(process.env.PATH || '').split(path.delimiter).filter(Boolean);
process.env.PATH = [runtimeDir, ...entries.filter((entry) => path.resolve(entry) !== path.resolve(runtimeDir))]
.join(path.delimiter);
}
configureWindowsVcRuntimePath();
configurePackagedEsbuildBinary();
require('tsx/cjs');
require('tsx/esm/api').register();
require('./src/main');