@gesslar/bedoc 1.4.7 → 1.4.10
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/dist/types/core/ActionManager.d.ts +3 -1
- package/dist/types/core/HookManager.d.ts +1 -2
- package/package.json +1 -1
- package/src/core/Configuration.js +6 -6
- package/src/core/Conveyor.js +1 -1
- package/src/core/Discovery.js +7 -4
- package/src/core/HookManager.js +1 -1
- package/src/core/util/DataUtil.js +3 -3
- package/src/core/util/FDUtil.js +24 -8
- package/src/core/util/TypeSpec.js +4 -4
- package/tsconfig.json +0 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Logger from './Logger'
|
|
2
|
-
import HookManager from './HookManager'
|
|
2
|
+
import HookManager, {HookPoints} from './HookManager'
|
|
3
3
|
|
|
4
4
|
export type MetaActionType = "print" | "parse"
|
|
5
5
|
|
|
@@ -24,6 +24,8 @@ export interface ActionDefinition {
|
|
|
24
24
|
setup?: (params: { parent: ActionManager; log: Logger }) => void
|
|
25
25
|
run({ module, content }: { module: string; content: object }): Promise<string>
|
|
26
26
|
hook?: (event: string, ...args: unknown[]) => Promise<unknown>
|
|
27
|
+
|
|
28
|
+
HOOKS?: HookPoints
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export interface PrintActionDefinition extends ActionDefinition {
|
|
@@ -27,7 +27,7 @@ interface HookManagerConstructorParams {
|
|
|
27
27
|
timeOut: number;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export const
|
|
30
|
+
export const HookPoints: Readonly<Record<Uppercase<HookEventType>, HookEventType>>;
|
|
31
31
|
|
|
32
32
|
export default class HookManager {
|
|
33
33
|
static new(arg: HookManagerConstructorParams): Promise<HookManager | null>;
|
|
@@ -51,7 +51,6 @@ export default class HookManager {
|
|
|
51
51
|
*/
|
|
52
52
|
on(event: HookEventType, ...args: unknown[]): Promise<HookResult | undefined>;
|
|
53
53
|
|
|
54
|
-
HOOKS?: HookPoints
|
|
55
54
|
#hooksFile: FileMap | null;
|
|
56
55
|
#log: Logger | null;
|
|
57
56
|
#hooks: HooksDefinition | null;
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@ export default class Configuration {
|
|
|
49
49
|
// Find them and add them to an array; the rest will be in pushed to the
|
|
50
50
|
// end of the priority array.
|
|
51
51
|
const orderedSections = []
|
|
52
|
-
ConfigurationPriorityKeys.forEach(
|
|
52
|
+
ConfigurationPriorityKeys.forEach(key => {
|
|
53
53
|
if(!ConfigurationParameters[key])
|
|
54
54
|
throw new Error(`Invalid priority key: ${key}`)
|
|
55
55
|
|
|
@@ -58,10 +58,10 @@ export default class Configuration {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
const remainingSections = Object.keys(ConfigurationParameters).filter(
|
|
61
|
-
|
|
61
|
+
key => !ConfigurationPriorityKeys.includes(key),
|
|
62
62
|
)
|
|
63
63
|
orderedSections.push(
|
|
64
|
-
...remainingSections.map(
|
|
64
|
+
...remainingSections.map(key => {
|
|
65
65
|
return {key, value: finalOptions[key]}
|
|
66
66
|
}),
|
|
67
67
|
)
|
|
@@ -106,7 +106,7 @@ export default class Configuration {
|
|
|
106
106
|
if(key === "input" || key === "exclude") {
|
|
107
107
|
if(isType(value, "array"))
|
|
108
108
|
value = await Promise.all(
|
|
109
|
-
value.map(
|
|
109
|
+
value.map(pattern => getFiles(pattern)),
|
|
110
110
|
)
|
|
111
111
|
else if(isType(value, "string"))
|
|
112
112
|
value = await getFiles(value)
|
|
@@ -251,7 +251,7 @@ export default class Configuration {
|
|
|
251
251
|
*/
|
|
252
252
|
#getEnvironmentVariables() {
|
|
253
253
|
const environmentVariables = {}
|
|
254
|
-
const params = Object.keys(ConfigurationParameters).map(
|
|
254
|
+
const params = Object.keys(ConfigurationParameters).map(param => {
|
|
255
255
|
return {
|
|
256
256
|
param,
|
|
257
257
|
env: `bedoc_${param}`.toUpperCase(),
|
|
@@ -280,7 +280,7 @@ export default class Configuration {
|
|
|
280
280
|
const nonEntryOptions = allOptions.filter(
|
|
281
281
|
option => option.source && option.source !== "entry",
|
|
282
282
|
)
|
|
283
|
-
const optionsOnly = nonEntryOptions.map(
|
|
283
|
+
const optionsOnly = nonEntryOptions.map(option => option.options)
|
|
284
284
|
const mergedOptions = optionsOnly.reduce((acc, options) => {
|
|
285
285
|
for(const [key, value] of Object.entries(options)) acc[key] = value
|
|
286
286
|
|
package/src/core/Conveyor.js
CHANGED
|
@@ -107,7 +107,7 @@ export default class Conveyor {
|
|
|
107
107
|
|
|
108
108
|
// Step 4: Write output
|
|
109
109
|
const {status: printStatus, destFile, content} = printResult
|
|
110
|
-
const isNullish =
|
|
110
|
+
const isNullish = value => value == null // Checks null or undefined
|
|
111
111
|
|
|
112
112
|
if(printStatus !== "success" || isNullish(destFile) || isNullish(content)) {
|
|
113
113
|
return {status: "error", file, error: new Error("Invalid print result")}
|
package/src/core/Discovery.js
CHANGED
|
@@ -5,8 +5,9 @@ import {execSync} from "child_process"
|
|
|
5
5
|
import * as FDUtil from "./util/FDUtil.js"
|
|
6
6
|
import * as ActionUtil from "./util/ActionUtil.js"
|
|
7
7
|
import * as DataUtil from "./util/DataUtil.js"
|
|
8
|
+
import {composeDirectory,directoryExists} from "./util/FDUtil.js"
|
|
8
9
|
|
|
9
|
-
const {ls,
|
|
10
|
+
const {ls,resolveFilename,getFiles} = FDUtil
|
|
10
11
|
const {actionTypes, actionMetaRequirements, loadJson} = ActionUtil
|
|
11
12
|
const {isType} = DataUtil
|
|
12
13
|
|
|
@@ -72,7 +73,9 @@ export default class Discovery {
|
|
|
72
73
|
debug("Found %d directories to search for actions", 2, directories.length)
|
|
73
74
|
debug("Directories to search for actions: %o", 3, directories)
|
|
74
75
|
|
|
75
|
-
const moduleDirectories = directories
|
|
76
|
+
const moduleDirectories = directories
|
|
77
|
+
.map(composeDirectory)
|
|
78
|
+
.filter(directoryExists)
|
|
76
79
|
for(const moduleDirectory of moduleDirectories) {
|
|
77
80
|
const {directories: dirs} = await ls(moduleDirectory.absolutePath)
|
|
78
81
|
|
|
@@ -310,9 +313,9 @@ export default class Discovery {
|
|
|
310
313
|
async #loadModule(module) {
|
|
311
314
|
const debug = this.#debug
|
|
312
315
|
|
|
313
|
-
debug("Loading module `%j`", 2, module)
|
|
316
|
+
debug("2 Loading module `%j`", 2, module)
|
|
314
317
|
|
|
315
|
-
const {absoluteUri} = module
|
|
318
|
+
const {absolutePath: absoluteUri} = module
|
|
316
319
|
const moduleExports = await import(absoluteUri)
|
|
317
320
|
|
|
318
321
|
return {file: module, ...moduleExports}
|
package/src/core/HookManager.js
CHANGED
|
@@ -10,7 +10,7 @@ const freeze = Object.freeze
|
|
|
10
10
|
const hookEvents = freeze(["start", "section_load", "enter", "exit", "end"])
|
|
11
11
|
export const HookPoints = freeze(
|
|
12
12
|
await allocateObject(
|
|
13
|
-
hookEvents.map(
|
|
13
|
+
hookEvents.map(event => event.toUpperCase()),
|
|
14
14
|
hookEvents,
|
|
15
15
|
),
|
|
16
16
|
)
|
|
@@ -38,7 +38,7 @@ const constructors = [
|
|
|
38
38
|
"Float64Array",
|
|
39
39
|
]
|
|
40
40
|
|
|
41
|
-
const dataTypes = [...primitives, ...constructors.map(
|
|
41
|
+
const dataTypes = [...primitives, ...constructors.map(c => c.toLowerCase())]
|
|
42
42
|
|
|
43
43
|
const emptyableTypes = ["string", "array", "object"]
|
|
44
44
|
|
|
@@ -96,7 +96,7 @@ function isArrayUnique(arr) {
|
|
|
96
96
|
* @returns {Array} The intersection of the two arrays.
|
|
97
97
|
*/
|
|
98
98
|
function arrayIntersection(arr1, arr2) {
|
|
99
|
-
return arr1.filter(
|
|
99
|
+
return arr1.filter(value => arr2.includes(value))
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
@@ -390,7 +390,7 @@ function deepFreezeObject(obj) {
|
|
|
390
390
|
* @returns {boolean} - True if valid, throws an error otherwise.
|
|
391
391
|
*/
|
|
392
392
|
function schemaCompare(schema, definition, stack = [], logger = new Logger()) {
|
|
393
|
-
const breadcrumb =
|
|
393
|
+
const breadcrumb = key => (stack.length ? `@${stack.join(".")}` : key)
|
|
394
394
|
const tag = "[DataUtil.schemaCompare]"
|
|
395
395
|
const pad = `${" ".repeat(stack.length * 2)}${stack.length ? "└─ " : ""}`
|
|
396
396
|
const debug = (message, key) =>
|
package/src/core/util/FDUtil.js
CHANGED
|
@@ -10,10 +10,10 @@ import * as ValidUtil from "./ValidUtil.js"
|
|
|
10
10
|
const {isArrayUniform, isType, allocateObject} = DataUtil
|
|
11
11
|
const {validType} = ValidUtil
|
|
12
12
|
|
|
13
|
-
const freeze =
|
|
13
|
+
const freeze = ob => Object.freeze(ob)
|
|
14
14
|
|
|
15
15
|
const fdTypes = freeze(["file", "directory"])
|
|
16
|
-
const upperFdTypes = freeze(fdTypes.map(
|
|
16
|
+
const upperFdTypes = freeze(fdTypes.map(type => type.toUpperCase()))
|
|
17
17
|
const fdType = freeze(await allocateObject(upperFdTypes, fdTypes))
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -67,7 +67,7 @@ function canWriteFile(FileMap) {
|
|
|
67
67
|
try {
|
|
68
68
|
fs.accessSync(FileMap.absolutePath, fs.constants.W_OK)
|
|
69
69
|
return true
|
|
70
|
-
} catch(
|
|
70
|
+
} catch(_error) {
|
|
71
71
|
return false
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -82,7 +82,22 @@ function fileExists(FileMap) {
|
|
|
82
82
|
try {
|
|
83
83
|
fs.accessSync(FileMap.absolutePath)
|
|
84
84
|
return true
|
|
85
|
-
} catch(
|
|
85
|
+
} catch(_error) {
|
|
86
|
+
return false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check if a directory exists
|
|
92
|
+
*
|
|
93
|
+
* @param {object} DirectoryMap - The directory map to check
|
|
94
|
+
* @returns {boolean} Whether the directory exists
|
|
95
|
+
*/
|
|
96
|
+
function directoryExists(DirectoryMap) {
|
|
97
|
+
try {
|
|
98
|
+
fs.accessSync(DirectoryMap.absolutePath)
|
|
99
|
+
return true
|
|
100
|
+
} catch(_error) {
|
|
86
101
|
return false
|
|
87
102
|
}
|
|
88
103
|
}
|
|
@@ -231,9 +246,9 @@ async function getFiles(globPattern) {
|
|
|
231
246
|
? globPattern
|
|
232
247
|
: globPattern
|
|
233
248
|
.split("|")
|
|
234
|
-
.map(
|
|
249
|
+
.map(g => g.trim())
|
|
235
250
|
.filter(Boolean)
|
|
236
|
-
).map(
|
|
251
|
+
).map(g => fixSlashes(g))
|
|
237
252
|
|
|
238
253
|
if(
|
|
239
254
|
Array.isArray(globbyArray) &&
|
|
@@ -246,7 +261,7 @@ async function getFiles(globPattern) {
|
|
|
246
261
|
|
|
247
262
|
// Use Globby to fetch matching files
|
|
248
263
|
const filesArray = await globby(globbyArray)
|
|
249
|
-
const files = filesArray.map(
|
|
264
|
+
const files = filesArray.map(file => mapFilename(file))
|
|
250
265
|
|
|
251
266
|
// Flatten the result and remove duplicates
|
|
252
267
|
return files
|
|
@@ -297,7 +312,7 @@ function composeDirectory(directory) {
|
|
|
297
312
|
async function ls(directory) {
|
|
298
313
|
const found = await fs.promises.readdir(directory, {withFileTypes: true})
|
|
299
314
|
const results = await Promise.all(
|
|
300
|
-
found.map(async
|
|
315
|
+
found.map(async dirent => {
|
|
301
316
|
const fullPath = path.join(directory, dirent.name)
|
|
302
317
|
const stat = await fs.promises.stat(fullPath)
|
|
303
318
|
return {dirent, stat, fullPath}
|
|
@@ -357,6 +372,7 @@ export {
|
|
|
357
372
|
composeDirectory,
|
|
358
373
|
composeFilename,
|
|
359
374
|
deconstructFilenameToParts,
|
|
375
|
+
directoryExists,
|
|
360
376
|
fileExists,
|
|
361
377
|
fixSlashes,
|
|
362
378
|
getFiles,
|
|
@@ -17,7 +17,7 @@ export default class TypeSpec {
|
|
|
17
17
|
|
|
18
18
|
toString() {
|
|
19
19
|
return this.#specs
|
|
20
|
-
.map(
|
|
20
|
+
.map(spec => {
|
|
21
21
|
return `${spec.typeName}${spec.array ? "[]" : ""}`
|
|
22
22
|
})
|
|
23
23
|
.join("|")
|
|
@@ -61,7 +61,7 @@ export default class TypeSpec {
|
|
|
61
61
|
// If we have a list of types, because the string was validly parsed,
|
|
62
62
|
// we need to ensure that all of the types that were parsed are valid types
|
|
63
63
|
// in JavaScript.
|
|
64
|
-
if(this.length && !this.every(
|
|
64
|
+
if(this.length && !this.every(t => isValidType(t.typeName)))
|
|
65
65
|
return false
|
|
66
66
|
|
|
67
67
|
// Now, let's do some checking with the types, respecting the array flag
|
|
@@ -71,7 +71,7 @@ export default class TypeSpec {
|
|
|
71
71
|
|
|
72
72
|
// We need to ensure that we match the type and the consistency of the types
|
|
73
73
|
// in an array, if it is an array and an array is allowed.
|
|
74
|
-
const matchingTypeSpec = this.filter(
|
|
74
|
+
const matchingTypeSpec = this.filter(spec => {
|
|
75
75
|
const {typeName: allowedType, array: allowedArray} = spec
|
|
76
76
|
|
|
77
77
|
if(valueType === allowedType && !isArray && !allowedArray)
|
|
@@ -97,7 +97,7 @@ export default class TypeSpec {
|
|
|
97
97
|
const delimiter = options?.delimiter ?? "|"
|
|
98
98
|
const parts = string.split(delimiter)
|
|
99
99
|
|
|
100
|
-
this.#specs = parts.map(
|
|
100
|
+
this.#specs = parts.map(part => {
|
|
101
101
|
const typeMatches = /(\w+)(\[\])?/.exec(part)
|
|
102
102
|
if(!typeMatches || typeMatches.length !== 3)
|
|
103
103
|
throw new TypeError(`Invalid type: ${part}`)
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src/**/*.js"], // Match all .js files in the src/ directory
|
|
3
|
-
"exclude": ["node_modules"], // Ignore node_modules/ (but NOT src/)
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"target": "ES2022", // Modern JavaScript output
|
|
6
|
-
"allowJs": true, // Process .js files
|
|
7
|
-
"declaration": true, // Generate .d.ts files
|
|
8
|
-
"emitDeclarationOnly": true, // Only output .d.ts files
|
|
9
|
-
"declarationMap": true, // Generate .d.ts.map for IDE support
|
|
10
|
-
"module": "NodeNext", // Use ESM-compatible Node.js modules
|
|
11
|
-
"moduleResolution": "nodenext", // Resolve ESM imports properly
|
|
12
|
-
"rootDir": "src", // Base input directory
|
|
13
|
-
"outDir": "dist/types", // Emit .d.ts files to a separate directory
|
|
14
|
-
"strict": true, // Enable strict type-checking
|
|
15
|
-
"esModuleInterop": true, // Interoperability for CommonJS modules
|
|
16
|
-
"forceConsistentCasingInFileNames": true, // Avoid case-sensitive issues
|
|
17
|
-
"skipLibCheck": true, // Skip checking .d.ts files in node_modules/
|
|
18
|
-
"noEmitOnError": true // Prevent output if there are errors
|
|
19
|
-
}
|
|
20
|
-
}
|