From a73b2d1ab864642d70c3676769e1faf1369daad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 8 Jun 2022 17:16:22 +0800 Subject: build config --- tools/build-doc.lua | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tools/build-doc.lua (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua new file mode 100644 index 00000000..f0331872 --- /dev/null +++ b/tools/build-doc.lua @@ -0,0 +1,4 @@ +package.path = package.path .. ';script/?.lua;tools/?.lua' + +local config = require 'configuration' + -- cgit v1.2.3 From 38484bc7546869604751274f21de9f46ca8faf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 8 Jun 2022 21:25:26 +0800 Subject: config doc --- tools/build-doc.lua | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua index f0331872..0ad50876 100644 --- a/tools/build-doc.lua +++ b/tools/build-doc.lua @@ -1,4 +1,97 @@ package.path = package.path .. ';script/?.lua;tools/?.lua' -local config = require 'configuration' +local fs = require 'bee.filesystem' +local config = require 'configuration' +local markdown = require 'provider.markdown' +local util = require 'utility' +local lloader = require 'locale-loader' +local inspect = require 'inspect' +local json = require 'json' +local function getLocale() + local locale = {} + + for dirPath in fs.pairs(fs.path 'locale') do + local lang = dirPath:filename():string() + local text = util.loadFile((dirPath / 'setting.lua'):string()) + if text then + locale[lang] = lloader(text, lang) + end + end + + return locale +end + +local localeMap = getLocale() + +local function getDesc(lang, desc) + if not desc then + return nil + end + if desc:sub(1, 1) ~= '%' or desc:sub(-1, -1) ~= '%' then + return desc + end + local locale = localeMap[lang] + if not locale then + return desc + end + local id = desc:sub(2, -2) + return locale[id] +end + +local function buildDesc(md, lang, conf) + local desc = conf.markdownDescription or conf.description + desc = getDesc(lang, desc) + if desc then + md:add('md', desc .. '\n') + else + md:add('md', '**Missing description!!**') + end +end + +local function buildDefault(md, lang, conf) + if not conf.default then + return + end + local default = conf.default + if default == json.null then + default = nil + end + md:add('md', '## default') + md:add('md', ('`%s`'):format(inspect(default))) +end + +local function buildEnum(md, lang, conf) + if not conf.enum then + return nil + end + md:add('md', '## enum') + for i, enum in ipairs(conf.enum) do + local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) + if desc then + md:add('md', ('* `%s`: %s'):format(inspect(enum), desc)) + else + md:add('md', ('* `%s`'):format(inspect(enum))) + end + end +end + +local function buildMarkdown(lang) + local dir = fs.path 'doc' / lang / 'config' + fs.create_directories(dir) + local configDoc = markdown() + + for name, conf in util.sortPairs(config) do + configDoc:add('md', '# ' .. name:gsub('^Lua%.', '') .. '\n') + buildDesc(configDoc, lang, conf) + buildDefault(configDoc, lang, conf) + buildEnum(configDoc, lang, conf) + configDoc:add('md', '') + end + + util.saveFile((dir / 'config.md'):string(), configDoc:string()) +end + +for lang in pairs(localeMap) do + buildMarkdown(lang) +end -- cgit v1.2.3 From c481991fee74022dd261fab3bd5f07f472b9f9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 9 Jun 2022 00:44:28 +0800 Subject: update config --- tools/build-doc.lua | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua index 0ad50876..a1fee036 100644 --- a/tools/build-doc.lua +++ b/tools/build-doc.lua @@ -39,14 +39,27 @@ local function getDesc(lang, desc) return locale[id] end +local function buildType(md, lang, conf) + md:add('md', '## type') + if type(conf.type) == 'table' then + md:add('md', ('`%s | %s`'):format(conf.type[1], conf.type[2])) + elseif conf.type == 'array' then + md:add('md', ('`%s<%s>`'):format(conf.type, conf.items.type)) + else + md:add('md', ('`%s`'):format(conf.type)) + end + md:emptyLine() +end + local function buildDesc(md, lang, conf) local desc = conf.markdownDescription or conf.description desc = getDesc(lang, desc) if desc then - md:add('md', desc .. '\n') + md:add('md', desc) else md:add('md', '**Missing description!!**') end + md:emptyLine() end local function buildDefault(md, lang, conf) @@ -58,7 +71,13 @@ local function buildDefault(md, lang, conf) default = nil end md:add('md', '## default') - md:add('md', ('`%s`'):format(inspect(default))) + md:emptyLine() + if type(default) == 'table' and conf.type == 'array' then + md:add('md', ('`[%s]`'):format(inspect(default):sub(2, -2))) + else + md:add('md', ('`%s`'):format(inspect(default))) + end + md:emptyLine() end local function buildEnum(md, lang, conf) @@ -66,6 +85,7 @@ local function buildEnum(md, lang, conf) return nil end md:add('md', '## enum') + md:emptyLine() for i, enum in ipairs(conf.enum) do local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) if desc then @@ -82,11 +102,13 @@ local function buildMarkdown(lang) local configDoc = markdown() for name, conf in util.sortPairs(config) do - configDoc:add('md', '# ' .. name:gsub('^Lua%.', '') .. '\n') + configDoc:add('md', '# ' .. name:gsub('^Lua%.', '')) + configDoc:emptyLine() buildDesc(configDoc, lang, conf) + buildType(configDoc, lang, conf) buildDefault(configDoc, lang, conf) buildEnum(configDoc, lang, conf) - configDoc:add('md', '') + configDoc:emptyLine() end util.saveFile((dir / 'config.md'):string(), configDoc:string()) -- cgit v1.2.3 From 05fc6b11b399f3024679d9ca9226b00cc193ae86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 9 Jun 2022 02:22:30 +0800 Subject: update doc --- tools/build-doc.lua | 80 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 26 deletions(-) (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua index a1fee036..7c006e0d 100644 --- a/tools/build-doc.lua +++ b/tools/build-doc.lua @@ -5,8 +5,7 @@ local config = require 'configuration' local markdown = require 'provider.markdown' local util = require 'utility' local lloader = require 'locale-loader' -local inspect = require 'inspect' -local json = require 'json' +local json = require 'json-beautify' local function getLocale() local locale = {} @@ -42,13 +41,24 @@ end local function buildType(md, lang, conf) md:add('md', '## type') if type(conf.type) == 'table' then - md:add('md', ('`%s | %s`'):format(conf.type[1], conf.type[2])) + md:add('ts', ('%s | %s'):format(conf.type[1], conf.type[2])) elseif conf.type == 'array' then - md:add('md', ('`%s<%s>`'):format(conf.type, conf.items.type)) + md:add('ts', ('Array<%s>'):format(conf.items.type)) + elseif conf.type == 'object' then + if conf.properties then + local _, first = next(conf.properties) + assert(first) + md:add('ts', ('object'):format(first.type)) + elseif conf.patternProperties then + local _, first = next(conf.patternProperties) + assert(first) + md:add('ts', ('Object'):format(first.type)) + else + md:add('ts', '**Unknown object type!!**') + end else - md:add('md', ('`%s`'):format(conf.type)) + md:add('ts', ('%s'):format(conf.type)) end - md:emptyLine() end local function buildDesc(md, lang, conf) @@ -63,35 +73,54 @@ local function buildDesc(md, lang, conf) end local function buildDefault(md, lang, conf) - if not conf.default then - return - end local default = conf.default if default == json.null then default = nil end md:add('md', '## default') - md:emptyLine() - if type(default) == 'table' and conf.type == 'array' then - md:add('md', ('`[%s]`'):format(inspect(default):sub(2, -2))) + if conf.type == 'object' then + if not default then + default = {} + for k, v in pairs(conf.properties) do + default[k] = v.default + end + end + setmetatable(default, json.object) + md:add('json', ('%s'):format(json.beautify(default, { indent = ' ' }))) else - md:add('md', ('`%s`'):format(inspect(default))) + md:add('json', ('%s'):format(json.encode(default))) end - md:emptyLine() end local function buildEnum(md, lang, conf) - if not conf.enum then - return nil + if conf.enum then + md:add('md', '## enum') + md:emptyLine() + for i, enum in ipairs(conf.enum) do + local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) + if desc then + md:add('md', ('* `%s`: %s'):format(json.encode(enum), desc)) + else + md:add('md', ('* `%s`'):format(json.encode(enum))) + end + end + return end - md:add('md', '## enum') - md:emptyLine() - for i, enum in ipairs(conf.enum) do - local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) - if desc then - md:add('md', ('* `%s`: %s'):format(inspect(enum), desc)) - else - md:add('md', ('* `%s`'):format(inspect(enum))) + + if conf.type == 'object' and conf.properties then + local _, first = next(conf.properties) + if first and first.enum then + md:add('md', '## enum') + md:emptyLine() + for i, enum in ipairs(first.enum) do + local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) + if desc then + md:add('md', ('* `%s`: %s'):format(json.encode(enum), desc)) + else + md:add('md', ('* `%s`'):format(json.encode(enum))) + end + end + return end end end @@ -106,9 +135,8 @@ local function buildMarkdown(lang) configDoc:emptyLine() buildDesc(configDoc, lang, conf) buildType(configDoc, lang, conf) - buildDefault(configDoc, lang, conf) buildEnum(configDoc, lang, conf) - configDoc:emptyLine() + buildDefault(configDoc, lang, conf) end util.saveFile((dir / 'config.md'):string(), configDoc:string()) -- cgit v1.2.3 From cd81adfaf346eeaf3f547babda2338747feefc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 9 Jun 2022 02:31:47 +0800 Subject: rename doc --- tools/build-doc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua index 7c006e0d..28f29283 100644 --- a/tools/build-doc.lua +++ b/tools/build-doc.lua @@ -126,7 +126,7 @@ local function buildEnum(md, lang, conf) end local function buildMarkdown(lang) - local dir = fs.path 'doc' / lang / 'config' + local dir = fs.path 'doc' / lang fs.create_directories(dir) local configDoc = markdown() -- cgit v1.2.3 From 037309aa78dfdb73dce73bec767260967b622216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 9 Jun 2022 02:40:53 +0800 Subject: update doc --- tools/build-doc.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua index 28f29283..7fa56706 100644 --- a/tools/build-doc.lua +++ b/tools/build-doc.lua @@ -99,11 +99,12 @@ local function buildEnum(md, lang, conf) for i, enum in ipairs(conf.enum) do local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) if desc then - md:add('md', ('* `%s`: %s'):format(json.encode(enum), desc)) + md:add('md', ('* ``%s``: %s'):format(json.encode(enum), desc)) else - md:add('md', ('* `%s`'):format(json.encode(enum))) + md:add('md', ('* ``%s``'):format(json.encode(enum))) end end + md:emptyLine() return end @@ -115,14 +116,30 @@ local function buildEnum(md, lang, conf) for i, enum in ipairs(first.enum) do local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) if desc then - md:add('md', ('* `%s`: %s'):format(json.encode(enum), desc)) + md:add('md', ('* ``%s``: %s'):format(json.encode(enum), desc)) else - md:add('md', ('* `%s`'):format(json.encode(enum))) + md:add('md', ('* ``%s``'):format(json.encode(enum))) end end + md:emptyLine() return end end + + if conf.type == 'array' and conf.items.enum then + md:add('md', '## enum') + md:emptyLine() + for i, enum in ipairs(conf.items.enum) do + local desc = getDesc(lang, conf.markdownEnumDescriptions and conf.markdownEnumDescriptions[i]) + if desc then + md:add('md', ('* ``%s``: %s'):format(json.encode(enum), desc)) + else + md:add('md', ('* ``%s``'):format(json.encode(enum))) + end + end + md:emptyLine() + return + end end local function buildMarkdown(lang) -- cgit v1.2.3 From 91068747651bdd30a3ca436e25a39ec09fba0545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 25 Jun 2022 03:27:13 +0800 Subject: make doc with description of groups --- tools/build-doc.lua | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'tools/build-doc.lua') diff --git a/tools/build-doc.lua b/tools/build-doc.lua index 7fa56706..fbf5fa6b 100644 --- a/tools/build-doc.lua +++ b/tools/build-doc.lua @@ -6,6 +6,19 @@ local markdown = require 'provider.markdown' local util = require 'utility' local lloader = require 'locale-loader' local json = require 'json-beautify' +local diagd = require 'proto.diagnostic' + +local function mergeDiagnosticGroupLocale(locale) + for groupName, names in pairs(diagd.diagnosticGroups) do + local key = ('config.diagnostics.%s'):format(groupName) + local list = {} + for name in util.sortPairs(names) do + list[#list+1] = ('* %s'):format(name) + end + local desc = table.concat(list, '\n') + locale[key] = desc + end +end local function getLocale() local locale = {} @@ -15,6 +28,8 @@ local function getLocale() local text = util.loadFile((dirPath / 'setting.lua'):string()) if text then locale[lang] = lloader(text, lang) + -- add `config.diagnostics.XXX` + mergeDiagnosticGroupLocale(locale[lang]) end end @@ -85,10 +100,28 @@ local function buildDefault(md, lang, conf) default[k] = v.default end end - setmetatable(default, json.object) - md:add('json', ('%s'):format(json.beautify(default, { indent = ' ' }))) + local list = util.getTableKeys(default, true) + if #list == 0 then + md:add('jsonc', '{}') + return + end + md:add('jsonc', '{') + for i, k in ipairs(list) do + local desc = getDesc(lang, conf.properties[k].description) + if desc then + md:add('jsonc', ' /*') + md:add('jsonc', (' %s'):format(desc:gsub('\n', '\n '))) + md:add('jsonc', ' */') + end + if i == #list then + md:add('jsonc',(' %s: %s'):format(json.encode(k), json.encode(default[k]))) + else + md:add('jsonc',(' %s: %s,'):format(json.encode(k), json.encode(default[k]))) + end + end + md:add('jsonc', '}') else - md:add('json', ('%s'):format(json.encode(default))) + md:add('jsonc', ('%s'):format(json.encode(default))) end end -- cgit v1.2.3