@gesslar/bedoc 1.6.0 → 1.6.1

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 CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@gesslar/bedoc",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Pluggable documentation engine for any language and format",
5
5
  "publisher": "gesslar",
6
+ "author": "gesslar",
7
+ "license": "Unlicense",
6
8
  "main": "./src/core/Core.js",
7
9
  "repository": {
8
10
  "type": "git",
@@ -63,19 +65,5 @@
63
65
  "language",
64
66
  "format",
65
67
  "hooks"
66
- ],
67
- "author": "gesslar",
68
- "license": "Unlicense",
69
- "contributes": {
70
- "commands": [
71
- {
72
- "command": "vscode-bedoc.generateDocs",
73
- "title": "BeDoc: Generate Documentation"
74
- }
75
- ]
76
- },
77
- "extensionKind": [
78
- "workspace",
79
- "ui"
80
68
  ]
81
69
  }
package/src/cli.js CHANGED
@@ -72,6 +72,7 @@ const {resolveDirectory} = FDUtil
72
72
  },
73
73
  source: Environment.CLI
74
74
  })
75
+
75
76
  const filesToProcess = bedoc.options.input.map(f => f.absolutePath)
76
77
  const result = await bedoc.processFiles(filesToProcess)
77
78
  const errored = result.errored
@@ -42,7 +42,9 @@ export default class Configuration {
42
42
  )
43
43
 
44
44
  const allOptions = this.#findAllOptions(options)
45
+
45
46
  Object.assign(finalOptions, await this.#mergeOptions(allOptions))
47
+
46
48
  this.#fixOptionValues(finalOptions)
47
49
 
48
50
  // Priority keys are those which must be processed first. They are
@@ -79,6 +81,12 @@ export default class Configuration {
79
81
  )
80
82
  }
81
83
 
