bajo 0.3.1 → 0.3.2
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, cloneDeep } from 'lodash-es'
|
|
1
|
+
import { filter, isArray, each, pullAt, camelCase, has, find, set, get, cloneDeep } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
async function buildCollections (options = {}) {
|
|
4
4
|
const { getConfig, getPluginName, fatal, runHook, error } = this.bajo.helper
|
|
@@ -7,36 +7,37 @@ async function buildCollections (options = {}) {
|
|
|
7
7
|
if (!plugin) plugin = getPluginName(4)
|
|
8
8
|
const config = getConfig()
|
|
9
9
|
const cfg = getConfig(plugin, { full: true })
|
|
10
|
-
|
|
11
|
-
if (!
|
|
12
|
-
|
|
10
|
+
let data = get(cfg, container)
|
|
11
|
+
if (!data) return []
|
|
12
|
+
if (!isArray(data)) data = [data]
|
|
13
13
|
await runHook(`${plugin}:${camelCase(`before build ${container}`)}`)
|
|
14
14
|
const deleted = []
|
|
15
|
-
for (const index in
|
|
16
|
-
const item =
|
|
15
|
+
for (const index in data) {
|
|
16
|
+
const item = data[index]
|
|
17
17
|
if (useDefaultName) {
|
|
18
18
|
if (!has(item, 'name')) {
|
|
19
|
-
if (find(
|
|
19
|
+
if (find(data, { name: 'default' })) throw error('Connection \'default\' already exists')
|
|
20
20
|
else item.name = 'default'
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
const result = await handler.call(this, { item, index, cfg })
|
|
24
|
-
if (result)
|
|
24
|
+
if (result) data[index] = result
|
|
25
25
|
else if (result === false) deleted.push(index)
|
|
26
26
|
if (config.tool && item.skipOnTool && !deleted.includes(index)) deleted.push(index)
|
|
27
27
|
}
|
|
28
|
-
if (deleted.length > 0) pullAt(
|
|
28
|
+
if (deleted.length > 0) pullAt(data, deleted)
|
|
29
29
|
|
|
30
30
|
// check for duplicity
|
|
31
|
-
each(
|
|
31
|
+
each(data, c => {
|
|
32
32
|
each(dupChecks, d => {
|
|
33
33
|
const checker = set({}, d, c[d])
|
|
34
|
-
const match = filter(
|
|
34
|
+
const match = filter(data, checker)
|
|
35
35
|
if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, dupChecks.join(', '))
|
|
36
36
|
})
|
|
37
37
|
})
|
|
38
38
|
await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
|
|
39
|
-
|
|
39
|
+
set(cfg, container, data)
|
|
40
|
+
return cloneDeep(data)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export default buildCollections
|
package/boot/helper/pick.js
CHANGED
|
@@ -2,11 +2,11 @@ import isSet from './is-set.js'
|
|
|
2
2
|
|
|
3
3
|
function pick (obj, items, excludeUnset) {
|
|
4
4
|
const result = {}
|
|
5
|
-
|
|
5
|
+
for (const item of items) {
|
|
6
6
|
const [k, nk] = item.split(':')
|
|
7
|
-
if (excludeUnset && !isSet(obj[k]))
|
|
7
|
+
if (excludeUnset && !isSet(obj[k])) continue
|
|
8
8
|
result[nk ?? k] = obj[k]
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
return result
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
async function startPlugin (name,
|
|
1
|
+
async function startPlugin (name, ...args) {
|
|
2
2
|
const { getConfig, importModule } = this.bajo.helper
|
|
3
3
|
const cfg = getConfig(name, { full: true })
|
|
4
4
|
const start = await importModule(`${cfg.dir.pkg}/bajo/start.js`)
|
|
5
|
-
await start.call(this,
|
|
5
|
+
await start.call(this, ...args)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export default startPlugin
|
package/boot/plugins/run.js
CHANGED
|
@@ -13,8 +13,7 @@ async function run ({ singles }) {
|
|
|
13
13
|
if (mod) {
|
|
14
14
|
log.debug('%s: %s', print.__(upperFirst(f)), plugin)
|
|
15
15
|
await runHook(`bajo:${camelCase(`before ${f} ${plugin}`)}`)
|
|
16
|
-
|
|
17
|
-
await mod.call(this, ...params)
|
|
16
|
+
await mod.call(this)
|
|
18
17
|
await runHook(`bajo:${camelCase(`after ${f} ${plugin}`)}`)
|
|
19
18
|
}
|
|
20
19
|
if (f === 'init') freeze(this[plugin].config)
|