@@ -2,8 +2,6 @@ open Node;
22open Belt ;
33
44let root = Process . cwd() ;
5- let sourcePath = Path . join([| root, "docs" |] );
6- let outputPath = Path . join([| root, "build/md" |] );
75
86{
97 HighlightJs . (hjs-> registerLanguage("reason" , reason));
@@ -16,6 +14,7 @@ let remarkable =
1614 "html" : true ,
1715 "linkify" : true ,
1816 "xhtmlOut" : true ,
17+ "langPrefix" : "hljs language-" ,
1918 "highlight" :
2019 Some (
2120 (code, lang) =>
@@ -30,48 +29,156 @@ let remarkable =
3029 },
3130 );
3231
32+ Js . log("Pages..." );
33+ let sourcePath = Path . join([| root, "docs" |] );
34+ let outputPath = Path . join([| root, "build" , "docs-pages" |] );
3335Path . join([| sourcePath, "**/*.md" |] )
3436-> FsUtils . transform(files => {
3537 let newFiles : array (FsUtils . t ) = [||] ;
36- files-> Array . reduce(
37- newFiles,
38- (files, file) => {
39- let shortName =
40- file. name
41- |> Js . String . replace(sourcePath, "" )
42- |> Js . String . replace(".md" , "" );
43- let front = FrontMatter . parse(file. content);
44- let content =
45- {
46- "id" : front## attributes## id,
47- "title" : front## attributes## title,
48- "body" : Remarkable . render(remarkable, front## body),
49- }
50- -> Js . Json . stringifyAny;
51- if (content-> Option . isNone) {
52- Js . log2(file. name, "can't be transformed" );
53- };
54- content
55- -> Option . map(content =>
56- files-> Array . concat([|
57- {
58- name: Path . join([| outputPath, shortName ++ ".json" |] ),
59- content,
60- },
61- |] )
38+ let finalFiles =
39+ files-> Array . reduce(
40+ newFiles,
41+ (files, file) => {
42+ let shortName =
43+ file. name
44+ |> Js . String . replace(sourcePath, "" )
45+ |> Js . String . replace(".md" , "" );
46+ let front = FrontMatter . parse(file. content);
47+ let content =
48+ {
49+ "id" : front## attributes## id,
50+ "title" : front## attributes## title,
51+ "body" : Remarkable . render(remarkable, front## body),
52+ }
53+ -> Js . Json . stringifyAny;
54+ if (content-> Option . isNone) {
55+ Js . log2(file. name, "can't be transformed" );
56+ };
57+ content
58+ -> Option . map(content =>
59+ files-> Array . concat([|
60+ {
61+ name: Path . join([| outputPath, shortName ++ ".json" |] ),
62+ content,
63+ },
64+ |] )
65+ )
66+ -> Option . getWithDefault(files);
67+ },
68+ );
69+ finalFiles-> Array . concat([|
70+ {
71+ name: Path . join([| outputPath, "__index__.json" |] ),
72+ content:
73+ (
74+ finalFiles-> Array . map(file =>
75+ file. name
76+ |> Js . String . replace(outputPath ++ "/" , "" )
77+ |> Js . String . replace(".json" , "" )
78+ )
79+ |> Js . Json . stringifyAny
80+ )
81+ -> Option . getWithDefault("[]" ),
82+ },
83+ |] );
84+ });
85+
86+ Js . log("Create missing markdown files (wip)..." );
87+ // create missing md for modules
88+ [@ bs . module "fs" ] external existsSync : string => bool = "existsSync" ;
89+ let createMissingMd = (sourcePath, outputPath, files) => {
90+ let newFiles : array (FsUtils . t ) = [||] ;
91+ files-> Array . reduce(
92+ newFiles,
93+ (files, file: FsUtils . t ) => {
94+ let shortName =
95+ file. name
96+ |> Js . String . replace(sourcePath ++ "/" , "" )
97+ |> Js . String . replace(".rei" , "" )
98+ |> Js . String . replace(".re" , "" );
99+ let finalfilename = Path . join([| outputPath, shortName ++ ".md" |] );
100+ if (try (! existsSync(finalfilename)) {
101+ | _ => true
102+ }) {
103+ let name = shortName-> Path . basename;
104+ let code = file. content;
105+ let content = { j | ---
106+ id: $shortName
107+ title: $name
108+ wip: true
109+ ---
110+
111+ ```reason
112+ $code
113+ ```
114+ | j } ;
115+ files-> Array . concat([| {name: finalfilename, content}|] );
116+ } else {
117+ files;
118+ };
119+ },
120+ );
121+ };
122+ let sourcePath = Path . join([| root, ".." , "bs-react-native-next" , "src" |] );
123+ let outputPath = Path . join([| root, ".." , "bs-react-native-next" , "src" |] );
124+ // create from rei first
125+ Path . join([| sourcePath, "**/*.rei" |] )
126+ -> FsUtils . transform(createMissingMd(sourcePath, outputPath));
127+ // fallback to re
128+ Path . join([| sourcePath, "**/*.re" |] )
129+ -> FsUtils . transform(createMissingMd(sourcePath, outputPath));
130+
131+ Js . log("Modules..." );
132+ let sourcePath = Path . join([| root, ".." , "bs-react-native-next" , "src" |] );
133+ let outputPath = Path . join([| root, "build" , "docs-src" |] );
134+ Path . join([| sourcePath, "**/*.md" |] )
135+ -> FsUtils . transform(files => {
136+ let newFiles : array (FsUtils . t ) = [||] ;
137+ let finalFiles =
138+ files-> Array . reduce(
139+ newFiles,
140+ (files, file) => {
141+ let shortName =
142+ file. name
143+ |> Js . String . replace(sourcePath, "" )
144+ |> Js . String . replace(".md" , "" );
145+ let front = FrontMatter . parse(file. content);
146+ let content =
147+ {
148+ "id" : front## attributes## id,
149+ "title" : front## attributes## title,
150+ "wip" : front## attributes## wip,
151+ "body" : Remarkable . render(remarkable, front## body),
152+ }
153+ -> Js . Json . stringifyAny;
154+ if (content-> Option . isNone) {
155+ Js . log2(file. name, "can't be transformed" );
156+ };
157+ content
158+ -> Option . map(content =>
159+ files-> Array . concat([|
160+ {
161+ name: Path . join([| outputPath, shortName ++ ".json" |] ),
162+ content,
163+ },
164+ |] )
165+ )
166+ -> Option . getWithDefault(files);
167+ },
168+ );
169+ finalFiles-> Array . concat([|
170+ {
171+ name: Path . join([| outputPath, "__index__.json" |] ),
172+ content:
173+ (
174+ finalFiles-> Array . map(file =>
175+ file. name
176+ |> Js . String . replace(outputPath ++ "/" , "" )
177+ |> Js . String . replace(".json" , "" )
178+ )
179+ |> Js . Json . stringifyAny
62180 )
63- -> Option . getWithDefault(files) ;
181+ -> Option . getWithDefault("[]" ) ,
64182 },
65- );
66- }) /* ->Future.map(files => {
67- let names = files->Array.map(file => file.name);
68- {"files": names}
69- ->Js.Json.stringifyAny
70- ->Option.map(jsonNames =>
71- Fs.writeFileAsUtf8Sync(
72- Path.join([|outputPath, "__index__" ++ ".json"|]),
73- jsonNames,
74- )
75- )
76- ->ignore;
77- })*/ ;
183+ |] );
184+ });
0 commit comments