Repository navigation
Expand file tree
/
Copy pathutils.ts
More file actions
60 lines (56 loc) · 1.45 KB
/
Copy pathutils.ts
File metadata and controls
60 lines (56 loc) · 1.45 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
import { existsSync } from "https://deno.land/std/fs/mod.ts";
import { join } from "https://deno.land/std@0.133.0/path/mod.ts";
import { parse } from "https://deno.land/std@0.134.0/encoding/csv.ts";
export const removeStackQLDownload = async () => {
const projectDir = Deno.cwd();
const stackqlPath = join(projectDir, ".stackql");
if (existsSync(stackqlPath)) {
await Deno.remove(stackqlPath, { recursive: true });
}
};
export const startStackQLServer = async (port = 5444) => {
const command = new Deno.Command("stackql", {
args: [
"srv",
"--pgsrv.address=0.0.0.0",
`--pgsrv.port=${port}`,
],
stdout: "inherit",
stderr: "inherit",
});
const process = command.spawn();
//TODO: find a way to wait for the server to be ready
const closeProcess = async () => {
try {
console.log("Closing process");
process.kill();
await process.status;
} catch (error) {
const alreadyClosed = error.message.includes(
"Child process has already terminated",
);
if (alreadyClosed) {
console.log("Process already closed");
return;
}
throw error;
}
};
return { closeProcess };
};
export const isJsonString = (str: string) => {
try {
JSON.parse(str);
} catch (_error) {
return false;
}
return true;
};
export const isCsvString = async (str: string) => {
try {
await parse(str);
} catch (_error) {
return false;
}
return true;
};