forked from boos/BoosAPI
feat: implement macOS notarization and ad-hoc signing in afterSign script
feat: add run-server script to manage server execution and compatibility checks feat: create main application logic for desktop with window management, server handling, and auto-updater test: add unit tests for desktop runtime helpers feat: implement desktop server environment configuration and health check test: add tests for server configuration and desktop routes feat: add native module guard for better-sqlite3 compatibility test: add tests for native module guard functionality test: add comprehensive tests for account verification feedback handling feat: implement account verification feedback helpers chore: add TypeScript configuration for desktop builds
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { spawn } from 'node:child_process';
|
||||
import { join } from 'node:path';
|
||||
import {
|
||||
buildBetterSqliteRebuildCommand,
|
||||
isNodeModuleVersionMismatch,
|
||||
} from '../../src/server/nativeModuleGuard.js';
|
||||
|
||||
function run(command: string, args: string[]) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const child = spawn(command, args, {
|
||||
cwd: process.cwd(),
|
||||
stdio: 'inherit',
|
||||
shell: false,
|
||||
env: process.env,
|
||||
});
|
||||
|
||||
child.once('exit', (code, signal) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject(new Error(`Command failed: ${command} ${args.join(' ')} (code=${code ?? 'null'}, signal=${signal ?? 'null'})`));
|
||||
});
|
||||
|
||||
child.once('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
async function ensureBetterSqliteCompatible() {
|
||||
try {
|
||||
await import('better-sqlite3');
|
||||
return;
|
||||
} catch (error) {
|
||||
if (!isNodeModuleVersionMismatch(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const rebuild = buildBetterSqliteRebuildCommand();
|
||||
console.log('[metapi] Detected better-sqlite3 ABI mismatch. Rebuilding for the current Node.js runtime...');
|
||||
await run(rebuild.command, rebuild.args);
|
||||
|
||||
try {
|
||||
await import('better-sqlite3');
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`better-sqlite3 is still incompatible after rebuild: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const isWatchMode = process.argv.includes('--watch');
|
||||
await ensureBetterSqliteCompatible();
|
||||
|
||||
if (isWatchMode) {
|
||||
const tsxCli = join(process.cwd(), 'node_modules', 'tsx', 'dist', 'cli.mjs');
|
||||
const child = spawn(process.execPath, [tsxCli, 'watch', 'src/server/index.ts'], {
|
||||
cwd: process.cwd(),
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
});
|
||||
child.once('exit', (code) => {
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const child = spawn(process.execPath, ['dist/server/index.js'], {
|
||||
cwd: process.cwd(),
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
});
|
||||
child.once('exit', (code) => {
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user