bajo 0.3.1 → 0.3.3
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/attach-helper.js +2 -0
- package/boot/helper/build-collections.js +13 -12
- package/boot/helper/parse-object.js +3 -2
- package/boot/helper/pick.js +3 -3
- package/boot/helper/start-plugin.js +2 -2
- package/boot/plugins/build-config.js +4 -18
- package/boot/plugins/index.js +2 -3
- package/boot/plugins/run.js +2 -6
- package/package.json +1 -2
package/boot/attach-helper.js
CHANGED
|
@@ -7,6 +7,7 @@ import dayjs from './lib/dayjs.js'
|
|
|
7
7
|
import fs from 'fs-extra'
|
|
8
8
|
import fastGlob from 'fast-glob'
|
|
9
9
|
import { sprintf } from 'sprintf-js'
|
|
10
|
+
import outmatch from 'outmatch'
|
|
10
11
|
|
|
11
12
|
export default async function () {
|
|
12
13
|
this.bajo.helper = await buildHelper.call(this, `${currentLoc(import.meta).dir}/helper`)
|
|
@@ -27,6 +28,7 @@ export default async function () {
|
|
|
27
28
|
this.bajo.helper.fs = fs
|
|
28
29
|
this.bajo.helper.fastGlob = fastGlob
|
|
29
30
|
this.bajo.helper.sprintf = sprintf
|
|
31
|
+
this.bajo.helper.outmatch = outmatch
|
|
30
32
|
// last cleanup
|
|
31
33
|
this.bajo.helper.freeze(this.bajo.helper, true)
|
|
32
34
|
if (!fs.existsSync(this.bajo.config.dir.data)) {
|
|
@@ -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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPlainObject, isArray, isNumber, set } from 'lodash-es'
|
|
1
|
+
import { isPlainObject, isArray, isNumber, set, cloneDeep } from 'lodash-es'
|
|
2
2
|
import dotenvParseVariables from 'dotenv-parse-variables'
|
|
3
3
|
import ms from 'ms'
|
|
4
4
|
import dayjs from '../lib/dayjs.js'
|
|
@@ -16,7 +16,8 @@ function parseDt (val) {
|
|
|
16
16
|
return dt.toDate()
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function parseObject (
|
|
19
|
+
function parseObject (input, silent = true, parseValue = false) {
|
|
20
|
+
const obj = cloneDeep(input)
|
|
20
21
|
const keys = Object.keys(obj)
|
|
21
22
|
keys.forEach(k => {
|
|
22
23
|
const v = obj[k]
|
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
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { camelCase, pick, isString, omit
|
|
1
|
+
import { camelCase, pick, isString, omit } from 'lodash-es'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
|
-
import lockfile from 'proper-lockfile'
|
|
4
3
|
import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
|
|
5
4
|
import titleize from '../helper/titleize.js'
|
|
6
5
|
|
|
@@ -24,7 +23,7 @@ export async function readAllConfigs (base, name) {
|
|
|
24
23
|
return cfg
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
async function runner (pkg, {
|
|
26
|
+
async function runner (pkg, { argv, env }) {
|
|
28
27
|
const { log, getConfig, getModuleDir, readConfig, error, readJson, defaultsDeep } = this.bajo.helper
|
|
29
28
|
const config = getConfig()
|
|
30
29
|
const name = camelCase(pkg)
|
|
@@ -53,29 +52,16 @@ async function runner (pkg, { singles, argv, env }) {
|
|
|
53
52
|
cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {})
|
|
54
53
|
cfg.dependencies = cfg.dependencies ?? []
|
|
55
54
|
if (isString(cfg.dependencies)) cfg.dependencies = [cfg.dependencies]
|
|
56
|
-
if (cfg.single) {
|
|
57
|
-
const lockfileDir = `${config.dir.tmp}/lock`
|
|
58
|
-
const lockfilePath = `${lockfileDir}/${name}.lock`
|
|
59
|
-
fs.ensureDirSync(lockfileDir)
|
|
60
|
-
const file = `${dir}/package.json`
|
|
61
|
-
try {
|
|
62
|
-
await lockfile.lock(file, { lockfilePath })
|
|
63
|
-
} catch (err) {
|
|
64
|
-
singles.push(pkg)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
55
|
if (!this[name]) this[name] = {}
|
|
68
56
|
this[name].config = cfg
|
|
69
57
|
}
|
|
70
58
|
|
|
71
|
-
async function buildConfig ({
|
|
59
|
+
async function buildConfig ({ argv, env }) {
|
|
72
60
|
const { log, freeze } = this.bajo.helper
|
|
73
61
|
log.debug('Read configurations')
|
|
74
62
|
for (const pkg of this.bajo.config.plugins) {
|
|
75
|
-
await runner.call(this, pkg, {
|
|
63
|
+
await runner.call(this, pkg, { argv, env })
|
|
76
64
|
}
|
|
77
|
-
pull(this.bajo.config.plugins, ...singles)
|
|
78
|
-
each(singles, s => delete this[camelCase(s)])
|
|
79
65
|
freeze(this.bajo.config)
|
|
80
66
|
}
|
|
81
67
|
|
package/boot/plugins/index.js
CHANGED
|
@@ -11,17 +11,16 @@ import parseArgsArgv from '../lib/parse-args-argv.js'
|
|
|
11
11
|
import parseEnv from '../lib/parse-env.js'
|
|
12
12
|
|
|
13
13
|
async function bootBajos () {
|
|
14
|
-
const singles = []
|
|
15
14
|
const { argv } = await parseArgsArgv({ useParser: true }) ?? {}
|
|
16
15
|
const env = parseEnv() ?? {}
|
|
17
16
|
await collectConfigHandlers.call(this)
|
|
18
|
-
await buildConfig.call(this, {
|
|
17
|
+
await buildConfig.call(this, { argv, env })
|
|
19
18
|
await extendConfig.call(this)
|
|
20
19
|
await checkClash.call(this)
|
|
21
20
|
await checkDependency.call(this)
|
|
22
21
|
await attachHelper.call(this)
|
|
23
22
|
await collectHooks.call(this)
|
|
24
|
-
await run.call(this
|
|
23
|
+
await run.call(this)
|
|
25
24
|
await collectExitHandlers.call(this)
|
|
26
25
|
}
|
|
27
26
|
|
package/boot/plugins/run.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { set, get, camelCase, upperFirst, map } from 'lodash-es'
|
|
2
2
|
|
|
3
|
-
async function run (
|
|
3
|
+
async function run () {
|
|
4
4
|
const { runHook, log, eachPlugins, importModule, freeze, getConfig, print } = this.bajo.helper
|
|
5
5
|
const config = getConfig()
|
|
6
6
|
const methods = ['init']
|
|
@@ -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)
|
|
@@ -23,9 +22,6 @@ async function run ({ singles }) {
|
|
|
23
22
|
await runHook(`bajo:${camelCase(`after ${f} all plugins`)}`)
|
|
24
23
|
}
|
|
25
24
|
log.debug('Loaded plugins: %s', map(config.plugins, b => camelCase(b)).join(', '))
|
|
26
|
-
if (singles.length > 0) {
|
|
27
|
-
log.warn('Unloaded \'single\' plugins: %s', map(singles, s => camelCase(s)).join(', '))
|
|
28
|
-
}
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
export default run
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bajo",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A framework to build a giant monstrous app rapidly",
|
|
5
5
|
"main": "boot/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"omit-deep": "^0.3.0",
|
|
44
44
|
"ora": "^8.0.1",
|
|
45
45
|
"outmatch": "^0.7.0",
|
|
46
|
-
"proper-lockfile": "^4.1.2",
|
|
47
46
|
"semver": "^7.5.1",
|
|
48
47
|
"sprintf-js": "^1.1.2",
|
|
49
48
|
"yargs": "^17.7.2"
|