bajo 2.9.0 → 2.10.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/class/bajo.js CHANGED
@@ -57,19 +57,13 @@ class Bajo extends Plugin {
57
57
  this.config = {}
58
58
 
59
59
  app.configHandlers = [
60
- { ext: '.js', readHandler: this._defConfigHandler },
60
+ { ext: '.js', readHandler: this.fromJs },
61
61
  { ext: '.json', readHandler: this.fromJson, writeHandler: this.toJson }
62
62
  ]
63
63
 
64
64
  this.hooks = []
65
65
  }
66
66
 
67
- async _defConfigHandler (file, opts = {}) {
68
- let mod = await importModule(file)
69
- if (isFunction(mod)) mod = await mod.call(this, opts)
70
- return mod
71
- }
72
-
73
67
  /**
74
68
  * Initialization:
75
69
  *
@@ -852,9 +846,9 @@ class Bajo extends Plugin {
852
846
  * @param {Object} [options.opts={}] - Parser setting
853
847
  * @returns {Object}
854
848
  */
855
- readConfig = async (file, { ns, pattern, globOptions = {}, ignoreError, defValue = {}, opts = {} } = {}) => {
849
+ readConfig = async (file, { ns, pattern, ignoreError = true, defValue = {}, options = {} } = {}) => {
856
850
  const { parseObject } = this.app.lib
857
- opts.readFromFile = true
851
+ options.readFromFile = true
858
852
  if (!ns) ns = this.ns
859
853
  file = resolvePath(this.getPluginFile(file))
860
854
  let ext = path.extname(file)
@@ -862,19 +856,19 @@ class Bajo extends Plugin {
862
856
  ext = ext.toLowerCase()
863
857
  if (ext === '.js') {
864
858
  const { readHandler } = find(this.app.configHandlers, { ext })
865
- return parseObject(await readHandler.call(this.app[ns], file, opts))
859
+ return parseObject(await readHandler.call(this.app[ns], file, options))
866
860
  }
867
- if (ext === '.json') return await this.fromJson(file, opts)
861
+ if (ext === '.json') return await this.fromJson(file, options)
868
862
  if (!['', '.*'].includes(ext)) {
869
863
  const item = find(this.app.configHandlers, { ext })
870
864
  if (!item) {
871
865
  if (!ignoreError) throw this.error('cantParse%s', file, { code: 'BAJO_CONFIG_NO_PARSER' })
872
866
  return parseObject(defValue)
873
867
  }
874
- return parseObject(await item.readHandler.call(this.app[ns], file, opts))
868
+ return parseObject(await item.readHandler.call(this.app[ns], file, options))
875
869
  }
876
870
  const item = pattern ?? `${fname}.{${map(map(this.app.configHandlers, 'ext'), k => k.slice(1)).join(',')}}`
877
- const files = await fastGlob(item, globOptions)
871
+ const files = await fastGlob(item, options.glob ?? {})
878
872
  if (files.length === 0) {
879
873
  if (!ignoreError) throw this.error('noConfigFileFound', { code: 'BAJO_CONFIG_FILE_NOT_FOUND' })
880
874
  return parseObject(defValue)
@@ -887,7 +881,7 @@ class Bajo extends Plugin {
887
881
  if (!ignoreError) throw this.error('cantParse%s', f, { code: 'BAJO_CONFIG_NO_PARSER' })
888
882
  continue
889
883
  }
890
- config = await item.readHandler.call(this.app[ns], f, opts)
884
+ config = await item.readHandler.call(this.app[ns], f, options)
891
885
  if (!isEmpty(config)) break
892
886
  }
893
887
  return parseObject(config)
@@ -913,15 +907,22 @@ class Bajo extends Plugin {
913
907
  return parseObject(JSON.parse(resp))
914
908
  }
915
909
 
916
- fromJson (data, opts = {}) {
917
- const content = opts.readFromFile ? fs.readFileSync(data, 'utf8') : data
910
+ fromJs = async (file, options = {}) => {
911
+ const args = options.args ?? []
912
+ let mod = await importModule(file)
913
+ if (isFunction(mod)) mod = await mod.call(this, ...args)
914
+ return mod
915
+ }
916
+
917
+ fromJson (data, options = {}) {
918
+ const content = options.readFromFile ? fs.readFileSync(data, 'utf8') : data
918
919
  return JSON.parse(content)
919
920
  }
920
921
 
921
- toJson = (data, opts = {}) => {
922
- const content = JSON.stringify(data, null, omit(opts, ['writeToFile']))
923
- if (opts.writeToFile) {
924
- fs.writeFileSync(opts.saveAsFile, content, 'utf8')
922
+ toJson = (data, options = {}) => {
923
+ const content = JSON.stringify(data, null, omit(options, ['writeToFile']))
924
+ if (options.writeToFile) {
925
+ fs.writeFileSync(options.saveAsFile, content, 'utf8')
925
926
  return
926
927
  }
927
928
  return content
@@ -162,7 +162,6 @@ export async function run () {
162
162
  await runHook(`bajo:${camelCase(`before all ${method}`)}`)
163
163
  await eachPlugins(async function () {
164
164
  const { ns } = this
165
- if (method === 'start') freeze(me[ns].config)
166
165
  /**
167
166
  * Run before ```{method}``` is executed within ```{ns}``` context
168
167
  *
@@ -186,6 +185,7 @@ export async function run () {
186
185
  * @see module:Helper/Base.run
187
186
  */
188
187
  await runHook(`${ns}:${camelCase(`after ${method}`)}`)
188
+ if (method === 'start') freeze(me[ns].config)
189
189
  })
190
190
  /**
191
191
  * Run after all ```{method}``` executed. Accepted ```{method}```: ```Init``` or ```Start```
@@ -229,12 +229,12 @@ class Print extends Tools {
229
229
  */
230
230
  fatal = (text, ...args) => {
231
231
  if (text instanceof Error) {
232
+ console.error(text)
232
233
  text = text.message
233
234
  args = []
234
235
  }
235
236
  this.setText(text, ...args)
236
237
  this.ora.fail()
237
- if (text instanceof Error && this.app.bajo.config.log.level === 'trace') console.error(text)
238
238
  this.app.exit()
239
239
  }
240
240
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "The ultimate framework for whipping up massive apps in no time",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-30
4
+
5
+ - [2.10.0] Add ability to pass options of ```configHandlers``` with type ```.js```
6
+ - [2.10.0] Freezing config object now occurs ```{ns}:afterStart()```
7
+ - [2.10.0] Bug fix on ```print.fatal()``` when argument is an Error object
8
+
3
9
  ## 2026-03-25
4
10
 
5
11
  - [2.9.0] Add ```dump()``` now available through out plugins