-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·47 lines (42 loc) · 1.1 KB
/
cli.js
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
#!/usr/bin/env node
import child_process from 'node:child_process';
import events from 'node:events';
const cwd = process.cwd();
const command = process.argv.length === 2 ? 'help' : process.argv[2];
async function executeHarperDB(mode) {
const p = child_process.spawn('harperdb', ['run', './'], {
cwd,
stdio: 'inherit',
env: {
...process.env,
HARPERDB_NEXTJS_MODE: mode,
THREADS_DEBUG: mode === 'dev' ? 'true' : 'false',
},
});
const [exitCode] = await events.once(p, 'exit');
console.log('HarperDB exited with code:', exitCode);
}
const HELP = `
Usage: harperdb-nextjs <command>
Available commands:
build - Build the Next.js app only
dev - Start HarperDB and run Next.js in development mode
help - Display this help message
start - Start HarperDB and run Next.js in production mode
`;
switch (command) {
case 'build':
await executeHarperDB('build');
break;
case 'dev':
await executeHarperDB('dev');
break;
case 'start':
await executeHarperDB('prod');
break;
default:
console.log('Unknown command:', command);
case 'help':
console.log(HELP);
break;
}