Merge pull request 'Run the program on the whole doc site' (#55) from feat/run-on-all into master
Reviewed-on: #55
This commit is contained in:
commit
cceb8a1ffc
|
@ -7,8 +7,8 @@
|
|||
"editor.acceptSuggestionOnEnter": "off"
|
||||
},
|
||||
"cSpell.words": [
|
||||
"aireone",
|
||||
"aire-one",
|
||||
"aireone",
|
||||
"ansicolors",
|
||||
"awesomewm",
|
||||
"buildx",
|
||||
|
@ -21,6 +21,7 @@
|
|||
"lldebugger",
|
||||
"Luacheck",
|
||||
"luacheckrc",
|
||||
"luafilesystem",
|
||||
"lualogging",
|
||||
"Luarocks",
|
||||
"luasec",
|
||||
|
|
3
justfile
3
justfile
|
@ -40,6 +40,9 @@ clean:
|
|||
run:
|
||||
{{ tl }} src/awesomewm.d.tl/init.tl
|
||||
|
||||
validate:
|
||||
cyan check `find generated/ -type f -iname '*.d.tl' | xargs`
|
||||
|
||||
# TODO : how to run a debugger on Teal code?
|
||||
debug:
|
||||
{{ lua }} debug.lua build/awesomewm.d.tl/init.lua
|
||||
|
|
|
@ -16,6 +16,7 @@ dependencies = {
|
|||
"penlight 1.13.1",
|
||||
"luasocket 3.1.0-1",
|
||||
"luasec 1.2.0-1",
|
||||
"luafilesystem 1.8.0-1",
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
local file = require "pl.file"
|
||||
local lfs = require "lfs"
|
||||
local logger = require "logger"
|
||||
local path = require "pl.path"
|
||||
|
||||
local log = logger.log("file_writer")
|
||||
|
||||
local function mkdir(dir_path: string)
|
||||
local sep, parent_dir = "/", ""
|
||||
for dir in dir_path:gmatch("[^" .. sep .. "]+") do
|
||||
parent_dir = parent_dir .. dir .. sep
|
||||
if not path.isdir(parent_dir) then
|
||||
local success, error_message = lfs.mkdir(parent_dir)
|
||||
if not success then
|
||||
log:error(logger.message_with_metadata(
|
||||
"Failed to create directory",
|
||||
{
|
||||
directory = parent_dir,
|
||||
error = error_message,
|
||||
}
|
||||
))
|
||||
error("Failed to create directory " .. parent_dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function write_file(file_content: string, file_path: string): boolean, nil | string
|
||||
-- Make sure the directory we want to write the file to exists
|
||||
local directory = path.dirname(file_path)
|
||||
if not path.isdir(directory) then
|
||||
path.mkdir(directory)
|
||||
mkdir(directory)
|
||||
end
|
||||
|
||||
return file.write(file_path, file_content, false)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
local crawler = require "crawler"
|
||||
local filesystem = require "filesystem"
|
||||
local List = require "pl.List"
|
||||
local logger = require "logger"
|
||||
local Module_Info = require "entity.Module_Info"
|
||||
local property = require "property"
|
||||
local scraper = require "scraper"
|
||||
local generator = require "generator"
|
||||
|
@ -11,48 +13,28 @@ log:info(logger.message_with_metadata("Start", { property = property }))
|
|||
|
||||
local index = crawler.fetch(property.base_url .. property.index_uri)
|
||||
|
||||
-- local modules =
|
||||
-- scraper.get_modules_from_index(index, property.ignored_modules)
|
||||
local module_infos = scraper.module_info_list.get_modules_from_index(index)
|
||||
local ignored_modules = List(property.ignored_modules)
|
||||
local module_infos = List(scraper.module_info_list.get_modules_from_index(index)):filter(
|
||||
function(module: Module_Info.Module_Info): boolean
|
||||
return not ignored_modules:contains(module.name)
|
||||
end
|
||||
)
|
||||
|
||||
log:info("Finished Module List scrapping, found " .. #module_infos .. " modules")
|
||||
-- for i = 1, 1 do -- #modules do
|
||||
-- local m = modules[i]
|
||||
-- log:info(inspect { try = m })
|
||||
-- local page = crawler.fetch(property.base_url .. "/" .. m.uri)
|
||||
-- local items = scraper.get_doc_from_page(page)
|
||||
-- log:info(inspect { items })
|
||||
-- end
|
||||
|
||||
local function do_one_file(url: string, module_name: string, output: string)
|
||||
local function do_one_file(url: string, output_base_dir: string)
|
||||
local module_name = url:gsub(".*/", ""):gsub(".html", "")
|
||||
local html = crawler.fetch(url)
|
||||
local module_doc = scraper.module_doc.get_doc_from_page(html, module_name)
|
||||
filesystem.file_writer.write(
|
||||
generator.teal_type_definitions.generate_teal(module_doc),
|
||||
output
|
||||
output_base_dir .. module_name:gsub("%.", "/") .. ".d.tl"
|
||||
)
|
||||
end
|
||||
|
||||
for i = 1, #module_infos do
|
||||
do_one_file(
|
||||
property.base_url .. "/widgets/wibox.widget.textbox.html",
|
||||
"wibox.widget.textbox",
|
||||
property.out_directory .. "/textbox.d.tl"
|
||||
)
|
||||
|
||||
do_one_file(
|
||||
property.base_url .. "/popups_and_bars/wibox.html",
|
||||
"wibox",
|
||||
property.out_directory .. "/wibox.d.tl"
|
||||
)
|
||||
|
||||
do_one_file(
|
||||
property.base_url .. "/widget_layouts/wibox.layout.fixed.html",
|
||||
"wibox.layout.fixed",
|
||||
property.out_directory .. "/fixed.d.tl"
|
||||
)
|
||||
|
||||
do_one_file(
|
||||
property.base_url .. "/core_components/client.html",
|
||||
"client",
|
||||
property.out_directory .. "/client.d.tl"
|
||||
property.base_url .. "/" .. module_infos[i].uri,
|
||||
property.out_directory .. "/"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -4,5 +4,6 @@ return {
|
|||
include_dir = {
|
||||
"src/awesomewm.d.tl",
|
||||
"types",
|
||||
"generated", -- used to remove require error when visualizing the generated type definitions
|
||||
},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
local record lfs
|
||||
|
||||
enum FileMode
|
||||
"file"
|
||||
"directory"
|
||||
"link"
|
||||
"socket"
|
||||
"named pipe"
|
||||
"char device"
|
||||
"block device"
|
||||
"other"
|
||||
end
|
||||
|
||||
record Attributes
|
||||
dev: number
|
||||
ino: number
|
||||
mode: FileMode
|
||||
nlink: number
|
||||
uid: number
|
||||
gid: number
|
||||
rdev: number
|
||||
access: number
|
||||
modification: number
|
||||
change: number
|
||||
size: number
|
||||
permissions: string
|
||||
blocks: number
|
||||
blksize: number
|
||||
end
|
||||
|
||||
enum OpenFileMode
|
||||
"binary"
|
||||
"text"
|
||||
end
|
||||
|
||||
enum LockMode
|
||||
"r"
|
||||
"w"
|
||||
end
|
||||
|
||||
record Lock
|
||||
free: function()
|
||||
end
|
||||
|
||||
dir: function(string): function(): string
|
||||
|
||||
chdir: function(string): boolean, string
|
||||
|
||||
lock_dir: function(string, number): Lock, string
|
||||
|
||||
-- returns number on success, really!? this should be fixed in the lfs library
|
||||
link: function(string, string, boolean): number, string
|
||||
|
||||
mkdir: function(string): boolean, string
|
||||
|
||||
rmdir: function(string): boolean, string
|
||||
|
||||
setmode: function(string, OpenFileMode): boolean, string
|
||||
|
||||
currentdir: function(): string
|
||||
|
||||
attributes: function(string): Attributes
|
||||
attributes: function(string, string): string
|
||||
attributes: function(string, string): number
|
||||
attributes: function(string, string): FileMode
|
||||
attributes: function(string, Attributes): Attributes
|
||||
|
||||
symlinkattributes: function(string): Attributes
|
||||
symlinkattributes: function(string, string): string
|
||||
symlinkattributes: function(string, string): number
|
||||
symlinkattributes: function(string, string): FileMode
|
||||
symlinkattributes: function(string, Attributes): Attributes
|
||||
|
||||
touch: function(string, number, number): boolean, string
|
||||
|
||||
-- TODO: FILE needs to be renamed to io.FILE in tl itself
|
||||
lock: function(FILE, LockMode, number, number): boolean, string
|
||||
unlock: function(FILE, number, number): boolean, string
|
||||
|
||||
end
|
||||
|
||||
return lfs
|
Loading…
Reference in New Issue