-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix_docs.ts
81 lines (61 loc) · 2.28 KB
/
fix_docs.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
const testFolder = "./docs/components";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require("fs");
function swapDocs(content: string) {
let lines = content.split("\n");
let ds = -1;
for (const l in lines) {
if (lines[l].includes("BEGIN_DOCS")) {
ds = parseInt(l);
break;
}
}
let newContent = "";
if (ds > 0) {
newContent += lines[0] + "\n";
for (let l = ds + 1; l < lines.length; l++) newContent += lines[l] + "\n";
for (let l = 1; l < ds; l++) newContent += lines[l] + "\n";
} else newContent = content;
newContent = newContent.replaceAll("() => [", "[");
// now fix table
lines = newContent.split("\n");
let dt = -1;
for (const l in lines) {
if (lines[l].includes("## Props")) {
dt = parseInt(l);
break;
}
}
lines[dt + 2] = lines[dt + 2].replace("| Values |", "|");
const parts = lines[dt + 3].split("|");
parts[4] = "_REMOVE_";
lines[dt + 3] = parts.join("|").replace(/\|_REMOVE_\|/, "|");
let i = 0;
while (lines[dt + 4 + i][0] === "|") {
const parts = lines[dt + 4 + i].split("|");
//console.log({ lines: lines[0], part: parts });
if (parts[1][1] !== "-") parts[1] = "`" + parts[1] + "`";
//console.log({ part2: parts });
lines[dt + 4 + i] = `|${parts[1]}|${parts[2]}|${parts[3]}|${parts[5]}|`;
lines[dt + 4 + i] = lines[dt + 4 + i].replaceAll("||", "| - |");
i++;
}
newContent = lines.join("\n");
return newContent;
}
fs.readdirSync(testFolder).forEach((file: string) => {
if (fs.lstatSync(testFolder + "/" + file).isDirectory()) {
fs.readdirSync(testFolder + "/" + file).forEach((file2: string) => {
const content = fs.readFileSync(testFolder + "/" + file + "/" + file2);
fs.writeFileSync(testFolder + "/" + file + "/" + file2, swapDocs(content.toString()));
});
} else {
const content = fs.readFileSync(testFolder + "/" + file);
fs.writeFileSync(testFolder + "/" + file, swapDocs(content.toString()));
}
});
/*fs.readdirSync(testFolder).forEach((file2: string) => {
if (fs.lstatSync(testFolder + "/" + file2).isDirectory()) return;
const content = fs.readFileSync(testFolder + "/" + file2);
fs.writeFileSync(testFolder + "/" + file2, swapDocs(content.toString()));
});*/ // NO IDEA WHY THIS DOESNT WORK