forked from solidjs/solid-docs-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
64 lines (53 loc) · 1.83 KB
/
build.ts
File metadata and controls
64 lines (53 loc) · 1.83 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
import { outputTutorials, outputDocs, writeToPath } from "../build/buildDocs";
import { readdir } from "fs/promises";
import { resolve, join, sep } from "path";
import watch from "node-watch";
const langsDir = resolve(__dirname, "../langs");
import {StringKeyed} from "../src/types";
async function buildAll() {
const langs: string[] = await readdir(langsDir);
const supported: StringKeyed = {};
function addSupported(resource: string, lang: string) {
const path = resource.split("/");
let pointer: any = supported;
for (let i = 0; i < path.length - 1; i++) {
pointer = pointer[path[i]] || (pointer[path[i]] = {});
}
const lastSegment = path[path.length - 1];
if (pointer[lastSegment]) {
pointer[lastSegment].push(lang);
} else {
pointer[lastSegment] = [lang];
}
}
for (const lang of langs) {
console.log("Processing", lang)
const supportedTutorials = await outputTutorials(lang);
if (supportedTutorials) supportedTutorials.forEach(resource => addSupported(resource, lang));
(await outputDocs(lang)).forEach(resource => addSupported(resource, lang));
}
const outputPath = resolve(__dirname, '../build/out', "supported.json");
await writeToPath(outputPath, supported);
}
async function watchAll() {
const langs: string[] = await readdir(langsDir);
for (const lang of langs) {
const langDir = join(langsDir, lang);
watch(langDir, { recursive: true }, async (event, name) => {
const relative = name.split(langDir)[1];
if (relative.startsWith(sep + "tutorials")) {
console.log("Rebuilding tutorials for", lang)
await outputTutorials(lang);
} else {
console.log("Rebuilding docs for", lang)
await outputDocs(lang);
}
});
}
}
if (process.argv[2] === "--watch") {
watchAll()
} else {
buildAll();
}
// run();