84
+ // Check for mandatory values
85
+ for(const [key, {required}] of Object.entries(ConfigurationParameters)) {
86
+ if(required && !orderedSections.find(s => s.key === key))
87
+ throw new SyntaxError(`Missing mandatory key \`${key}\``)
88
+ }
89
+
82
90
  for(const section of orderedSections) {
83
91
  const {key} = section
84
92
 
@@ -213,7 +221,6 @@ export default class Configuration {
213
221
  */
214
222
  #findAllOptions(entryOptions) {
215
223
  const allOptions = []
216
-
217
224
  const environmentVariables = this.#getEnvironmentVariables()
218
225
  if(environmentVariables)
219
226
  allOptions.push({source: "environment", options: environmentVariables})
package/src/core/Core.js CHANGED
@@ -45,11 +45,9 @@ export default class Core {
45
45
  debug("Creating new BeDoc instance with options: `%o`", 2, validConfig)
46
46
 
47
47
  const discovery = new Discovery(instance)
48
- const {printer: validPrint, parser: validParse} = validConfig
49
-
50
48
  const actionDefs = await discovery.discoverActions({
51
- print: validPrint,
52
- parse: validParse
49
+ print: validConfig.printer,
50
+ parse: validConfig.parser
53
51
  })
54
52
 
55
53
  const validCrit = discovery.satisfyCriteria(actionDefs, validConfig)
@@ -97,7 +95,7 @@ export default class Core {
97
95
  for(const [, value] of Object.entries(finalActions)) {
98
96
  const {action: actionType} = value.action.meta
99
97
 
100
- debug("Attaching `%o` action to instance", 2, actionType)
98
+ debug("Attaching %o action to instance", 2, actionType)
101
99
  instance.actions[actionType] = new managers[actionType](
102
100
  value, instance.logger
103
101
  )
@@ -34,6 +34,8 @@ export default class Discovery {
34
34
 
35
35
  debug("Discovering actions", 2)
36
36
 
37
+ debug("Specific modules provided: %o", 2, specific)
38
+
37
39
  const bucket = []
38
40
  const options = this.core.options ?? {}
39
41
 
@@ -53,7 +55,7 @@ export default class Discovery {
53
55
  if(this.core.packageJson?.modules) {
54
56
  const actions = this.core.packageJson?.modules
55
57
 
56
- debug("Found %d actions in package.json", 3, actions)
58
+ debug("Found %o actions in package.json", 3, actions)
57
59
  debug("Actions found in package.json action in package.json: %o", 3, actions)
58
60
 
59
61
  if(actions && typeof(actions) === "object")
@@ -70,7 +72,7 @@ export default class Discovery {
70
72
  execSync("npm root -g").toString().trim(),
71
73
  ]
72
74
 
73
- debug("Found %d directories to search for actions", 2, directories.length)
75
+ debug("Found %o directories to search for actions", 2, directories.length)
74
76
  debug("Directories to search for actions: %o", 3, directories)
75
77
 
76
78
  const moduleDirectories = directories
@@ -79,15 +81,15 @@ export default class Discovery {
79
81
  for(const moduleDirectory of moduleDirectories) {
80
82
  const {directories: dirs} = await ls(moduleDirectory.absolutePath)
81
83
 
82
- debug("Found %d directories in `%s`", 2,
84
+ debug("Found %o directories in `%s`", 2,
83
85
  dirs.length, moduleDirectory.absolutePath
84
86
  )
85
87
 
86
88
  const bedocDirs = dirs.filter(d => d.name.startsWith("bedoc-"))
87
- debug("Found %d bedoc directories under %s", 2, bedocDirs.length, moduleDirectory.absolutePath)
89
+ debug("Found %o bedoc directories under %s", 2, bedocDirs.length, moduleDirectory.absolutePath)
88
90
 
89
91
  const exports = bedocDirs.map(d => this.#getModuleExports(d))
90
- debug("Found %d module exports under %s", 2, exports.length, moduleDirectory.absolutePath)
92
+ debug("Found %o module exports under %s", 2, exports.length, moduleDirectory.absolutePath)
91
93
 
92
94
  bucket.push(...exports.flat())
93
95
  }
@@ -127,34 +129,35 @@ export default class Discovery {
127
129
  * respective contracts.
128
130
  *
129
131
  * @param {object[]} moduleFiles The module file objects to process
130
- * @param {object} specific The specific actions to load
132
+ * @param {object} specificModules The specific modules to load
131
133
  * @returns {Promise<object>} The discovered action
132
134
  */
133
- async #loadActionsAndContracts(moduleFiles, specific) {
135
+ async #loadActionsAndContracts(moduleFiles, specificModules) {
134
136
  const debug = this.#debug
135
137
 
136
138
  debug("Loading actions and contracts", 2)
137
139
  debug("Loading %d module files", 2, moduleFiles.length)
138
- debug("Specific actions to load: %o", 2, specific)
140
+ debug("Specific modules to load: %o", 2, specificModules)
139
141
 
140
142
  const resultActions = {}
141
143
  actionTypes.forEach(actionType => (resultActions[actionType] = []))
142
144
 
143
145
  // Tag the specific actions to load, so we can filter them later
144
- for(const [type, file] of Object.entries(specific)) {
146
+ for(const [type, file] of Object.entries(specificModules)) {
145
147
  if(file) {
146
- debug("Tagging specific action `%s` as `%s`", 3, file.absolutePath, type)
147
- file.specificType = type
148
+ debug("Tagging specific module `%s` as `%s`", 3, file.absolutePath, type)
149
+ file.specificType = file.specificType || []
150
+ file.specificType.push(type)
148
151
  }
149
152
  }
150
153
 
151
154
  const toLoad = [
152
155
  ...moduleFiles,
153
- ...Object.values(specific).filter(Boolean),
156
+ ...Object.values(specificModules).filter(Boolean),
154
157
  ]
155
158
 
156
- debug("Loading %d combined actions", 2, toLoad.length)
157
- debug("Actions to load: %o", 3, toLoad)
159
+ debug("Loading %d discovered modules", 2, toLoad.length)
160
+ debug("Modules to load: %o", 3, toLoad)
158
161
 
159
162
  const loadedActions = []
160
163
  for(const file of toLoad) {
@@ -170,19 +173,21 @@ export default class Discovery {
170
173
  }
171
174
 
172
175
  debug("Loaded %d actions", 2, loadedActions.length)
176
+ debug("Loaded actions", 3, loadedActions)
173
177
 
174
- const filtered = []
178
+ const filteredActions = []
175
179
  for(const actionType of actionTypes) {
176
- const file = specific[actionType]
180
+ const module = specificModules[actionType]
177
181
  const matchingActions = []
178
- if(file) {
179
- debug("Filtering actions for specific `%s`", 2, actionType)
182
+ if(module) {
183
+ debug("Filtering actions for specific: %o", 2, actionType)
180
184
  const found = loadedActions.find(
181
- e => e.file.absolutePath === file.absolutePath
185
+ e => e.file.specificType?.includes(actionType) &&
186
+ e.action.meta?.action === actionType
182
187
  )
183
188
 
184
189
  if(!found)
185
- throw new Error(`Could not find specific action: ${file.absolutePath}`)
190
+ throw new Error(`Could not find specific action: ${module.absolutePath}`)
186
191
 
187
192
  matchingActions.push(found)
188
193
  } else {
@@ -198,15 +203,17 @@ export default class Discovery {
198
203
  matchingActions.length, actionType
199
204
  )
200
205
 
201
- filtered.push(...matchingActions)
206
+ filteredActions.push(...matchingActions)
202
207
  }
203
208
 
204
- debug("Filtered %d actions", 2, filtered.length)
209
+ debug("Filtered %d actions", 2, filteredActions.length)
210
+ debug("Filtered actions %o", 3, filteredActions)
205
211
 
206
212
  // Now check the metas for validity
207
- for(const e of filtered) {
208
- const {action, contract, file: moduleFile} = e
213
+ for(const filtered of filteredActions) {
214
+ const {action, contract, file: moduleFile} = filtered
209
215
  const meta = action.meta
216
+
210
217
  if(!meta)
211
218
  throw new TypeError("Action has no meta object:\n" +
212
219
  JSON.stringify(moduleFile, null, 2) + "\n" +
@@ -222,7 +229,7 @@ export default class Discovery {
222
229
 
223
230
  const isValid = this.#validMeta(metaAction, {action, contract})
224
231
 
225
- debug("Action `%o` in `%s` is %s", 3,
232
+ debug("Meta in action %o in %o is %o", 3,
226
233
  metaAction, moduleFile.module, isValid ? "valid" : "invalid"
227
234
  )
228
235
 
@@ -239,7 +246,7 @@ export default class Discovery {
239
246
 
240
247
  for(const actionType of actionTypes) {
241
248
  const total = resultActions[actionType].length
242
- debug("Found %d `%s` actions", 2, total, actionType)
249
+ debug("Found %o `%o` actions", 2, total, actionType)
243
250
  }
244
251
 
245
252
  const total = Object.keys(resultActions).reduce((acc, curr) => {
@@ -255,6 +262,9 @@ export default class Discovery {
255
262
 
256
263
  satisfyCriteria(actions, validatedConfig) {
257
264
  const debug = this.#debug
265
+
266
+ debug("Available actions to check %o", 3, actions)
267
+
258
268
  const satisfied = {parse: [], print: []}
259
269
  const toMatch = {
260
270
  parse: {criterion: "language", config: "parser"},
@@ -272,10 +282,10 @@ export default class Discovery {
272
282
  if(validatedConfig[config]) {
273
283
  debug("Checking for specific `%s` action", 3, actionType)
274
284
  const found = actions[actionType].find(
275
- a => a.file.specificType === actionType
285
+ a => a.file.specificType.includes(actionType)
276
286
  )
277
287
  if(found) {
278
- debug("Found specific `%s` action", 3, actionType)
288
+ debug("Found specific %o action", 3, actionType)
279
289
  satisfied[actionType].push(found)
280
290
  continue
281
291
  }
@@ -283,7 +293,6 @@ export default class Discovery {
283
293
  debug("No specific `%s` action found", 3, actionType)
284
294
  }
285
295
 
286
-
287
296
  // Hmm! We didn't find anything specific. Let's check the criterion
288
297
  debug("Checking for `%s` actions with criterion `%s`", 3, actionType, criterion)
289
298
  debug("Validated config to check against: %o", 3, validatedConfig)
@@ -293,7 +302,7 @@ export default class Discovery {
293
302
  return a.action.meta[criterion] === validatedConfig[criterion]
294
303
  })
295
304
 
296
- debug("Found %d `%s` actions with criterion `%s`", 3,
305
+ debug("Found %o %o actions with criterion %o", 3,
297
306
  found.length, actionType, criterion
298
307
  )
299
308