1+ let readMarkdownFile = (filePath : string ): string => {
2+ let fileContent = Node .Fs .readFileSync2 (filePath , "utf8" )
3+ fileContent
4+ }
5+
6+ let rec collectFiles = (dirPath : string ): array <string > => {
7+ let entries = Node .Fs .readdirSync (dirPath )
8+ entries -> Array .reduce ([], (acc , entry ) => {
9+ let fullPath = Node .Path .join ([dirPath , entry ])
10+ let stats = Node .Fs .statSync (fullPath )
11+ switch stats ["isDirectory" ]() {
12+ | true => acc -> Array .concat (collectFiles (fullPath ))
13+ | false => {
14+ acc -> Array .push (fullPath )
15+ acc
16+ }
17+ }
18+ })
19+ }
20+
21+ let clearFile = (filePath : string ): unit => {
22+ Node .Fs .writeFileSync (filePath , "" )
23+ }
24+
25+ let createDirectoryIfNotExists = (dirPath : string ): unit => {
26+ if ! Node .Fs .existsSync (dirPath ) {
27+ Node .Fs .mkdirSync (dirPath )
28+ }
29+ }
30+
31+ let removeCodeTabTags = (content : string ): string => {
32+ let regex = Js .Re .fromStringWithFlags ("<CodeTab.*?>[\\ s\\ S]*?</CodeTab>" , ~flags = "g" )
33+ Js .String .replaceByRe (regex , "" , content )
34+ }
35+
36+ let removeCodeBlocks = (content : string ): string => {
37+ let regex = Js .Re .fromStringWithFlags ("```[a-zA-Z]+\\ s*[\\ s\\ S]*?```" , ~flags = "g" )
38+ Js .String .replaceByRe (regex , "" , content )
39+ }
40+
41+ let removeFileTitle = (content : string ): string => {
42+ let regex = Js .Re .fromStringWithFlags ("---\n title[\\ s\\ S]*?---" , ~flags = "g" )
43+ Js .String .replaceByRe (regex , "" , content )
44+ }
45+
46+ let removeUnnecessaryBreaks = (content : string ): string => {
47+ let regex = Js .Re .fromStringWithFlags ("^\n {2,}" , ~flags = "g" )
48+ Js .String .replaceByRe (regex , "" , content )
49+ }
50+
51+ let removeToDos = (content : string ): string => {
52+ let regex = Js .Re .fromStringWithFlags ("<!-- TODO[\\ s\\ S]*?-->" , ~flags = "g" )
53+ Js .String .replaceByRe (regex , "" , content )
54+ }
55+
56+ let createFullFile = (content : string , filePath : string ): unit => {
57+ Node .Fs .appendFileSync (filePath , content ++ "\n " , "utf8" )
58+ }
59+
60+ let createSmallFile = (content : string , filePath : string ): unit => {
61+ let smallContent =
62+ content
63+ -> removeCodeTabTags
64+ -> removeFileTitle
65+ -> removeToDos
66+ -> removeCodeBlocks
67+ -> removeUnnecessaryBreaks
68+ Node .Fs .appendFileSync (filePath , smallContent , "utf8" )
69+ }
70+
71+ let processVersions = (
72+ versions : array <string >,
73+ docsDirectory : string ,
74+ llmsDirectory : string ,
75+ ): unit => {
76+ let fullFileName = "llm-full.txt"
77+ let smallFileName = "llm-small.txt"
78+ let llmsFileName = "llms.txt"
79+
80+ versions -> Array .forEach (version => {
81+ let versionDir = docsDirectory -> Node .Path .join2 (version )
82+ let llmsDir = llmsDirectory -> Node .Path .join2 (version )
83+ let fullFilePath = llmsDir -> Node .Path .join2 (fullFileName )
84+ let smallFilePath = llmsDir -> Node .Path .join2 (smallFileName )
85+
86+ createDirectoryIfNotExists (llmsDir )
87+ clearFile (fullFilePath )
88+ clearFile (smallFilePath )
89+
90+ versionDir
91+ -> collectFiles
92+ -> Array .forEach (filePath => {
93+ if Js .String .endsWith (".mdx" , filePath ) {
94+ let content = readMarkdownFile (filePath )
95+
96+ content -> createFullFile (fullFilePath )
97+
98+ content -> createSmallFile (smallFilePath )
99+ }
100+ })
101+ })
102+ }
103+
104+ let manualVersions = ["v12.0.0" , "v11.0.0" ]
105+ let reactManualVersions = ["latest" , "v0.10.0" , "v0.11.0" ]
106+
107+ let manualDocsDirectory = "pages/docs/manual"
108+ let reactDocsDirectory = "pages/docs/react"
109+
110+ let manualLlmsDirectory = "public/llms/manual"
111+ let reactLlmsDirectory = "public/llms/react"
112+
113+ processVersions (manualVersions , manualDocsDirectory , manualLlmsDirectory )
114+ processVersions (reactManualVersions , reactDocsDirectory , reactLlmsDirectory )
0 commit comments