47 lines
1.9 KiB
Fennel
47 lines
1.9 KiB
Fennel
"Script to generate /src/fennel-ls/docs/lua54.fnl and friends automatically"
|
|
|
|
(local {: sh} (require :tools.util.sh))
|
|
(local fennel (require :deps.fennel))
|
|
|
|
(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 write-doc-file! [out-filename doc-src doc-tbl]
|
|
(assert doc-tbl
|
|
"bad argument #3, `doc-tbl` to write-doc-file! (expected string, got nil)")
|
|
(with-open [file (io.open (.. :src/fennel-ls/docs/generated/ out-filename) :w)]
|
|
(file:write ";; auto-generated by `make docs` from fennel-ls. Contents come from "
|
|
doc-src "\n" doc-tbl "\n")))
|
|
|
|
(fn derive-docs-from-url [url out-filename convert]
|
|
(write-doc-file! out-filename url
|
|
(convert (with-open [file (curl-cached url)]
|
|
(file:read :*a)))))
|
|
|
|
(fn main []
|
|
(sh :mkdir :-p :build/)
|
|
(sh :mkdir :-p :src/fennel-ls/docs/generated/)
|
|
(let [{:convert lua-manual} (require :tools.get-docs.lua-manual)
|
|
{:convert tic80-manual} (require :tools.get-docs.tic80)
|
|
{:convert download-and-convert-love2d-manual!} (require :tools.get-docs.love2d)]
|
|
(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 tic80-manual)
|
|
(write-doc-file! :love2d.fnl
|
|
"https://github.com/love2d-community/love-api/"
|
|
(download-and-convert-love2d-manual!))))
|
|
|
|
(main)
|