bajo 0.3.5 → 0.3.6
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/boot/helper/build-collections.js +2 -2
- package/boot/helper/join.js +11 -0
- package/boot/lib/logger.js +0 -1
- package/boot/plugins/check-dependency.js +2 -2
- package/boot/plugins/collect-config-handlers.js +2 -2
- package/boot/plugins/collect-exit-handlers.js +2 -2
- package/boot/plugins/run.js +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { filter, isArray, each, pullAt, camelCase, has, find, set, get, cloneDeep } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
async function buildCollections (options = {}) {
|
|
4
|
-
const { getConfig, getPluginName, fatal, runHook, error } = this.bajo.helper
|
|
4
|
+
const { getConfig, getPluginName, fatal, runHook, error, join } = this.bajo.helper
|
|
5
5
|
let { plugin, handler, dupChecks = [], container = 'connections', useDefaultName } = options
|
|
6
6
|
useDefaultName = useDefaultName ?? true
|
|
7
7
|
if (!plugin) plugin = getPluginName(4)
|
|
@@ -32,7 +32,7 @@ async function buildCollections (options = {}) {
|
|
|
32
32
|
each(dupChecks, d => {
|
|
33
33
|
const checker = set({}, d, c[d])
|
|
34
34
|
const match = filter(data, checker)
|
|
35
|
-
if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container,
|
|
35
|
+
if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, join(dupChecks))
|
|
36
36
|
})
|
|
37
37
|
})
|
|
38
38
|
await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isPlainObject } from 'lodash-es'
|
|
2
|
+
import isSet from './is-set.js'
|
|
3
|
+
|
|
4
|
+
const join = (array, sep) => {
|
|
5
|
+
if (isSet(sep) && !isPlainObject(sep)) return array.join(sep)
|
|
6
|
+
const { separator = ', ', joiner = 'and' } = sep ?? {}
|
|
7
|
+
const last = (array.pop() ?? '').trim()
|
|
8
|
+
return array.map(a => (a + '').trim()).join(separator) + ` ${joiner} ${last}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default join
|
package/boot/lib/logger.js
CHANGED
|
@@ -58,7 +58,6 @@ class Log {
|
|
|
58
58
|
text = JSON.stringify(json)
|
|
59
59
|
} else {
|
|
60
60
|
text = `[${dayjs(dt).utc(true).format(this.format)}] ${upperFirst(level)}: ${msg}`
|
|
61
|
-
// if (!isEmpty(data)) text += '\n ' + (pretty.render(data, prettyOpts).split('\n').join('\n '))
|
|
62
61
|
if (!isEmpty(data)) text += '\n' + JSON.stringify(data)
|
|
63
62
|
}
|
|
64
63
|
console.log(text)
|
|
@@ -2,7 +2,7 @@ import { reduce, map, trim, keys, intersection, each, camelCase, get } from 'lod
|
|
|
2
2
|
import semver from 'semver'
|
|
3
3
|
|
|
4
4
|
async function runner ({ plugin, pkg, dependencies }) {
|
|
5
|
-
const { log, getConfig, error } = this.bajo.helper
|
|
5
|
+
const { log, getConfig, error, join } = this.bajo.helper
|
|
6
6
|
log.trace('Checking dependencies: %s', plugin)
|
|
7
7
|
const config = getConfig()
|
|
8
8
|
const odep = reduce(dependencies, (o, k) => {
|
|
@@ -13,7 +13,7 @@ async function runner ({ plugin, pkg, dependencies }) {
|
|
|
13
13
|
const deps = keys(odep)
|
|
14
14
|
if (deps.length > 0) {
|
|
15
15
|
if (intersection(config.plugins, deps).length !== deps.length) {
|
|
16
|
-
throw error('Dependency for \'%s\' unfulfilled: %s', pkg,
|
|
16
|
+
throw error('Dependency for \'%s\' unfulfilled: %s', pkg, join(deps), { code: 'BAJO_DEPENDENCY' })
|
|
17
17
|
}
|
|
18
18
|
each(deps, d => {
|
|
19
19
|
if (!odep[d]) return
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isFunction, isPlainObject, map } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
async function collectConfigHandlers (pkg) {
|
|
4
|
-
const { getModuleDir, importModule, log } = this.bajo.helper
|
|
4
|
+
const { getModuleDir, importModule, log, join } = this.bajo.helper
|
|
5
5
|
for (const pkg of this.bajo.config.plugins) {
|
|
6
6
|
let dir
|
|
7
7
|
try {
|
|
@@ -16,7 +16,7 @@ async function collectConfigHandlers (pkg) {
|
|
|
16
16
|
this.bajo.configHandlers.concat(mod)
|
|
17
17
|
}
|
|
18
18
|
const exts = map(this.bajo.configHandlers, 'ext')
|
|
19
|
-
log.trace('Config handlers: %s',
|
|
19
|
+
log.trace('Config handlers: %s', join(exts))
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export default collectConfigHandlers
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {} from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
async function collectExitHandlers () {
|
|
4
|
-
const { importModule, log, eachPlugins, getConfig, print } = this.bajo.helper
|
|
4
|
+
const { importModule, log, eachPlugins, getConfig, print, join } = this.bajo.helper
|
|
5
5
|
const config = getConfig()
|
|
6
6
|
if (!config.exitHandler) return
|
|
7
7
|
this.bajo.exitHandler = this.bajo.exitHandler ?? {}
|
|
@@ -12,7 +12,7 @@ async function collectExitHandlers () {
|
|
|
12
12
|
this.bajo.exitHandler[plugin] = mod
|
|
13
13
|
names.push(plugin)
|
|
14
14
|
})
|
|
15
|
-
log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') :
|
|
15
|
+
log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') : join(names))
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export default collectExitHandlers
|
package/boot/plugins/run.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { set, get, camelCase, upperFirst, map } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
async function run () {
|
|
4
|
-
const { runHook, log, eachPlugins, importModule, freeze, getConfig, print } = this.bajo.helper
|
|
4
|
+
const { runHook, log, eachPlugins, importModule, freeze, getConfig, print, join } = this.bajo.helper
|
|
5
5
|
const config = getConfig()
|
|
6
6
|
const methods = ['init']
|
|
7
7
|
if (!get(config, 'tool')) methods.push('start')
|
|
@@ -20,7 +20,7 @@ async function run () {
|
|
|
20
20
|
})
|
|
21
21
|
await runHook(`bajo:${camelCase(`after ${f} all plugins`)}`)
|
|
22
22
|
}
|
|
23
|
-
log.debug('Loaded plugins: %s', map(config.plugins, b => camelCase(b))
|
|
23
|
+
log.debug('Loaded plugins: %s', join(map(config.plugins, b => camelCase(b))))
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export default run
|