forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_gen.js
80 lines (64 loc) · 2.91 KB
/
doc_gen.js
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
//@ts-check
// This assume you already have cmi at hand
// Okay to use ES6 since it is generated before shipping
var fs = require('fs')
var path = require('path')
var child_process = require('child_process')
var runtime_dir = path.join(__dirname,'..','jscomp','runtime')
var others_dir = path.join(__dirname,'..','jscomp','others')
var stdlib_dir = path.join(__dirname,'..','jscomp','stdlib-402')
var jscomp = path.join(__dirname,'..','jscomp')
var runtime_prefix = path.relative(jscomp,runtime_dir)
var others_prefix = path.relative(jscomp, others_dir)
const capitalize = (s) => {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
const strip = filename => filename.split('.').slice(0, -1).join('.')
var hidden_list = []
var runtime_files =
fs.readdirSync(runtime_dir)
.filter(file =>
file.startsWith("js") && (file.endsWith(".ml") || file.endsWith(".mli")) && (!file.endsWith(".cppo.ml")) && (!file.endsWith(".cppo.mli"))
)
.map (x => {
if (x.includes("internal")){
hidden_list.push(capitalize(strip(x)))
}
return path.join(runtime_prefix,x)
})
.join(' ')
var others_files =
fs.readdirSync(others_dir)
.filter(file =>
(file.endsWith(".ml") || file.endsWith(".mli")) && (!file.endsWith(".cppo.ml")) && (!file.endsWith(".cppo.mli"))
)
.map(x=> {
if (x.includes("internal")){
hidden_list.push(capitalize(strip(x)))
}
return path.join(others_prefix,x)
})
.join(' ')
var odoc_gendir = path.join(__dirname,'..', 'odoc_gen')
var bsppx = path.join(__dirname,'..','lib','bsppx.exe')
var api_doc_dir = path.join(__dirname,'..','docs','api')
var intro = path.join(__dirname,'..','jscomp','others','intro.txt')
//
var generator = `-g ${odoc_gendir}/generator.cmxs`
// var generator = `-html`
var ocamldoc = `ocamldoc.opt`
var hidden_modules = ``
// hidden_modules = `-hide ${hidden_list.join(',')}`
// var ocamldoc = path.join(__dirname,'..','vendor','ocaml','ocamldoc','ocamldoc.opt')
var prefix_flags = `${ocamldoc} ${generator} ${hidden_modules} -w -40 -nostdlib -nopervasives -I ${others_dir} -I ${runtime_dir} -open Bs_stdlib_mini -charset utf-8 -intro ${intro} -sort -ppx ${bsppx} -d ${api_doc_dir}`
// -html it is weird
// It is weird, -html will unload the plugin
// It seems ocamldoc does need require all files for indexing modules, WTF ocamldoc !!
var cmd = `${prefix_flags} ${runtime_files} ${others_files}`
console.log(`Running ${cmd}`)
child_process.execSync(cmd, {cwd : jscomp})
// console.log(`runtime files : ${runtime_files}`)
// child_process.execSync(`${prefix_flags} ${runtime_files} `, {cwd : runtime_dir})
// console.log(`others files : ${others_files}`)
// child_process.execSync(`${prefix_flags} ${others_files} `, {cwd : others_dir})