@gesslar/bedoc 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/core/ActionManager.js +2 -4
- package/src/core/Configuration.js +12 -7
- package/src/core/Discovery.js +7 -5
- package/src/core/HookManager.js +2 -1
- package/src/core/util/ActionUtil.js +5 -3
- package/src/core/util/FDUtil.js +1 -1
- package/src/core/util/ModuleUtil.js +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gesslar/bedoc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Pluggable documentation engine for any language and format",
|
|
5
5
|
"publisher": "gesslar",
|
|
6
6
|
"main": "./src/core/Core.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"dotenv": "^16.4.7",
|
|
40
40
|
"error-stack-parser": "^2.1.4",
|
|
41
41
|
"globby": "^14.0.2",
|
|
42
|
+
"json5": "^2.2.3",
|
|
42
43
|
"micromatch": "^4.0.8",
|
|
43
44
|
"node-fetch": "^3.3.2",
|
|
44
45
|
"yaml": "^2.7.0"
|
|
@@ -49,8 +50,8 @@
|
|
|
49
50
|
"@typescript-eslint/parser": "^8.22.0",
|
|
50
51
|
"axios": "^1.7.9",
|
|
51
52
|
"chokidar": "^4.0.3",
|
|
52
|
-
"eslint-plugin-jsdoc": "^50.6.3",
|
|
53
53
|
"eslint": "^9.18.0",
|
|
54
|
+
"eslint-plugin-jsdoc": "^50.6.3",
|
|
54
55
|
"form-data": "^4.0.1"
|
|
55
56
|
},
|
|
56
57
|
"keywords": [
|
|
@@ -71,9 +71,7 @@ export default class ActionManager {
|
|
|
71
71
|
if(!setup)
|
|
72
72
|
return
|
|
73
73
|
|
|
74
|
-
await this.action.setup.call(
|
|
75
|
-
this.action, {parent: this, log: this.#log}
|
|
76
|
-
)
|
|
74
|
+
await this.action.setup.call(this.action, {log: this.#log})
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
async #cleanupAction() {
|
|
@@ -119,7 +117,7 @@ export default class ActionManager {
|
|
|
119
117
|
throw new Error(`No \`run\` function found for action \`${this.meta.action}\``)
|
|
120
118
|
|
|
121
119
|
const actionResult = await func.call(
|
|
122
|
-
this.action, {
|
|
120
|
+
this.action, {file, moduleContent: content}
|
|
123
121
|
)
|
|
124
122
|
|
|
125
123
|
return actionResult
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import process from "node:process"
|
|
2
2
|
import {Environment} from "./Core.js"
|
|
3
|
+
import JSON5 from "json5"
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
ConfigurationParameters,
|
|
@@ -217,7 +218,7 @@ export default class Configuration {
|
|
|
217
218
|
if(environmentVariables)
|
|
218
219
|
allOptions.push({source: "environment", options: environmentVariables})
|
|
219
220
|
|
|
220
|
-
const packageJson = entryOptions
|
|
221
|
+
const packageJson = entryOptions?.packageJson
|
|
221
222
|
if(packageJson?.bedoc)
|
|
222
223
|
allOptions.push({source: "packageJson", options: packageJson.bedoc})
|
|
223
224
|
|
|
@@ -228,12 +229,16 @@ export default class Configuration {
|
|
|
228
229
|
environmentVariables?.config
|
|
229
230
|
|
|
230
231
|
if(useConfig) {
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
const configFile =
|
|
233
|
+
packageJson?.bedoc?.config
|
|
234
|
+
? resolveFilename(packageJson?.bedoc?.config)
|
|
235
|
+
: entryOptions.config?.value
|
|
236
|
+
? resolveFilename(entryOptions.config.value)
|
|
237
|
+
: null
|
|
238
|
+
|
|
239
|
+
if(!configFile)
|
|
234
240
|
throw new Error("No config file specified")
|
|
235
241
|
|
|
236
|
-
const configFile = resolveFilename(configFilename)
|
|
237
242
|
const config = loadJson(configFile)
|
|
238
243
|
|
|
239
244
|
allOptions.push({source: "config", options: config})
|
|
@@ -303,7 +308,7 @@ export default class Configuration {
|
|
|
303
308
|
|
|
304
309
|
// Last, but not least, add any defaulted options that are not in the
|
|
305
310
|
// mapped options
|
|
306
|
-
for(const [key, value] of Object.entries(entryOptions)) {
|
|
311
|
+
for(const [key, value] of Object.entries(entryOptions ?? {})) {
|
|
307
312
|
if(!mappedOptions[key]) {
|
|
308
313
|
if(value.source)
|
|
309
314
|
mappedOptions[key] = value.value
|
|
@@ -329,7 +334,7 @@ export default class Configuration {
|
|
|
329
334
|
switch(param.type.toString()) {
|
|
330
335
|
case "boolean":
|
|
331
336
|
case "number":
|
|
332
|
-
options[key] =
|
|
337
|
+
options[key] = JSON5.parse(options[key])
|
|
333
338
|
break
|
|
334
339
|
}
|
|
335
340
|
}
|
package/src/core/Discovery.js
CHANGED
|
@@ -50,10 +50,10 @@ export default class Discovery {
|
|
|
50
50
|
debug("Mock path not set, discovering actions in node_modules", 1)
|
|
51
51
|
|
|
52
52
|
debug("Looking for actions in project's package.json", 2)
|
|
53
|
-
if(this.core.packageJson?.
|
|
54
|
-
const actions = this.core.packageJson?.
|
|
53
|
+
if(this.core.packageJson?.modules) {
|
|
54
|
+
const actions = this.core.packageJson?.modules
|
|
55
55
|
|
|
56
|
-
debug("Found %d actions in package.json
|
|
56
|
+
debug("Found %d actions in package.json", 3, actions)
|
|
57
57
|
debug("Actions found in package.json action in package.json: %o", 3, actions)
|
|
58
58
|
|
|
59
59
|
if(actions && typeof(actions) === "object")
|
|
@@ -158,7 +158,7 @@ export default class Discovery {
|
|
|
158
158
|
|
|
159
159
|
const loadedActions = []
|
|
160
160
|
for(const file of toLoad) {
|
|
161
|
-
debug("Loading module `%s`", 2, file.
|
|
161
|
+
debug("Loading module `%s`", 2, file.absoluteUri)
|
|
162
162
|
|
|
163
163
|
const loading = await this.#loadModule(file)
|
|
164
164
|
const loaded = loading.actions.map((action, index) => {
|
|
@@ -283,8 +283,10 @@ export default class Discovery {
|
|
|
283
283
|
debug("No specific `%s` action found", 3, actionType)
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
|
|
286
287
|
// Hmm! We didn't find anything specific. Let's check the criterion
|
|
287
288
|
debug("Checking for `%s` actions with criterion `%s`", 3, actionType, criterion)
|
|
289
|
+
debug("Validated config to check against: %o", 3, validatedConfig)
|
|
288
290
|
const found = actions[actionType].filter(a => {
|
|
289
291
|
debug("Meta criterion value: %o", 4, a.action.meta[criterion])
|
|
290
292
|
debug("Config criterion value: %o", 4, validatedConfig[criterion])
|
|
@@ -315,7 +317,7 @@ export default class Discovery {
|
|
|
315
317
|
|
|
316
318
|
debug("2 Loading module `%j`", 2, module)
|
|
317
319
|
|
|
318
|
-
const {
|
|
320
|
+
const {absoluteUri} = module
|
|
319
321
|
const moduleExports = await import(absoluteUri)
|
|
320
322
|
|
|
321
323
|
return {file: module, ...moduleExports}
|
package/src/core/HookManager.js
CHANGED
|
@@ -90,6 +90,7 @@ export default class HookManager {
|
|
|
90
90
|
return null
|
|
91
91
|
|
|
92
92
|
hooksObj.log = instance.log
|
|
93
|
+
hooksObj.timeout = this.timeout
|
|
93
94
|
instance.#hooks = hooksObj
|
|
94
95
|
|
|
95
96
|
debug("Hooks loaded successfully for `%s`", 2, instance.action)
|
|
@@ -121,7 +122,7 @@ export default class HookManager {
|
|
|
121
122
|
assert(isType(hook, "function"), `Hook "${event}" is not a function`, 1)
|
|
122
123
|
|
|
123
124
|
const hookExecution = await hook.call(this.hooks, args)
|
|
124
|
-
const hookTimeout = this.
|
|
125
|
+
const hookTimeout = this.timeout
|
|
125
126
|
const expireAsync = () =>
|
|
126
127
|
timeoutPromise(
|
|
127
128
|
hookTimeout,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as FDUtil from "./FDUtil.js"
|
|
2
|
+
import process from "node:process"
|
|
3
|
+
import JSON5 from "json5"
|
|
2
4
|
|
|
3
5
|
const {readFile, fileExists, composeFilename} = FDUtil
|
|
4
6
|
|
|
@@ -20,7 +22,7 @@ const actionMetaRequirements = freeze({
|
|
|
20
22
|
function loadJson(jsonFileObject) {
|
|
21
23
|
// Read the file
|
|
22
24
|
const jsonContent = readFile(jsonFileObject)
|
|
23
|
-
const json =
|
|
25
|
+
const json = JSON5.parse(jsonContent)
|
|
24
26
|
return json
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -31,11 +33,11 @@ function loadJson(jsonFileObject) {
|
|
|
31
33
|
* @returns {object?} The parsed package.json content or null if the file does
|
|
32
34
|
* not exist
|
|
33
35
|
*/
|
|
34
|
-
function loadPackageJson(basePath =
|
|
36
|
+
function loadPackageJson(basePath = process.cwd()) {
|
|
35
37
|
const packageJsonFileObject = composeFilename(basePath, "./package.json")
|
|
36
38
|
if(fileExists(packageJsonFileObject)) {
|
|
37
39
|
const jsonContent = readFile(packageJsonFileObject)
|
|
38
|
-
const json =
|
|
40
|
+
const json = JSON5.parse(jsonContent)
|
|
39
41
|
return json
|
|
40
42
|
} else
|
|
41
43
|
return null
|
package/src/core/util/FDUtil.js
CHANGED
|
@@ -256,7 +256,7 @@ async function getFiles(globPattern) {
|
|
|
256
256
|
!globbyArray.length
|
|
257
257
|
)
|
|
258
258
|
throw new Error(
|
|
259
|
-
|
|
259
|
+
`Invalid glob pattern: Array must contain only strings. Got ${JSON.stringify(globPattern)}`,
|
|
260
260
|
)
|
|
261
261
|
|
|
262
262
|
// Use Globby to fetch matching files
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {createRequire} from "module"
|
|
2
2
|
import FDUtil from "./FDUtil.js"
|
|
3
|
+
import JSON5 from "json5"
|
|
3
4
|
|
|
4
5
|
export default class ModuleUtil {
|
|
5
6
|
/**
|
|
@@ -21,7 +22,7 @@ export default class ModuleUtil {
|
|
|
21
22
|
static async loadJson(jsonFileObject) {
|
|
22
23
|
// Read the file
|
|
23
24
|
const jsonContent = await FDUtil.readFile(jsonFileObject)
|
|
24
|
-
const json =
|
|
25
|
+
const json = JSON5.parse(jsonContent)
|
|
25
26
|
return json
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -33,7 +34,7 @@ export default class ModuleUtil {
|
|
|
33
34
|
static async loadPackageJson() {
|
|
34
35
|
const packageJsonFileObject = FDUtil.resolveFilename("./package.json")
|
|
35
36
|
const jsonContent = await FDUtil.readFile(packageJsonFileObject)
|
|
36
|
-
const json =
|
|
37
|
+
const json = JSON5.parse(jsonContent)
|
|
37
38
|
return json
|
|
38
39
|
}
|
|
39
40
|
}
|