-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.ts
executable file
·119 lines (104 loc) · 2.9 KB
/
generate.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bun
import { defineCommand, runMain } from "citty";
import { readdir, exists } from "node:fs/promises";
import { $ } from "bun";
import { confirm } from "@inquirer/prompts";
const CONFIG_EXTENSION = ".docsetconfig";
const toArrayIfString = (val: string | string[]) =>
Array.isArray(val) ? val : [val];
const main = defineCommand({
meta: {
name: "generate",
version: "1.0.0",
description: "Docsets",
},
args: {
docsets: {
type: "positional",
description: "Docset name",
required: false,
},
docset: {
type: "string",
description: "Docset name",
alias: ["d", "docset"],
required: false,
},
all: {
type: "boolean",
description:
"if other args are not provided defauts to true, if no args are provided defaults to false",
default: undefined,
},
},
async run({ args }) {
let { all, _: rest, docset, docsets } = args;
const docsetNames = Array.from(
new Set(
[
...toArrayIfString(docset),
...toArrayIfString(docsets),
...toArrayIfString(rest),
].filter(Boolean),
),
);
const checkedDocsets: Array<string> = [];
if (all === undefined && docsetNames.length === 0) {
all = await confirm({
message: "Do you want to generate all docsets?",
default: false,
});
}
if (docsetNames.length === 0 && all) {
const configs = await readdir("./configs");
for (const config of configs) {
if (config.endsWith(CONFIG_EXTENSION)) {
const docsetName = config.slice(0, -CONFIG_EXTENSION.length);
checkedDocsets.push(docsetName);
}
}
} else {
for (const docsetName of docsetNames) {
const docsetConfigPath = `./configs/${docsetName}${CONFIG_EXTENSION}`;
const exist = await exists(docsetConfigPath);
if (!exist) {
console.error(`Docset config ${docsetConfigPath} does not exist`);
continue;
}
checkedDocsets.push(docsetName);
}
}
if (checkedDocsets.length === 0) {
return;
}
console.log("Generating docs for: ", checkedDocsets);
for (const docsetName of checkedDocsets) {
const docsetConfigPath = `./configs/${docsetName}${CONFIG_EXTENSION}`;
console.log(
`Generating docset ${docsetName} from config ${docsetConfigPath}`,
);
console.log(`[LOG]: ./tmp/${docsetName}.docset/log.txt`);
console.log(
`[Scrapping LOG]: ./tmp/${docsetName}.docset/resumeData/scrapes.txt`,
);
await $`cd tmp && DocsetGenerator .${docsetConfigPath}`;
await $`cd tmp && tar -cvzf ../docsets/${docsetName}.tgz ${docsetName}.docset`;
console.log(`Docset ${docsetName} generated`);
}
const shouldGenerateJson = await confirm({
message: "Do you want to generate json?",
default: true,
});
if (shouldGenerateJson) {
await $`./generate-json.ts`;
}
const shouldGenerateImages = await confirm({
message: "Do you want to generate images?",
default: true,
});
if (shouldGenerateImages) {
await $`./generate-images.ts`;
}
},
});
runMain(main);