- Replace better-sqlite3 with bun:sqlite (native, no native addon build)
- Change all spawn('node') to spawn('bun') for agent processes
- Update package.json scripts: node→bun, tsx→bun, npm→bun
- Add bun-types for tsc compatibility
- Add bun:sqlite→better-sqlite3 shim for vitest (tests run on Node.js)
- Update Dockerfile: install bun alongside Node.js (CLIs need Node)
- Update setup/platform.ts: getNodePath() resolves bun binary
- Remove better-sqlite3 from production dependencies (devDep only for tests)
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
/**
|
|
* Step: environment — Detect OS, Node, existing config.
|
|
* Replaces 01-check-environment.sh
|
|
*/
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
import { Database } from 'bun:sqlite';
|
|
|
|
import { STORE_DIR } from '../src/config.js';
|
|
import { logger } from '../src/logger.js';
|
|
import { getPlatform, isHeadless, isWSL } from './platform.js';
|
|
import { emitStatus } from './status.js';
|
|
|
|
export async function run(_args: string[]): Promise<void> {
|
|
const projectRoot = process.cwd();
|
|
|
|
logger.info('Starting environment check');
|
|
|
|
const platform = getPlatform();
|
|
const wsl = isWSL();
|
|
const headless = isHeadless();
|
|
|
|
// Check existing config
|
|
const hasEnv = fs.existsSync(path.join(projectRoot, '.env'));
|
|
|
|
const authDir = path.join(projectRoot, 'store', 'auth');
|
|
const hasAuth = fs.existsSync(authDir) && fs.readdirSync(authDir).length > 0;
|
|
|
|
let hasRegisteredGroups = false;
|
|
// Check JSON file first (pre-migration)
|
|
if (fs.existsSync(path.join(projectRoot, 'data', 'registered_groups.json'))) {
|
|
hasRegisteredGroups = true;
|
|
} else {
|
|
// Check SQLite directly using better-sqlite3 (no sqlite3 CLI needed)
|
|
const dbPath = path.join(STORE_DIR, 'messages.db');
|
|
if (fs.existsSync(dbPath)) {
|
|
try {
|
|
const db = new Database(dbPath, { readonly: true });
|
|
const row = db
|
|
.prepare('SELECT COUNT(*) as count FROM registered_groups')
|
|
.get() as { count: number };
|
|
if (row.count > 0) hasRegisteredGroups = true;
|
|
db.close();
|
|
} catch {
|
|
// Table might not exist yet
|
|
}
|
|
}
|
|
}
|
|
|
|
logger.info(
|
|
{
|
|
platform,
|
|
wsl,
|
|
hasEnv,
|
|
hasAuth,
|
|
hasRegisteredGroups,
|
|
},
|
|
'Environment check complete',
|
|
);
|
|
|
|
emitStatus('CHECK_ENVIRONMENT', {
|
|
PLATFORM: platform,
|
|
IS_WSL: wsl,
|
|
IS_HEADLESS: headless,
|
|
HAS_ENV: hasEnv,
|
|
HAS_AUTH: hasAuth,
|
|
HAS_REGISTERED_GROUPS: hasRegisteredGroups,
|
|
STATUS: 'success',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
}
|