bajo 0.2.4 → 0.2.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import resolvePath from './resolve-path.js'
|
|
2
2
|
import { isFunction, isPlainObject } from 'lodash-es'
|
|
3
3
|
import error from './error.js'
|
|
4
|
+
import fs from 'fs-extra'
|
|
4
5
|
|
|
5
6
|
async function load (file, asDefaultImport = true) {
|
|
6
7
|
const imported = await import(resolvePath(file, true))
|
|
@@ -9,6 +10,7 @@ async function load (file, asDefaultImport = true) {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
async function importModule (file, { asDefaultImport, asHandler } = {}) {
|
|
13
|
+
if (!fs.existsSync(file)) return
|
|
12
14
|
let mod = await load(file, asDefaultImport)
|
|
13
15
|
if (!asHandler) return mod
|
|
14
16
|
if (isFunction(mod)) mod = { level: 999, handler: mod }
|
|
@@ -6,6 +6,7 @@ import dotenvParseVariables from 'dotenv-parse-variables'
|
|
|
6
6
|
import importModule from '../helper/import-module.js'
|
|
7
7
|
import { find, each, set, camelCase, forOwn } from 'lodash-es'
|
|
8
8
|
import fs from 'fs-extra'
|
|
9
|
+
import path from 'path'
|
|
9
10
|
import currentLoc from '../helper/current-loc.js'
|
|
10
11
|
|
|
11
12
|
const { unflatten } = flat
|
|
@@ -14,7 +15,7 @@ const parseItem = (data, delimiter) => {
|
|
|
14
15
|
return unflatten(data, {
|
|
15
16
|
delimiter,
|
|
16
17
|
safe: true,
|
|
17
|
-
overwrite: true
|
|
18
|
+
overwrite: true
|
|
18
19
|
})
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -28,10 +29,8 @@ const parseWithParser = async () => {
|
|
|
28
29
|
|
|
29
30
|
const parseWithYargs = async () => {
|
|
30
31
|
const parser = './app/bajo/argv-parser.js'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return await mod(yargs)
|
|
34
|
-
}
|
|
32
|
+
const mod = await importModule(parser)
|
|
33
|
+
if (mod) return await mod(yargs)
|
|
35
34
|
const pkg = fs.readJSONSync(`${currentLoc(import.meta).dir}/../../package.json`)
|
|
36
35
|
let name = `node ${pkg.main}`
|
|
37
36
|
if (pkg.bin) name = path.basename(pkg.bin, '.js')
|
|
@@ -47,7 +46,7 @@ const parseWithYargs = async () => {
|
|
|
47
46
|
.version().alias('version', 'v')
|
|
48
47
|
.help().alias('help', 'h')
|
|
49
48
|
.alias('tool', 't')
|
|
50
|
-
|
|
49
|
+
if (pkg.homepage) cli.epilog(`For more information please visit ${pkg.homepage}`)
|
|
51
50
|
return cli.argv
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isFunction, isPlainObject, map } from 'lodash-es'
|
|
2
|
-
import fs from 'fs-extra'
|
|
3
2
|
|
|
4
3
|
async function collectConfigHandlers (pkg) {
|
|
5
4
|
const { getModuleDir, importModule, log } = this.bajo.helper
|
|
@@ -10,13 +9,11 @@ async function collectConfigHandlers (pkg) {
|
|
|
10
9
|
} catch (err) {}
|
|
11
10
|
if (!dir) continue
|
|
12
11
|
const file = `${dir}/bajo/extend/read-config.js`
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.bajo.configHandlers.concat(mod)
|
|
19
|
-
} catch (err) {}
|
|
12
|
+
let mod = await importModule(file)
|
|
13
|
+
if (!mod) continue
|
|
14
|
+
if (isFunction(mod)) mod = await mod.call(this)
|
|
15
|
+
if (isPlainObject(mod)) mod = [mod]
|
|
16
|
+
this.bajo.configHandlers.concat(mod)
|
|
20
17
|
}
|
|
21
18
|
const exts = map(this.bajo.configHandlers, 'ext')
|
|
22
19
|
log.trace('Config handlers: %s', exts.join(', '))
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {} from 'lodash-es'
|
|
2
|
-
import fs from 'fs-extra'
|
|
3
2
|
|
|
4
3
|
async function collectExitHandlers () {
|
|
5
4
|
const { importModule, log, eachPlugins, getConfig, print } = this.bajo.helper
|
|
@@ -9,13 +8,10 @@ async function collectExitHandlers () {
|
|
|
9
8
|
const names = []
|
|
10
9
|
await eachPlugins(async function ({ plugin, dir }) {
|
|
11
10
|
const file = `${dir}/bajo/exit.js`
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
names.push(plugin)
|
|
17
|
-
} catch (err) {
|
|
18
|
-
}
|
|
11
|
+
const mod = await importModule(file)
|
|
12
|
+
if (!mod) return undefined
|
|
13
|
+
this.bajo.exitHandler[plugin] = mod
|
|
14
|
+
names.push(plugin)
|
|
19
15
|
})
|
|
20
16
|
log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') : names.join(', '))
|
|
21
17
|
}
|
package/boot/plugins/run.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { get, camelCase, upperFirst, map } from 'lodash-es'
|
|
2
|
-
import fs from 'fs-extra'
|
|
3
2
|
|
|
4
3
|
async function run ({ singles }) {
|
|
5
4
|
const { runHook, log, eachPlugins, importModule, freeze, getConfig, print } = this.bajo.helper
|
|
@@ -10,12 +9,12 @@ async function run ({ singles }) {
|
|
|
10
9
|
await runHook(`bajo:${camelCase(`before ${f} all plugins`)}`)
|
|
11
10
|
await eachPlugins(async function ({ plugin, dir }) {
|
|
12
11
|
const file = `${dir}/bajo/${f}.js`
|
|
13
|
-
|
|
12
|
+
const mod = await importModule(file)
|
|
13
|
+
if (mod) {
|
|
14
14
|
log.debug('%s: %s', print.__(upperFirst(f)), plugin)
|
|
15
15
|
await runHook(`bajo:${camelCase(`before ${f} ${plugin}`)}`)
|
|
16
|
-
const item = await importModule(file)
|
|
17
16
|
const params = f === 'start' ? ['all', true] : []
|
|
18
|
-
await
|
|
17
|
+
await mod.call(this, ...params)
|
|
19
18
|
await runHook(`bajo:${camelCase(`after ${f} ${plugin}`)}`)
|
|
20
19
|
}
|
|
21
20
|
if (f === 'init') freeze(this[plugin].config)
|