fennel-ls/tools/gen-docs.fnl
XeroOl 3564167cab TIC80 docs are in!
You can't turn them on because I haven't sorted out the settings yet.
But, the docs are in!
2024-05-31 13:39:04 -05:00

53 lines
2.0 KiB
Fennel

"Script to generate /src/fennel-ls/docs/lua54.fnl and friends automatically"
(fn sh [...]
"run a shell command."
(let [command (table.concat
(icollect [_ arg (ipairs [...])]
(if
;; table skips escaping
(= (type arg) :table)
(. arg 1)
;; simple string skips escaping
(arg:find "^[a-zA-Z0-9/_-]+$")
arg
;; full escaping
(.. "'"
(string.gsub arg "'" "\\'")
"'")))
" ")]
(print (.. "tools/gen-docs: " command))
(os.execute command)))
(fn mkdir-p [dirname]
(sh "mkdir" "-p" dirname))
(fn curl-cached [url]
(let [filename (.. "build/" (url:gsub "[/:]" "_"))
file (io.open filename :r)]
(if file
file
(do
(sh "curl" url [">"] filename)
(io.open filename :r)))))
(fn derive-docs-from-url [url out-filename convert]
(let [result
(convert
(with-open [file (curl-cached url)]
(file:read "*a")))]
(with-open [file (io.open (.. "src/fennel-ls/docs/" out-filename) :w)]
(file:write ";; auto-generated by `make docs` from fennel-ls. Contents come from " url "\n"
result "\n"))))
(fn main []
(let [{:convert lua-manual} (require :tools.gen-docs.lua-manual)
{:convert tic-manual} (require :tools.gen-docs.tic80)]
(derive-docs-from-url "https://www.lua.org/manual/5.1/manual.html" "lua51.fnl" lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.2/manual.html" "lua52.fnl" lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.3/manual.html" "lua53.fnl" lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.4/manual.html" "lua54.fnl" lua-manual)
(derive-docs-from-url "https://tic80.com/learn" "tic80.fnl" tic-manual)))
(main)