lua-doc-extractor
Advanced tools
| { | ||
| "name": "lua-doc-extractor", | ||
| "version": "3.0.0", | ||
| "version": "3.1.0", | ||
| "description": "Extracts lua documentation from C-style comments", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -42,2 +42,3 @@ import { LuaNamedType, LuaType } from "./luaType"; | ||
| isLocal: boolean; | ||
| tables: Table[]; | ||
| name: string; | ||
@@ -44,0 +45,0 @@ description: string; |
+23
-7
@@ -15,2 +15,3 @@ #!/usr/bin/env node | ||
| const package_json_1 = __importDefault(require("../package.json")); | ||
| const result_1 = require("./result"); | ||
| const optionList = [ | ||
@@ -56,2 +57,7 @@ { | ||
| { | ||
| name: "error", | ||
| type: Boolean, | ||
| description: "{white (Default: false)} Return error code 1 if any errors or warnings are encountered.\n", | ||
| }, | ||
| { | ||
| name: "help", | ||
@@ -91,3 +97,3 @@ alias: "h", | ||
| async function runAsync() { | ||
| const { src, dest, help, repo, file } = options; | ||
| const { src, dest, help, repo, file, error: enableErrorCode } = options; | ||
| if (help) { | ||
@@ -102,8 +108,14 @@ printUsage(); | ||
| console.log((0, chalk_1.default) `{bold.underline Extracting docs:}\n`); | ||
| const docs = await Promise.all(src.map(async (path) => { | ||
| const [docResult, error] = (0, _1.getDocs)(await (0, promises_1.readFile)(path, "utf8"), path); | ||
| const processed = await Promise.all(src.map(async (path) => { | ||
| const [file, fileError] = await (0, result_1.toResultAsync)(() => (0, promises_1.readFile)(path, "utf8")); | ||
| if (fileError != null) { | ||
| console.error((0, chalk_1.default) `{bold.red ✘} '{white ${path}}'`); | ||
| errors.push((0, chalk_1.default) `'{white ${path}}': Error loading file: ${fileError}`); | ||
| return null; | ||
| } | ||
| const [docResult, error] = (0, _1.getDocs)(file, path); | ||
| if (error != null) { | ||
| console.error((0, chalk_1.default) `{bold.red ✘} '{white ${path}}'`); | ||
| errors.push((0, chalk_1.default) `'{white ${path}}': ${error}`); | ||
| return []; | ||
| return null; | ||
| } | ||
@@ -120,6 +132,7 @@ const [docs, docErrors] = docResult; | ||
| })); | ||
| const valid = processed.filter((e) => e != null); | ||
| console.log((0, chalk_1.default) `\n{bold.underline Writing output:}\n`); | ||
| if (file === undefined) { | ||
| // Multi-file output. | ||
| await Promise.all(docs.map(async ([path, ds]) => { | ||
| await Promise.all(valid.map(async ([path, ds]) => { | ||
| const outPath = (0, path_1.join)(dest, `${(0, path_1.basename)(path, (0, path_1.extname)(path))}.lua`); | ||
@@ -132,4 +145,4 @@ await writeLibraryFile(ds, outPath, repo, [path]); | ||
| const outPath = (0, path_1.join)(dest, file); | ||
| const sources = docs.map(([path]) => path); | ||
| await writeLibraryFile(docs.flatMap(([, ds]) => ds), outPath, repo, sources); | ||
| const sources = valid.map(([path]) => path); | ||
| await writeLibraryFile(valid.flatMap(([, ds]) => ds), outPath, repo, sources); | ||
| } | ||
@@ -139,2 +152,5 @@ console.log((0, chalk_1.default) `\n{bold {green ✔} Done}\n`); | ||
| console.error((0, chalk_1.default) `\n{red.underline ERRORS}\n\n${errors.join("\n")}`); | ||
| if (enableErrorCode) { | ||
| process.exit(1); | ||
| } | ||
| } | ||
@@ -141,0 +157,0 @@ } |
+1
-0
@@ -51,2 +51,3 @@ "use strict"; | ||
| isLocal: false, | ||
| tables: [], | ||
| name: tableName, | ||
@@ -53,0 +54,0 @@ description: "", |
@@ -30,3 +30,3 @@ "use strict"; | ||
| }, | ||
| { "name": "attribute", "symbols": [(docLexer_1.docLexer.has("tableAttr") ? { type: "tableAttr" } : tableAttr), "__", "identifier", "lines"], "postprocess": ([, , name, description]) => (0, attribute_1.createAttribute)("table", { isLocal: false, name, description }) | ||
| { "name": "attribute", "symbols": [(docLexer_1.docLexer.has("tableAttr") ? { type: "tableAttr" } : tableAttr), "__", "fieldIdentifier", "description"], "postprocess": ([, , field, description]) => (0, attribute_1.createAttribute)("table", { isLocal: false, ...field, description }) | ||
| }, | ||
@@ -33,0 +33,0 @@ { "name": "attribute", "symbols": [(docLexer_1.docLexer.has("enumAttr") ? { type: "enumAttr" } : enumAttr), "__", "identifier", "lines"], "postprocess": ([, , name, description]) => (0, attribute_1.createAttribute)("enum", { name, description }) |
@@ -10,1 +10,2 @@ export type Success<T> = [T, null]; | ||
| export declare function toResult<T>(fn: () => T): Result<T>; | ||
| export declare function toResultAsync<T>(fn: () => Promise<T>): Promise<Result<T>>; |
@@ -9,2 +9,3 @@ "use strict"; | ||
| exports.toResult = toResult; | ||
| exports.toResultAsync = toResultAsync; | ||
| function isSuccess(result) { | ||
@@ -39,1 +40,9 @@ return result[1] === null; | ||
| } | ||
| async function toResultAsync(fn) { | ||
| try { | ||
| return success(await fn()); | ||
| } | ||
| catch (e) { | ||
| return failAny(e); | ||
| } | ||
| } |
@@ -43,3 +43,3 @@ "use strict"; | ||
| // Generate code. | ||
| const { isLocal, name } = table.args; | ||
| const { isLocal, tables, name } = table.args; | ||
| const fieldAttrs = (0, doc_1.hasAttribute)(doc, "class") | ||
@@ -49,7 +49,8 @@ ? [] | ||
| const fields = formatTableFields(fieldAttrs); | ||
| const qualifiedName = (0, field_1.formatFieldName)(tables, name); | ||
| if (isLocal) { | ||
| doc.lua.push(`local ${name} = {${fields}}`); | ||
| doc.lua.push(`local ${qualifiedName} = {${fields}}`); | ||
| } | ||
| else { | ||
| doc.lua.push(`${name} = {${fields}}`); | ||
| doc.lua.push(`${qualifiedName} = {${fields}}`); | ||
| } | ||
@@ -56,0 +57,0 @@ }; |
@@ -21,2 +21,3 @@ "use strict"; | ||
| isLocal: true, | ||
| tables: [], | ||
| name, | ||
@@ -34,2 +35,3 @@ description: "", | ||
| isLocal: false, | ||
| tables: [], | ||
| name: enumName, | ||
@@ -36,0 +38,0 @@ description: "", |
+1
-1
| { | ||
| "name": "lua-doc-extractor", | ||
| "version": "3.0.0", | ||
| "version": "3.1.0", | ||
| "description": "Extracts lua documentation from C-style comments", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
67931
1.77%1534
2.06%