bajo 0.3.2 → 0.3.4
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/import-module.js +9 -2
- package/boot/helper/parse-object.js +3 -2
- package/boot/helper/start-plugin.js +2 -3
- package/boot/plugins/build-config.js +4 -18
- package/boot/plugins/collect-exit-handlers.js +1 -2
- 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,9 +1,9 @@
|
|
|
1
1
|
import resolvePath from './resolve-path.js'
|
|
2
|
-
import { isFunction, isPlainObject } from 'lodash-es'
|
|
2
|
+
import { isFunction, isPlainObject, get } from 'lodash-es'
|
|
3
3
|
import error from './error.js'
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
|
|
6
|
-
async function load (file, asDefaultImport = true, noCache =
|
|
6
|
+
async function load (file, asDefaultImport = true, noCache = true) {
|
|
7
7
|
file = resolvePath(file, true)
|
|
8
8
|
if (noCache) file += `?_=${Date.now()}`
|
|
9
9
|
const imported = await import(file)
|
|
@@ -12,6 +12,13 @@ async function load (file, asDefaultImport = true, noCache = false) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
async function importModule (file, { asDefaultImport, asHandler, noCache } = {}) {
|
|
15
|
+
if (file.includes(':')) {
|
|
16
|
+
const [plugin, path] = file.split(':')
|
|
17
|
+
if (plugin.length > 1) {
|
|
18
|
+
const dir = get(this[plugin], 'config.dir.pkg')
|
|
19
|
+
file = `${dir}${path}`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
if (!fs.existsSync(file)) return
|
|
16
23
|
let mod = await load(file, asDefaultImport, noCache)
|
|
17
24
|
if (!asHandler) return mod
|
|
@@ -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]
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
async function startPlugin (name, ...args) {
|
|
2
|
-
const {
|
|
3
|
-
const
|
|
4
|
-
const start = await importModule(`${cfg.dir.pkg}/bajo/start.js`)
|
|
2
|
+
const { importModule } = this.bajo.helper
|
|
3
|
+
const start = await importModule(`${name}:/bajo/start.js`)
|
|
5
4
|
await start.call(this, ...args)
|
|
6
5
|
}
|
|
7
6
|
|
|
@@ -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
|
|
|
@@ -7,8 +7,7 @@ async function collectExitHandlers () {
|
|
|
7
7
|
this.bajo.exitHandler = this.bajo.exitHandler ?? {}
|
|
8
8
|
const names = []
|
|
9
9
|
await eachPlugins(async function ({ plugin, dir }) {
|
|
10
|
-
const
|
|
11
|
-
const mod = await importModule(file)
|
|
10
|
+
const mod = await importModule(`${dir}/bajo/exit.js`)
|
|
12
11
|
if (!mod) return undefined
|
|
13
12
|
this.bajo.exitHandler[plugin] = mod
|
|
14
13
|
names.push(plugin)
|
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']
|
|
@@ -8,8 +8,7 @@ async function run ({ singles }) {
|
|
|
8
8
|
for (const f of methods) {
|
|
9
9
|
await runHook(`bajo:${camelCase(`before ${f} all plugins`)}`)
|
|
10
10
|
await eachPlugins(async function ({ plugin, dir }) {
|
|
11
|
-
const
|
|
12
|
-
const mod = await importModule(file)
|
|
11
|
+
const mod = await importModule(`${dir}/bajo/${f}.js`)
|
|
13
12
|
if (mod) {
|
|
14
13
|
log.debug('%s: %s', print.__(upperFirst(f)), plugin)
|
|
15
14
|
await runHook(`bajo:${camelCase(`before ${f} ${plugin}`)}`)
|
|
@@ -22,9 +21,6 @@ async function run ({ singles }) {
|
|
|
22
21
|
await runHook(`bajo:${camelCase(`after ${f} all plugins`)}`)
|
|
23
22
|
}
|
|
24
23
|
log.debug('Loaded plugins: %s', map(config.plugins, b => camelCase(b)).join(', '))
|
|
25
|
-
if (singles.length > 0) {
|
|
26
|
-
log.warn('Unloaded \'single\' plugins: %s', map(singles, s => camelCase(s)).join(', '))
|
|
27
|
-
}
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
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.4",
|
|
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"
|