- Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathgenerate_llms.res
137 lines (112 loc) · 4.21 KB
/
generate_llms.res
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
letreadMarkdownFile= (filePath: string): string=> {
letfileContent=Node.Fs.readFileSync2(filePath, "utf8")
fileContent
}
letreccollectFiles= (dirPath: string): array<string> => {
letentries=Node.Fs.readdirSync(dirPath)
entries->Array.reduce([], (acc, entry) => {
letfullPath=Node.Path.join([dirPath, entry])
letstats=Node.Fs.statSync(fullPath)
switchstats["isDirectory"]() {
| true=>acc->Array.concat(collectFiles(fullPath))
| false=> {
acc->Array.push(fullPath)
acc
}
}
})
}
letclearFile= (filePath: string): unit=> {
Node.Fs.writeFileSync(filePath, "")
}
letcreateDirectoryIfNotExists= (dirPath: string): unit=> {
if!Node.Fs.existsSync(dirPath) {
Node.Fs.mkdirSync(dirPath)
}
}
letremoveCodeTabTags= (content: string): string=> {
letregex=RegExp.fromStringWithFlags("<CodeTab.*?>[\\s\\S]*?</CodeTab>", ~flags="g")
String.replaceRegExp(content, regex, "")
}
letremoveCodeBlocks= (content: string): string=> {
letregex=RegExp.fromStringWithFlags("```[a-zA-Z]+\\s*[\\s\\S]*?```", ~flags="g")
String.replaceRegExp(content, regex, "")
}
letremoveFileTitle= (content: string): string=> {
letregex=RegExp.fromStringWithFlags("---\ntitle[\\s\\S]*?---", ~flags="g")
String.replaceRegExp(content, regex, "")
}
letremoveUnnecessaryBreaks= (content: string): string=> {
letregex=RegExp.fromStringWithFlags("^\n{2,}", ~flags="g")
String.replaceRegExp(content, regex, "")
}
letremoveToDos= (content: string): string=> {
letregex=RegExp.fromStringWithFlags("<!-- TODO[\\s\\S]*?-->", ~flags="g")
String.replaceRegExp(content, regex, "")
}
letfillContentWithVersion= (content: string, version: string): string=> {
letregex=RegExp.fromStringWithFlags("<VERSION>", ~flags="g")
String.replaceRegExp(content, regex, version)
}
letcreateFullFile= (content: string, filePath: string): unit=> {
Node.Fs.appendFileSync(filePath, content++"\n", "utf8")
}
letcreateSmallFile= (content: string, filePath: string): unit=> {
letsmallContent=
content
->removeCodeTabTags
->removeFileTitle
->removeToDos
->removeCodeBlocks
->removeUnnecessaryBreaks
Node.Fs.appendFileSync(filePath, smallContent, "utf8")
}
letcreateLlmsFiles= (version: string, docsDirectory: string, llmsDirectory: string): unit=> {
letmdxFileTemplatePath=llmsDirectory->Node.Path.join2("template.mdx")
letmdxFilePath=docsDirectory->Node.Path.join2(version)->Node.Path.join2("llms.mdx")
lettxtFileTemplatePath=llmsDirectory->Node.Path.join2("template.txt")
lettxtFilePath=llmsDirectory->Node.Path.join2(version)->Node.Path.join2("llms.txt")
Node.Fs.writeFileSync(
mdxFilePath,
readMarkdownFile(mdxFileTemplatePath)->fillContentWithVersion(version),
)
Node.Fs.writeFileSync(
txtFilePath,
readMarkdownFile(txtFileTemplatePath)->fillContentWithVersion(version),
)
}
letprocessVersions= (
versions: array<string>,
docsDirectory: string,
llmsDirectory: string,
): unit=> {
letfullFileName="llm-full.txt"
letsmallFileName="llm-small.txt"
versions->Array.forEach(version=> {
letversionDir=docsDirectory->Node.Path.join2(version)
letllmsDir=llmsDirectory->Node.Path.join2(version)
letfullFilePath=llmsDir->Node.Path.join2(fullFileName)
letsmallFilePath=llmsDir->Node.Path.join2(smallFileName)
createDirectoryIfNotExists(llmsDir)
clearFile(fullFilePath)
clearFile(smallFilePath)
createLlmsFiles(version, docsDirectory, llmsDirectory)
versionDir
->collectFiles
->Array.forEach(filePath=> {
ifString.endsWith(filePath, ".mdx") {
letcontent=readMarkdownFile(filePath)
content->createFullFile(fullFilePath)
content->createSmallFile(smallFilePath)
}
})
})
}
letmanualVersions= ["v12.0.0", "v11.0.0"]
letreactManualVersions= ["latest", "v0.10.0", "v0.11.0"]
letmanualDocsDirectory="pages/docs/manual"
letreactDocsDirectory="pages/docs/react"
letmanualLlmsDirectory="public/llms/manual"
letreactLlmsDirectory="public/llms/react"
processVersions(manualVersions, manualDocsDirectory, manualLlmsDirectory)
processVersions(reactManualVersions, reactDocsDirectory, reactLlmsDirectory)