-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathprint.mts
More file actions
40 lines (36 loc) · 1012 Bytes
/
print.mts
File metadata and controls
40 lines (36 loc) · 1012 Bytes
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
import { mkdir, writeFile } from "fs/promises";
import path from "path";
import { queriesOutputPath } from "./constants.mjs";
import { LimitedUserConfig } from "./cli.mjs";
import { buildQueriesOutputPath, exists } from "./common.mjs";
async function printGeneratedTS(
result: {
name: string;
content: string;
},
options: Pick<LimitedUserConfig, "output">
) {
const dir = buildQueriesOutputPath(options.output);
const dirExists = await exists(dir);
if (!dirExists) {
await mkdir(dir, { recursive: true });
}
await writeFile(path.join(dir, result.name), result.content);
}
export async function print(
results: {
name: string;
content: string;
}[],
options: Pick<LimitedUserConfig, "output">
) {
const outputPath = options.output;
const dirExists = await exists(outputPath);
if (!dirExists) {
await mkdir(outputPath);
}
const promises = results.map(async (result) => {
await printGeneratedTS(result, options);
});
await Promise.all(promises);
}