diff --git a/demo/bin/demo.js b/demo/bin/demo.js index 69c754e..ff7ef3e 100644 --- a/demo/bin/demo.js +++ b/demo/bin/demo.js @@ -20,7 +20,8 @@ import pty from '@lydell/node-pty'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const HTTP_PORT = process.env.PORT || 8080; +const DEV_MODE = process.argv.includes('--dev'); +const HTTP_PORT = process.env.PORT || (DEV_MODE ? 8000 : 8080); const WS_PORT = 3001; // ============================================================================ @@ -31,13 +32,25 @@ import { createRequire } from 'module'; const require = createRequire(import.meta.url); function findGhosttyWeb() { + // In dev mode, we use Vite - no need to find built assets + if (DEV_MODE) { + const repoRoot = path.join(__dirname, '..', '..'); + const wasmPath = path.join(repoRoot, 'ghostty-vt.wasm'); + if (!fs.existsSync(wasmPath)) { + console.error('Error: ghostty-vt.wasm not found.'); + console.error('Run: bun run build:wasm'); + process.exit(1); + } + return { distPath: null, wasmPath, repoRoot }; + } + // First, check for local development (repo root dist/) const localDist = path.join(__dirname, '..', '..', 'dist'); const localJs = path.join(localDist, 'ghostty-web.js'); const localWasm = path.join(__dirname, '..', '..', 'ghostty-vt.wasm'); if (fs.existsSync(localJs) && fs.existsSync(localWasm)) { - return { distPath: localDist, wasmPath: localWasm, isDev: true }; + return { distPath: localDist, wasmPath: localWasm, repoRoot: path.join(__dirname, '..', '..') }; } // Use require.resolve to find the installed ghostty-web package @@ -49,7 +62,7 @@ function findGhosttyWeb() { const wasmPath = path.join(ghosttyWebRoot, 'ghostty-vt.wasm'); if (fs.existsSync(path.join(distPath, 'ghostty-web.js')) && fs.existsSync(wasmPath)) { - return { distPath, wasmPath, isDev: false }; + return { distPath, wasmPath, repoRoot: null }; } } catch (e) { // require.resolve failed, package not found @@ -62,7 +75,7 @@ function findGhosttyWeb() { process.exit(1); } -const { distPath, wasmPath, isDev } = findGhosttyWeb(); +const { distPath, wasmPath, repoRoot } = findGhosttyWeb(); // ============================================================================ // HTML Template @@ -193,8 +206,9 @@ const HTML_TEMPLATE = `