From fcad0b33f9eb7b65767d2967d295de1cd1a4388f Mon Sep 17 00:00:00 2001 From: Aire-One Date: Mon, 19 Dec 2022 22:46:03 +0100 Subject: [PATCH 1/3] run: make the program run on all the doc site --- src/awesomewm.d.tl/init.tl | 52 +++++++++++++------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/src/awesomewm.d.tl/init.tl b/src/awesomewm.d.tl/init.tl index 743a5ec..d87c41c 100644 --- a/src/awesomewm.d.tl/init.tl +++ b/src/awesomewm.d.tl/init.tl @@ -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 -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" -) +for i = 1, #module_infos do + do_one_file( + property.base_url .. "/" .. module_infos[i].uri, + property.out_directory .. "/" + ) +end From 0c4b2a84f3c6fe6c42b2e744782c0e7c932d694f Mon Sep 17 00:00:00 2001 From: Aire-One Date: Mon, 19 Dec 2022 22:47:47 +0100 Subject: [PATCH 2/3] fix(filesystem): mkdir handle multiple parents --- .vscode/settings.json | 3 +- rockspecs/awesomewm.d.tl-dev-1.rockspec | 1 + src/awesomewm.d.tl/filesystem/file_writer.tl | 23 +++++- tlconfig.lua | 1 + types/lfs.d.tl | 82 ++++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 types/lfs.d.tl diff --git a/.vscode/settings.json b/.vscode/settings.json index d31f9d8..e21c6be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", diff --git a/rockspecs/awesomewm.d.tl-dev-1.rockspec b/rockspecs/awesomewm.d.tl-dev-1.rockspec index cc2af55..0e9fdc1 100644 --- a/rockspecs/awesomewm.d.tl-dev-1.rockspec +++ b/rockspecs/awesomewm.d.tl-dev-1.rockspec @@ -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", diff --git a/src/awesomewm.d.tl/filesystem/file_writer.tl b/src/awesomewm.d.tl/filesystem/file_writer.tl index a68581f..de44d8a 100644 --- a/src/awesomewm.d.tl/filesystem/file_writer.tl +++ b/src/awesomewm.d.tl/filesystem/file_writer.tl @@ -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) diff --git a/tlconfig.lua b/tlconfig.lua index aafa9c4..0fa854d 100644 --- a/tlconfig.lua +++ b/tlconfig.lua @@ -4,5 +4,6 @@ return { include_dir = { "src/awesomewm.d.tl", "types", + "generated", -- used to remove require error when visualizing the generated type definitions }, } diff --git a/types/lfs.d.tl b/types/lfs.d.tl new file mode 100644 index 0000000..12535ca --- /dev/null +++ b/types/lfs.d.tl @@ -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 From a6af7a77e43c347ffd3671f6b6e8b625dffb6376 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Mon, 19 Dec 2022 22:48:21 +0100 Subject: [PATCH 3/3] run: add a just `validate` command --- justfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/justfile b/justfile index 2e65606..5fea64e 100644 --- a/justfile +++ b/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