bajo 0.2.18 → 0.2.20
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 { filter, isArray, each, pullAt, camelCase, has, find, set } from 'lodash-es'
|
|
1
|
+
import { filter, isArray, each, pullAt, camelCase, has, find, set, cloneDeep } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
async function buildCollections (options = {}) {
|
|
4
4
|
const { getConfig, getPluginName, fatal, runHook, error } = this.bajo.helper
|
|
@@ -34,7 +34,7 @@ async function buildCollections (options = {}) {
|
|
|
34
34
|
})
|
|
35
35
|
})
|
|
36
36
|
await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
|
|
37
|
-
return cfg[container]
|
|
37
|
+
return cloneDeep(cfg[container])
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export default buildCollections
|
package/boot/lib/build-helper.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fastGlob from 'fast-glob'
|
|
2
|
+
import path from 'path'
|
|
2
3
|
import { camelCase, isFunction, isPlainObject, forOwn } from 'lodash-es'
|
|
3
4
|
import resolvePath from '../helper/resolve-path.js'
|
|
4
5
|
import importModule from '../helper/import-module.js'
|
|
6
|
+
import readJson from '../helper/read-json.js'
|
|
5
7
|
|
|
6
8
|
function stackInfo (name, ...args) {
|
|
7
9
|
const { log, callsites } = this.bajo.helper
|
|
@@ -32,13 +34,16 @@ const wrapAsyncFn = function (name, handler, bind) {
|
|
|
32
34
|
|
|
33
35
|
export default async function (dir, pkg = 'bajo') {
|
|
34
36
|
dir = resolvePath(dir)
|
|
35
|
-
const files = await fastGlob([`!${dir}/**/_*.js`, `${dir}/**/*.js`])
|
|
37
|
+
const files = await fastGlob([`!${dir}/**/_*.{js,json}`, `${dir}/**/*.{js,json}`])
|
|
36
38
|
const helper = {}
|
|
37
39
|
for (const f of files) {
|
|
38
|
-
const
|
|
40
|
+
const ext = path.extname()
|
|
41
|
+
const base = f.replace(dir, '').replace(ext, '')
|
|
39
42
|
const name = camelCase(base)
|
|
40
43
|
const fnName = pkg + '.' + name
|
|
41
|
-
let mod
|
|
44
|
+
let mod
|
|
45
|
+
if (ext === '.json') mod = readJson(f)
|
|
46
|
+
else await importModule(f)
|
|
42
47
|
if (isFunction(mod)) {
|
|
43
48
|
if (mod.constructor.name === 'AsyncFunction') mod = wrapAsyncFn.call(this, fnName, mod, true)
|
|
44
49
|
else mod = wrapFn.call(this, fnName, mod, true)
|