Repository navigation
Expand file tree
/
Copy pathdev.mjs
More file actions
67 lines (56 loc) · 1.9 KB
/
Copy pathdev.mjs
File metadata and controls
67 lines (56 loc) · 1.9 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
import {spawnSync} from 'node:child_process';
import {mkdtempSync} from 'node:fs';
import {tmpdir} from 'node:os';
import path from 'node:path';
const defaultArgs = ['run', 'sqlrooms', '--no-open-browser', '--no-ui'];
function getForwardedArgs() {
const raw = process.env.SQLROOMS_CLI_DEV_ARGS;
if (!raw) return unwrapForwardedArgs(process.argv.slice(2));
try {
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed.map(String) : [];
} catch {
return [];
}
}
function unwrapForwardedArgs(args) {
const separatorIndex = args.indexOf('--');
if (separatorIndex === -1) return args;
return args.slice(separatorIndex + 1);
}
function readOptionValue(args, name) {
const prefix = `${name}=`;
for (let index = 0; index < args.length; index += 1) {
const arg = args[index];
if (arg === name) return args[index + 1] ?? null;
if (arg.startsWith(prefix)) return arg.slice(prefix.length);
}
return null;
}
const forwardedArgs = getForwardedArgs();
function createDefaultDbPath() {
const defaultDbDir = mkdtempSync(path.join(tmpdir(), 'sqlrooms-'));
return path.join(defaultDbDir, 'sqlrooms.db');
}
// Keep the standalone dev API aligned with the Vite proxy default. Production
// `sqlrooms` still starts from the public CLI app port when --port is omitted.
const portArgs =
readOptionValue(forwardedArgs, '--port') === null ? ['--port', '4273'] : [];
const dbPathArgs =
readOptionValue(forwardedArgs, '--db-path') === null &&
readOptionValue(forwardedArgs, '-d') === null
? ['--db-path', createDefaultDbPath()]
: [];
const result = spawnSync(
'uv',
[...defaultArgs, ...portArgs, ...dbPathArgs, ...forwardedArgs],
{
stdio: 'inherit',
shell: process.platform === 'win32',
},
);
if (typeof result.status === 'number') {
process.exit(result.status);
}
console.error('Failed to launch sqlrooms CLI dev server via uv.', result.error);
process.exit(1);