bajo 2.12.0 → 2.12.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/class/bajo.js +23 -13
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
package/class/bajo.js
CHANGED
|
@@ -852,32 +852,42 @@ class Bajo extends Plugin {
|
|
|
852
852
|
const { parseObject } = this.app.lib
|
|
853
853
|
const { defaultsDeep } = this.app.lib.aneka
|
|
854
854
|
const { uniq, isString, isArray, findIndex, isPlainObject } = this.app.lib._
|
|
855
|
-
let { ns, baseNs, extend, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
855
|
+
let { ns, baseNs, extend, checkOverride, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
856
|
+
|
|
857
|
+
const getParseOptsArgs = (opts, orig) => {
|
|
858
|
+
opts.parserOpts = opts.parserOpts ?? {}
|
|
859
|
+
opts.parserOpts.args = opts.parserOpts.args ?? []
|
|
860
|
+
const idx = findIndex(opts.parserOpts.args, item => {
|
|
861
|
+
return isPlainObject(item) && Object.keys(item)[0] === '_orig'
|
|
862
|
+
})
|
|
863
|
+
if (idx > -1) opts.parserOpts.args[idx] = { _orig: orig }
|
|
864
|
+
else opts.parserOpts.args.push({ _orig: orig })
|
|
865
|
+
}
|
|
856
866
|
|
|
857
867
|
const output = async (obj) => {
|
|
858
|
-
|
|
868
|
+
let orig = parseObject(obj)
|
|
859
869
|
if (!baseNs || extend === false) return orig
|
|
860
870
|
const { suffix = '', keys = [] } = options
|
|
861
871
|
let bases = this.app.getAllNs()
|
|
862
872
|
if (isString(extend)) extend = extend.split(',').map(i => i.trim)
|
|
863
873
|
if (isArray(extend)) bases = [...extend, 'main']
|
|
864
874
|
bases = uniq(bases)
|
|
865
|
-
let ext = isArray(
|
|
875
|
+
let ext = isArray(orig) ? [] : {}
|
|
866
876
|
const dir = this.app[ns].dir.pkg
|
|
867
877
|
let [names, _path] = file.split(':')
|
|
868
878
|
if (file.slice(0, names.length + 1) !== `${ns}:`) _path = file.slice(dir.length + 1)
|
|
869
879
|
if (_path.startsWith('extend/')) _path = _path.slice(7)
|
|
870
880
|
if (_path.startsWith(`${baseNs}/`)) _path = _path.slice(baseNs.length + 1)
|
|
871
881
|
_path = _path.slice(0, -(path.extname(_path).length)) + '.*'
|
|
882
|
+
// check for override? Override only exists in main plugin
|
|
872
883
|
const opts = omit(options, ['suffix', 'keys', 'extend'])
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
884
|
+
if (checkOverride) {
|
|
885
|
+
getParseOptsArgs(opts, orig)
|
|
886
|
+
const fileExt = `${this.app.main.dir.pkg}/extend/${baseNs}/override/${ns}${suffix}/${_path}`
|
|
887
|
+
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, checkOverride: false }))
|
|
888
|
+
if (!isEmpty(result)) orig = result
|
|
889
|
+
}
|
|
890
|
+
getParseOptsArgs(opts, orig)
|
|
881
891
|
for (const base of bases) {
|
|
882
892
|
if (!this.app[base]) continue
|
|
883
893
|
const fileExt = `${this.app[base].dir.pkg}/extend/${baseNs}/extend/${ns}${suffix}/${_path}`
|
|
@@ -983,13 +993,13 @@ class Bajo extends Plugin {
|
|
|
983
993
|
let ext = {}
|
|
984
994
|
// default config file
|
|
985
995
|
try {
|
|
986
|
-
cfg = await this.readConfig(`${path}
|
|
996
|
+
cfg = await this.readConfig(`${path}.*`)
|
|
987
997
|
} catch (err) {
|
|
988
998
|
if (['BAJO_CONFIG_NO_PARSER'].includes(err.code)) throw err
|
|
989
999
|
}
|
|
990
1000
|
// env based config file
|
|
991
1001
|
try {
|
|
992
|
-
ext = await this.readConfig(`${path}-${this.config.env}
|
|
1002
|
+
ext = await this.readConfig(`${path}-${this.config.env}.*`)
|
|
993
1003
|
} catch (err) {
|
|
994
1004
|
if (!['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) throw err
|
|
995
1005
|
}
|
package/package.json
CHANGED