@gesslar/bedoc 1.3.1 → 1.4.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.
@@ -1,4 +1,4 @@
1
- import { Environment } from './Core';
1
+ import { EnvironmentType } from './Core';
2
2
 
3
3
  interface ConfigurationOption {
4
4
  value: unknown;
@@ -11,7 +11,7 @@ interface ConfigurationOptions {
11
11
 
12
12
  interface ValidateParams {
13
13
  options: ConfigurationOptions;
14
- source: typeof Environment;
14
+ source: EnvironmentType;
15
15
  }
16
16
 
17
17
  interface ValidationResult {
@@ -10,6 +10,14 @@ interface LoggerOptions {
10
10
  type LogLevel = 'debug' | 'warn' | 'info' | 'error';
11
11
  type DebugLevel = 0 | 1 | 2 | 3 | 4;
12
12
 
13
+ export declare const loggerColours: {
14
+ debug: string[];
15
+ info: string;
16
+ warn: string;
17
+ error: string;
18
+ reset: string;
19
+ };
20
+
13
21
  /**
14
22
  * Logger class
15
23
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gesslar/bedoc",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "Pluggable documentation engine for any language and format",
5
5
  "publisher": "gesslar",
6
6
  "main": "./src/core/Core.js",
package/src/cli.js CHANGED
@@ -75,6 +75,11 @@ const {resolveDirectory} = FDUtil
75
75
  const filesToProcess = bedoc.options.input.map(f => f.absolutePath)
76
76
  const result = await bedoc.processFiles(filesToProcess)
77
77
  const errored = result.errored
78
+ const warned = result.warned
79
+
80
+ if(warned.length > 0)
81
+ warned.forEach(w => bedoc.logger.warn(w.warning))
82
+
78
83
  if(errored.length > 0)
79
84
  throw new AggregateError(errored.map(e => e.error), "Error processing files")
80
85
  } catch(error) {
@@ -6,6 +6,7 @@ const {readFile, writeFile, composeFilename} = FDUtil
6
6
 
7
7
  export default class Conveyor {
8
8
  #succeeded = []
9
+ #warned = []
9
10
  #errored = []
10
11
 
11
12
  constructor(parse, print, logger, output) {
@@ -33,8 +34,10 @@ export default class Conveyor {
33
34
  const slot = Promise.race(semaphore) // Wait for an available slot
34
35
  semaphore.push(slot.then(async() => {
35
36
  const result = await this.#processFile(file)
36
- if(result.status === "success" || result.status === "warning")
37
+ if(result.status === "success")
37
38
  this.#succeeded.push({input: file, output: result.file})
39
+ else if(result.status === "warning")
40
+ this.#warned.push({input: file, warning: result.warning})
38
41
  else {
39
42
  this.#errored.push({input: file, error: result.error})
40
43
  }
@@ -49,7 +52,11 @@ export default class Conveyor {
49
52
  await this.parse.cleanupAction()
50
53
  await this.print.cleanupAction()
51
54
 
52
- return {succeeded: this.#succeeded, errored: this.#errored}
55
+ return {
56
+ succeeded: this.#succeeded,
57
+ errored: this.#errored,
58
+ warned: this.#warned
59
+ }
53
60
  }
54
61
 
55
62
  /**
@@ -78,7 +85,15 @@ export default class Conveyor {
78
85
  if(parseResult.status === "error")
79
86
  return parseResult
80
87
 
81
- debug("Parsed file successfully: `%s`", 2, file.path)
88
+ if(parseResult.status === "warning")
89
+ debug("Parsed file successfully, but with warnings: `%s`", 2, file.path)
90
+ else
91
+ debug("Parsed file successfully: `%s`", 2, file.path)
92
+
93
+ if(!parseResult.result?.functions?.length) {
94
+ const mess = format("No functions found in `%s`. No file written.", file.path)
95
+ return {status: "warning", file, warning: mess}
96
+ }
82
97
 
83
98
  // Step 3: Print file
84
99
  const printResult = await print.runAction({
package/src/core/Core.js CHANGED
@@ -2,7 +2,7 @@ import process from "node:process"
2
2
 
3
3
  import Discovery from "./Discovery.js"
4
4
  import HookManager from "./HookManager.js"
5
- import Logger from "./Logger.js"
5
+ import Logger, {loggerColours} from "./Logger.js"
6
6
  import ParseManager from "./action/ParseManager.js"
7
7
  import PrintManager from "./action/PrintManager.js"
8
8
  import Conveyor from "./Conveyor.js"
@@ -149,11 +149,21 @@ export default class Core {
149
149
 
150
150
  // Grab the results
151
151
  const totalFiles = input.length
152
- const errored = result.errored
153
152
  const succeeded = result.succeeded
153
+ const warned = result.warned
154
+ const errored = result.errored
155
+
156
+ const {
157
+ info: succeedColour, warn: warnColour, error: errorColour, reset
158
+ } = loggerColours
159
+
160
+
161
+ const success = `${succeedColour}${succeeded.length}${reset}`
162
+ const warn = `${warnColour}${warned.length}${reset}`
163
+ const error = `${errorColour}${errored.length}${reset}`
154
164
 
155
- const message = `Processed ${totalFiles} files: ${succeeded.length} succeeded, ${errored.length} errored ` +
156
- `in ${processEnd}ms [total: ${endTime}ms]`
165
+ const message = `Processed ${totalFiles} files: ${success} succeeded, ${error} errored, ` +
166
+ `${warn} warned in ${processEnd}ms [total: ${endTime}ms]`
157
167
 
158
168
  this.logger.debug(message, 1)
159
169
 
@@ -33,7 +33,7 @@ import * as StringUtil from "./util/StringUtil.js"
33
33
  const {resolveFilename} = FDUtil
34
34
  const {capitalize} = StringUtil
35
35
 
36
- const loggerColours = {
36
+ export const loggerColours = {
37
37
  debug: [
38
38
  "\x1b[38;5;19m", // Debug level 0: Dark blue
39
39
  "\x1b[38;5;27m", // Debug level 1: Medium blue