bajo 0.3.10 → 1.0.1
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/README.md +127 -26
- package/bajoI18N/resource/id.json +31 -0
- package/boot/class/app.js +69 -0
- package/boot/class/bajo-core/helper/attach-method.js +30 -0
- package/boot/{boot-order.js → class/bajo-core/helper/boot-order.js} +10 -10
- package/boot/class/bajo-core/helper/boot-plugins.js +19 -0
- package/boot/class/bajo-core/helper/build-config.js +61 -0
- package/boot/class/bajo-core/helper/build-plugins.js +26 -0
- package/boot/class/bajo-core/helper/collect-config-handlers.js +21 -0
- package/boot/{exit-handler.js → class/bajo-core/helper/exit-handler.js} +10 -16
- package/boot/class/bajo-core/helper/run-as-applet.js +26 -0
- package/boot/class/bajo-core/method/arrange-array.js +18 -0
- package/boot/class/bajo-core/method/break-ns-path-from-file.js +24 -0
- package/boot/class/bajo-core/method/break-ns-path.js +29 -0
- package/boot/class/bajo-core/method/build-collections.js +46 -0
- package/boot/class/bajo-core/method/call-handler.js +29 -0
- package/boot/{helper → class/bajo-core/method}/defaults-deep.js +1 -1
- package/boot/class/bajo-core/method/each-plugins.js +55 -0
- package/boot/class/bajo-core/method/envs.js +7 -0
- package/boot/{helper → class/bajo-core/method}/generate-id.js +4 -0
- package/boot/{helper → class/bajo-core/method}/get-global-module-dir.js +3 -4
- package/boot/class/bajo-core/method/get-method.js +10 -0
- package/boot/{helper → class/bajo-core/method}/get-module-dir.js +3 -4
- package/boot/{helper → class/bajo-core/method}/get-plugin-data-dir.js +2 -3
- package/boot/class/bajo-core/method/get-plugin-file.js +18 -0
- package/boot/class/bajo-core/method/get-plugin.js +23 -0
- package/boot/{helper → class/bajo-core/method}/import-module.js +4 -10
- package/boot/{helper → class/bajo-core/method}/import-pkg.js +9 -3
- package/boot/class/bajo-core/method/includes.js +13 -0
- package/boot/class/bajo-core/method/is-class.js +7 -0
- package/boot/{helper → class/bajo-core/method}/is-log-in-range.js +1 -1
- package/boot/{helper → class/bajo-core/method}/is-valid-app.js +2 -2
- package/boot/class/bajo-core/method/join.js +15 -0
- package/boot/class/bajo-core/method/log-levels.js +9 -0
- package/boot/class/bajo-core/method/num-unit.js +9 -0
- package/boot/{helper → class/bajo-core/method}/parse-object.js +24 -8
- package/boot/class/bajo-core/method/read-config.js +48 -0
- package/boot/{helper → class/bajo-core/method}/read-json.js +2 -2
- package/boot/class/bajo-core/method/run-hook.js +26 -0
- package/boot/{helper → class/bajo-core/method}/save-as-download.js +2 -2
- package/boot/class/bajo-core/method/slice-string.js +13 -0
- package/boot/class/bajo-core/method/titleize.js +23 -0
- package/boot/class/bajo-core.js +30 -0
- package/boot/class/bajo-plugin/helper/attach-method.js +14 -0
- package/boot/class/bajo-plugin/helper/build-config.js +10 -0
- package/boot/class/bajo-plugin/helper/check-clash.js +16 -0
- package/boot/class/bajo-plugin/helper/check-dependency.js +37 -0
- package/boot/class/bajo-plugin/helper/collect-exit-handlers.js +14 -0
- package/boot/class/bajo-plugin/helper/collect-hooks.js +29 -0
- package/boot/class/bajo-plugin/helper/run.js +20 -0
- package/boot/class/bajo-plugin.js +78 -0
- package/boot/class/error.js +59 -0
- package/boot/class/log.js +67 -0
- package/boot/class/plugin.js +51 -0
- package/boot/class/print.js +103 -0
- package/boot/index.js +4 -51
- package/boot/lib/create-method.js +30 -0
- package/boot/{helper → lib}/current-loc.js +1 -1
- package/boot/lib/omitted-plugin-keys.js +1 -1
- package/boot/lib/parse-args-argv.js +8 -11
- package/boot/lib/parse-env.js +7 -6
- package/boot/lib/read-all-configs.js +36 -0
- package/boot/lib/translate.js +18 -0
- package/docs/ecosystem.md +55 -0
- package/docs/hook.md +11 -0
- package/package.json +55 -56
- package/test/{helper-isSet.js → method/isSet.js} +6 -4
- package/waibuStatic/virtual.json +7 -0
- package/boot/attach-helper.js +0 -40
- package/boot/build-config.js +0 -99
- package/boot/create-scope.js +0 -36
- package/boot/helper/break-ns-path.js +0 -20
- package/boot/helper/build-collections.js +0 -43
- package/boot/helper/build-name.js +0 -17
- package/boot/helper/call-helper-or-handler.js +0 -15
- package/boot/helper/dump.js +0 -14
- package/boot/helper/each-plugins.js +0 -106
- package/boot/helper/envs.js +0 -14
- package/boot/helper/error.js +0 -77
- package/boot/helper/fatal.js +0 -13
- package/boot/helper/get-config.js +0 -19
- package/boot/helper/get-helper.js +0 -12
- package/boot/helper/get-item-by-name.js +0 -26
- package/boot/helper/get-plugin-file.js +0 -16
- package/boot/helper/get-plugin-name.js +0 -39
- package/boot/helper/get-plugin.js +0 -14
- package/boot/helper/join.js +0 -11
- package/boot/helper/log-levels.js +0 -19
- package/boot/helper/read-config.js +0 -48
- package/boot/helper/resolve-tpl-path.js +0 -15
- package/boot/helper/run-hook.js +0 -49
- package/boot/helper/spinner.js +0 -9
- package/boot/helper/start-plugin.js +0 -7
- package/boot/helper/titleize.js +0 -14
- package/boot/lib/build-helper.js +0 -60
- package/boot/lib/logger.js +0 -76
- package/boot/lib/print.js +0 -138
- package/boot/plugins/attach-helper.js +0 -20
- package/boot/plugins/build-config.js +0 -68
- package/boot/plugins/check-clash.js +0 -18
- package/boot/plugins/check-dependency.js +0 -37
- package/boot/plugins/collect-config-handlers.js +0 -22
- package/boot/plugins/collect-exit-handlers.js +0 -18
- package/boot/plugins/collect-hooks.js +0 -34
- package/boot/plugins/extend-config.js +0 -21
- package/boot/plugins/index.js +0 -27
- package/boot/plugins/run.js +0 -26
- package/boot/run-tool.js +0 -41
- package/docs/boot_build-config.js.html +0 -75
- package/docs/boot_create-scope.js.html +0 -25
- package/docs/boot_index.js.html +0 -43
- package/docs/data/search.json +0 -1
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/helper_emit.js.html +0 -18
- package/docs/helper_envs.js.html +0 -16
- package/docs/helper_error.js.html +0 -25
- package/docs/helper_get-bajo.js.html +0 -42
- package/docs/helper_index.js.html +0 -39
- package/docs/helper_log-levels.js.html +0 -20
- package/docs/helper_set-hook.js.html +0 -38
- package/docs/helper_walk-bajos.js.html +0 -51
- package/docs/index.html +0 -16
- package/docs/module-boot.html +0 -3
- package/docs/module-boot_buildConfig.html +0 -3
- package/docs/module-boot_createScope.html +0 -3
- package/docs/module-helper.html +0 -7
- package/docs/module-helper_setHook.html +0 -4
- package/docs/module-helper_walkBajos.html +0 -6
- package/docs/scripts/core.js +0 -655
- package/docs/scripts/core.min.js +0 -23
- package/docs/scripts/resize.js +0 -90
- package/docs/scripts/search.js +0 -265
- package/docs/scripts/search.min.js +0 -6
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -202
- package/docs/scripts/third-party/fuse.js +0 -9
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -369
- package/docs/scripts/third-party/hljs-line-num.js +0 -1
- package/docs/scripts/third-party/hljs-original.js +0 -5171
- package/docs/scripts/third-party/hljs.js +0 -1
- package/docs/scripts/third-party/popper.js +0 -5
- package/docs/scripts/third-party/tippy.js +0 -1
- package/docs/scripts/third-party/tocbot.js +0 -672
- package/docs/scripts/third-party/tocbot.min.js +0 -1
- package/docs/styles/clean-jsdoc-theme-base.css +0 -975
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -407
- package/docs/styles/clean-jsdoc-theme-light.css +0 -388
- package/docs/styles/clean-jsdoc-theme.min.css +0 -1
- package/test/helper-error.js +0 -25
- package/test/helper-pathResolve.js +0 -28
- /package/boot/{helper → class/bajo-core/method}/get-key-by-value.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/is-empty-dir.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/is-set.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/is-valid-plugin.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/paginate.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/pascal-case.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/pick.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/resolve-path.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/round.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/sec-to-hms.js +0 -0
- /package/boot/{helper → class/bajo-core/method}/white-space.js +0 -0
package/boot/lib/print.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import Sprintf from 'sprintf-js'
|
|
2
|
-
import ora from 'ora'
|
|
3
|
-
import { isPlainObject, get } from 'lodash-es'
|
|
4
|
-
import defaultsDeep from '../helper/defaults-deep.js'
|
|
5
|
-
|
|
6
|
-
const { sprintf } = Sprintf
|
|
7
|
-
|
|
8
|
-
export class Print {
|
|
9
|
-
constructor (opts = {}) {
|
|
10
|
-
this.opts = opts
|
|
11
|
-
this.startTime = null
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
setOpts (args = []) {
|
|
15
|
-
const { getConfig } = this.scope.bajo.helper
|
|
16
|
-
const config = getConfig()
|
|
17
|
-
let opts = {}
|
|
18
|
-
if (isPlainObject(args.slice(-1)[0])) opts = args.pop()
|
|
19
|
-
this.opts.isLog = !config.tool
|
|
20
|
-
if (this.opts.isLog) this.opts.isEnabled = false
|
|
21
|
-
this.opts.isSilent = !!(config.silent || this.opts.isSilent)
|
|
22
|
-
this.opts = defaultsDeep(opts, this.opts)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
setScope (scope) {
|
|
26
|
-
this.scope = scope
|
|
27
|
-
const { dayjs } = this.scope.bajo.helper
|
|
28
|
-
this.startTime = dayjs()
|
|
29
|
-
this.setOpts()
|
|
30
|
-
this.ora = ora(this.opts)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setText (text, ...args) {
|
|
34
|
-
const { dayjs } = this.scope.bajo.helper
|
|
35
|
-
text = this.__(text, ...args)
|
|
36
|
-
this.setOpts(args)
|
|
37
|
-
const prefixes = []
|
|
38
|
-
const texts = []
|
|
39
|
-
if (this.opts.showDatetime) prefixes.push('[' + dayjs().toISOString() + ']')
|
|
40
|
-
if (this.opts.showCounter) texts.push('[' + this.getElapsed() + ']')
|
|
41
|
-
if (prefixes.length > 0) this.ora.prefixText = this.ora.prefixText + prefixes.join(' ')
|
|
42
|
-
if (texts.length > 0) text = texts.join(' ') + ' ' + text
|
|
43
|
-
if (this.opts.isLog) this.info(text, ...args)
|
|
44
|
-
else this.ora.text = text
|
|
45
|
-
return this
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
__ (text, ...args) {
|
|
49
|
-
if (text) {
|
|
50
|
-
const i18n = get(this, 'scope.bajoI18N.instance')
|
|
51
|
-
if (i18n) {
|
|
52
|
-
if (isPlainObject(args[0])) text = i18n.t(text, args[0])
|
|
53
|
-
else text = i18n.t(text, { ns: this.ns, postProcess: 'sprintf', sprintf: args })
|
|
54
|
-
} else text = sprintf(text, ...args)
|
|
55
|
-
}
|
|
56
|
-
return text
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getElapsed (unit = 'hms') {
|
|
60
|
-
const { dayjs, secToHms } = this.scope.bajo.helper
|
|
61
|
-
const u = unit === 'hms' ? 'second' : unit
|
|
62
|
-
const elapsed = dayjs().diff(this.startTime, u)
|
|
63
|
-
return unit === 'hms' ? secToHms(elapsed) : elapsed
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
start (text, ...args) {
|
|
67
|
-
this.setOpts(args)
|
|
68
|
-
if (this.opts.isLog) {
|
|
69
|
-
this.ora.start()
|
|
70
|
-
this.info(text, ...args)
|
|
71
|
-
return this
|
|
72
|
-
}
|
|
73
|
-
this.setText(text, ...args)
|
|
74
|
-
this.ora.start()
|
|
75
|
-
return this
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
stop () {
|
|
79
|
-
this.ora.stop()
|
|
80
|
-
return this
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
succeed (text, ...args) {
|
|
84
|
-
const { log } = this.scope.bajo.helper
|
|
85
|
-
if (this.opts.isLog) return log.debug(text, ...args)
|
|
86
|
-
this.setText(text, ...args)
|
|
87
|
-
this.ora.succeed()
|
|
88
|
-
return this
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
fail (text, ...args) {
|
|
92
|
-
const { log } = this.scope.bajo.helper
|
|
93
|
-
if (this.opts.isLog) return log.error(text, ...args)
|
|
94
|
-
this.setText(text, ...args)
|
|
95
|
-
this.ora.fail()
|
|
96
|
-
return this
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
warn (text, ...args) {
|
|
100
|
-
const { log } = this.scope.bajo.helper
|
|
101
|
-
if (this.opts.isLog) return log.warn(text, ...args)
|
|
102
|
-
this.setText(text, ...args)
|
|
103
|
-
this.ora.warn()
|
|
104
|
-
return this
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
info (text, ...args) {
|
|
108
|
-
const { log } = this.scope.bajo.helper
|
|
109
|
-
if (this.opts.isLog) return log.debug(text, ...args)
|
|
110
|
-
this.setText(text, ...args)
|
|
111
|
-
this.ora.info()
|
|
112
|
-
return this
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
clear () {
|
|
116
|
-
this.ora.clear()
|
|
117
|
-
return this
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
render () {
|
|
121
|
-
this.ora.render()
|
|
122
|
-
return this
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
fatal (text, ...args) {
|
|
126
|
-
const { log } = this.scope.bajo.helper
|
|
127
|
-
if (this.opts.isLog) return log.fatal(text, ...args)
|
|
128
|
-
this.setText(text, ...args)
|
|
129
|
-
this.ora.fail()
|
|
130
|
-
process.kill(process.pid, 'SIGINT')
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export default function (options) {
|
|
135
|
-
const print = new Print(options)
|
|
136
|
-
print.setScope(this)
|
|
137
|
-
return print
|
|
138
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import buildHelper from '../lib/build-helper.js'
|
|
2
|
-
import { keys } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
async function runner (plugin, pkg) {
|
|
5
|
-
const { log, freeze } = this.bajo.helper
|
|
6
|
-
const dir = pkg === 'app' ? (this.bajo.config.dir.base + '/app') : this.bajo.helper.getModuleDir(pkg)
|
|
7
|
-
this[plugin].helper = await buildHelper.call(this, `${dir}/bajo/helper`, pkg)
|
|
8
|
-
freeze(this[plugin].helper, true)
|
|
9
|
-
log.trace('Attach helper: %s (%d)', plugin, keys(this[plugin].helper).length)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function attachHelper () {
|
|
13
|
-
const { log, eachPlugins } = this.bajo.helper
|
|
14
|
-
log.debug('Attach helpers')
|
|
15
|
-
await eachPlugins(async function ({ plugin, pkg }) {
|
|
16
|
-
await runner.call(this, plugin, pkg)
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default attachHelper
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { camelCase, pick, isString, omit } from 'lodash-es'
|
|
2
|
-
import fs from 'fs-extra'
|
|
3
|
-
import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
|
|
4
|
-
import titleize from '../helper/titleize.js'
|
|
5
|
-
|
|
6
|
-
export async function readAllConfigs (base, name) {
|
|
7
|
-
const { readConfig, getConfig } = this.bajo.helper
|
|
8
|
-
const config = getConfig()
|
|
9
|
-
let cfg = {}
|
|
10
|
-
try {
|
|
11
|
-
cfg = await readConfig(`${base}-${config.env}.*`)
|
|
12
|
-
} catch (err) {
|
|
13
|
-
if (['BAJO_CONFIG_NO_PARSER'].includes(err.code)) throw err
|
|
14
|
-
if (['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) {
|
|
15
|
-
try {
|
|
16
|
-
cfg = await readConfig(`${base}.*`)
|
|
17
|
-
} catch (err) {
|
|
18
|
-
if (!['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) throw err
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
cfg.name = name
|
|
23
|
-
return cfg
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function runner (pkg, { argv, env }) {
|
|
27
|
-
const { log, getConfig, getModuleDir, readConfig, error, readJson, defaultsDeep } = this.bajo.helper
|
|
28
|
-
const config = getConfig()
|
|
29
|
-
const name = camelCase(pkg)
|
|
30
|
-
log.trace('Read configuration: %s', name)
|
|
31
|
-
const dir = pkg === 'app' ? (config.dir.base + '/app') : getModuleDir(pkg)
|
|
32
|
-
if (pkg !== 'app' && !fs.existsSync(`${dir}/bajo`)) throw error('Package \'%s\' isn\'t a valid Bajo package', pkg, { code: 'BAJO_INVALID_PACKAGE' })
|
|
33
|
-
let cfg = await readAllConfigs.call(this, `${dir}/bajo/config`, name)
|
|
34
|
-
cfg.dir = {
|
|
35
|
-
pkg: dir,
|
|
36
|
-
data: `${config.dir.data}/plugins/${name}`
|
|
37
|
-
}
|
|
38
|
-
const pkgJson = await readJson(`${dir + (pkg === 'app' ? '/..' : '')}/package.json`)
|
|
39
|
-
cfg.pkg = pick(pkgJson,
|
|
40
|
-
['name', 'version', 'description', 'author', 'license', 'homepage'])
|
|
41
|
-
if (cfg.name === 'app') {
|
|
42
|
-
cfg.alias = 'app'
|
|
43
|
-
cfg.title = 'Application'
|
|
44
|
-
} else if (!isString(cfg.alias)) cfg.alias = pkg.slice(0, 5) === 'bajo-' ? pkg.slice(5).toLowerCase() : pkg // fix. can't be overriden
|
|
45
|
-
cfg.title = cfg.title ?? titleize.call(this, cfg.alias)
|
|
46
|
-
// merge with config from datadir
|
|
47
|
-
try {
|
|
48
|
-
const altCfg = await readConfig(`${config.dir.data}/config/${cfg.name}.*`)
|
|
49
|
-
cfg = defaultsDeep({}, omit(altCfg, omittedPluginKeys), cfg)
|
|
50
|
-
} catch (err) {}
|
|
51
|
-
const envArgv = defaultsDeep({}, omit(env[cfg.name] ?? {}, omittedPluginKeys) ?? {}, omit(argv[cfg.name] ?? {}, omittedPluginKeys) ?? {})
|
|
52
|
-
cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {})
|
|
53
|
-
cfg.dependencies = cfg.dependencies ?? []
|
|
54
|
-
if (isString(cfg.dependencies)) cfg.dependencies = [cfg.dependencies]
|
|
55
|
-
if (!this[name]) this[name] = {}
|
|
56
|
-
this[name].config = cfg
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function buildConfig ({ argv, env }) {
|
|
60
|
-
const { log, freeze } = this.bajo.helper
|
|
61
|
-
log.debug('Read configurations')
|
|
62
|
-
for (const pkg of this.bajo.config.plugins) {
|
|
63
|
-
await runner.call(this, pkg, { argv, env })
|
|
64
|
-
}
|
|
65
|
-
freeze(this.bajo.config)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default buildConfig
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { find } from 'lodash-es'
|
|
2
|
-
import error from '../helper/error.js'
|
|
3
|
-
|
|
4
|
-
async function checkAlias () {
|
|
5
|
-
const { log, eachPlugins } = this.bajo.helper
|
|
6
|
-
log.debug('Checking alias & name clashes')
|
|
7
|
-
const refs = []
|
|
8
|
-
await eachPlugins(async function ({ plugin, pkg, alias }) {
|
|
9
|
-
let item = find(refs, { plugin })
|
|
10
|
-
if (item) throw error('Plugin name clash: \'%s (%s)\' with \'%s (%s)\'', plugin, pkg, item.plugin, item.pkg, { code: 'BAJO_NAME_CLASH' })
|
|
11
|
-
item = find(refs, { alias })
|
|
12
|
-
if (item) throw error('Plugin alias clash: \'%s (%s)\' with \'%s (%s)\'', alias, pkg, item.alias, item.pkg, { code: 'BAJO_ALIAS_CLASH' })
|
|
13
|
-
refs.push({ plugin, alias, pkg })
|
|
14
|
-
})
|
|
15
|
-
this.bajo.pluginRefs = refs
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default checkAlias
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { reduce, map, trim, keys, intersection, each, camelCase, get } from 'lodash-es'
|
|
2
|
-
import semver from 'semver'
|
|
3
|
-
|
|
4
|
-
async function runner ({ plugin, pkg, dependencies }) {
|
|
5
|
-
const { log, getConfig, error, join } = this.bajo.helper
|
|
6
|
-
log.trace('Checking dependencies: %s', plugin)
|
|
7
|
-
const config = getConfig()
|
|
8
|
-
const odep = reduce(dependencies, (o, k) => {
|
|
9
|
-
const item = map(k.split('@'), m => trim(m))
|
|
10
|
-
o[item[0]] = item[1]
|
|
11
|
-
return o
|
|
12
|
-
}, {})
|
|
13
|
-
const deps = keys(odep)
|
|
14
|
-
if (deps.length > 0) {
|
|
15
|
-
if (intersection(config.plugins, deps).length !== deps.length) {
|
|
16
|
-
throw error('Dependency for \'%s\' unfulfilled: %s', pkg, join(deps), { code: 'BAJO_DEPENDENCY' })
|
|
17
|
-
}
|
|
18
|
-
each(deps, d => {
|
|
19
|
-
if (!odep[d]) return
|
|
20
|
-
const ver = get(this[camelCase(d)], 'config.pkg.version')
|
|
21
|
-
if (!ver) return
|
|
22
|
-
if (!semver.satisfies(ver, odep[d])) {
|
|
23
|
-
throw error('Semver check \'%s\' against \'%s\' failed', pkg, `${d}@${odep[d]}`, { code: 'BAJO_DEPENDENCY_SEMVER' })
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function checkDependency () {
|
|
30
|
-
const { log, eachPlugins } = this.bajo.helper
|
|
31
|
-
log.debug('Checking dependencies')
|
|
32
|
-
await eachPlugins(async function ({ plugin, pkg, dependencies }) {
|
|
33
|
-
await runner.call(this, { plugin, pkg, dependencies })
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default checkDependency
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { isFunction, isPlainObject, map } from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
async function collectConfigHandlers (pkg) {
|
|
4
|
-
const { getModuleDir, importModule, log, join } = this.bajo.helper
|
|
5
|
-
for (const pkg of this.bajo.config.plugins) {
|
|
6
|
-
let dir
|
|
7
|
-
try {
|
|
8
|
-
dir = getModuleDir(pkg)
|
|
9
|
-
} catch (err) {}
|
|
10
|
-
if (!dir) continue
|
|
11
|
-
const file = `${dir}/bajo/extend/read-config.js`
|
|
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)
|
|
17
|
-
}
|
|
18
|
-
const exts = map(this.bajo.configHandlers, 'ext')
|
|
19
|
-
log.trace('Config handlers: %s', join(exts))
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default collectConfigHandlers
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {} from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
async function collectExitHandlers () {
|
|
4
|
-
const { importModule, log, eachPlugins, getConfig, print, join } = this.bajo.helper
|
|
5
|
-
const config = getConfig()
|
|
6
|
-
if (!config.exitHandler) return
|
|
7
|
-
this.bajo.exitHandler = this.bajo.exitHandler ?? {}
|
|
8
|
-
const names = []
|
|
9
|
-
await eachPlugins(async function ({ plugin, dir }) {
|
|
10
|
-
const mod = await importModule(`${dir}/bajo/exit.js`)
|
|
11
|
-
if (!mod) return undefined
|
|
12
|
-
this.bajo.exitHandler[plugin] = mod
|
|
13
|
-
names.push(plugin)
|
|
14
|
-
})
|
|
15
|
-
log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') : join(names))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default collectExitHandlers
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { map, camelCase, merge, forOwn, groupBy } from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
async function collectHooks () {
|
|
4
|
-
const { eachPlugins, log, runHook, isLogInRange, importModule } = this.bajo.helper
|
|
5
|
-
this.bajo.hooks = this.bajo.hooks ?? []
|
|
6
|
-
log.debug('Collect hooks')
|
|
7
|
-
// collects
|
|
8
|
-
await eachPlugins(async function ({ plugin, dir, file }) {
|
|
9
|
-
const hookName = (file.slice(dir.length + 1) ?? '').split('/')[1]
|
|
10
|
-
let [ns, path] = hookName.replace('.js', '').split('@')
|
|
11
|
-
if (!path) {
|
|
12
|
-
path = ns
|
|
13
|
-
ns = plugin
|
|
14
|
-
}
|
|
15
|
-
path = camelCase(path)
|
|
16
|
-
ns = map(ns.split('.'), (n, i) => i === 1 ? n : camelCase(n)).join('.')
|
|
17
|
-
const mod = await importModule(file, { asHandler: true })
|
|
18
|
-
if (!mod) return undefined
|
|
19
|
-
merge(mod, { ns, path })
|
|
20
|
-
this.bajo.hooks.push(mod)
|
|
21
|
-
}, { glob: 'hook/**/*.js', insideBajo: true })
|
|
22
|
-
await runHook('bajo:afterCollectHooks')
|
|
23
|
-
// for log trace purpose only
|
|
24
|
-
if (!isLogInRange('trace')) return
|
|
25
|
-
const items = groupBy(this.bajo.hooks, 'ns')
|
|
26
|
-
forOwn(items, (v, k) => {
|
|
27
|
-
const hooks = groupBy(v, 'path')
|
|
28
|
-
forOwn(hooks, (v1, k1) => {
|
|
29
|
-
log.trace('Collect hook: %s:%s (%d)', k, k1, v1.length)
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default collectHooks
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isArray, each, isPlainObject, has, merge, concat } from 'lodash-es'
|
|
2
|
-
import { readAllConfigs } from './build-config.js'
|
|
3
|
-
|
|
4
|
-
async function extendConfig () {
|
|
5
|
-
const { eachPlugins } = this.bajo.helper
|
|
6
|
-
await eachPlugins(async function (opts) {
|
|
7
|
-
if (!opts.cfg.mergeProps) return undefined
|
|
8
|
-
await eachPlugins(async function ({ dir, plugin }) {
|
|
9
|
-
const cfg = await readAllConfigs.call(this, `${dir}/${opts.plugin}/config`, opts.plugin)
|
|
10
|
-
each(opts.cfg.mergeProps, p => {
|
|
11
|
-
if (!has(cfg, p)) return undefined
|
|
12
|
-
if (isArray(opts.cfg[p])) this[opts.plugin].config[p] = concat(opts.cfg[p], cfg[p])
|
|
13
|
-
else if (isPlainObject(opts.cfg[p])) this[opts.plugin].config[p] = merge(opts.cfg[p], cfg[p])
|
|
14
|
-
else this[opts.plugin].config[p] = cfg[p]
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
delete this[opts.plugin].config.mergeProps
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default extendConfig
|
package/boot/plugins/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import buildConfig from './build-config.js'
|
|
2
|
-
import extendConfig from './extend-config.js'
|
|
3
|
-
import checkDependency from './check-dependency.js'
|
|
4
|
-
import checkClash from './check-clash.js'
|
|
5
|
-
import attachHelper from './attach-helper.js'
|
|
6
|
-
import collectHooks from './collect-hooks.js'
|
|
7
|
-
import run from './run.js'
|
|
8
|
-
import collectConfigHandlers from './collect-config-handlers.js'
|
|
9
|
-
import collectExitHandlers from './collect-exit-handlers.js'
|
|
10
|
-
import parseArgsArgv from '../lib/parse-args-argv.js'
|
|
11
|
-
import parseEnv from '../lib/parse-env.js'
|
|
12
|
-
|
|
13
|
-
async function bootBajos () {
|
|
14
|
-
const { argv } = await parseArgsArgv({ useParser: true }) ?? {}
|
|
15
|
-
const env = parseEnv() ?? {}
|
|
16
|
-
await collectConfigHandlers.call(this)
|
|
17
|
-
await buildConfig.call(this, { argv, env })
|
|
18
|
-
await extendConfig.call(this)
|
|
19
|
-
await checkClash.call(this)
|
|
20
|
-
await checkDependency.call(this)
|
|
21
|
-
await attachHelper.call(this)
|
|
22
|
-
await collectHooks.call(this)
|
|
23
|
-
await run.call(this)
|
|
24
|
-
await collectExitHandlers.call(this)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default bootBajos
|
package/boot/plugins/run.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { set, get, camelCase, upperFirst, map } from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
async function run () {
|
|
4
|
-
const { runHook, log, eachPlugins, importModule, freeze, getConfig, print, join } = this.bajo.helper
|
|
5
|
-
const config = getConfig()
|
|
6
|
-
const methods = ['init']
|
|
7
|
-
if (!get(config, 'tool')) methods.push('start')
|
|
8
|
-
for (const f of methods) {
|
|
9
|
-
await runHook(`bajo:${camelCase(`before ${f} all plugins`)}`)
|
|
10
|
-
await eachPlugins(async function ({ plugin, dir }) {
|
|
11
|
-
const mod = await importModule(`${dir}/bajo/${f}.js`)
|
|
12
|
-
if (mod) {
|
|
13
|
-
log.debug('%s: %s', print.__(upperFirst(f)), plugin)
|
|
14
|
-
await runHook(`bajo:${camelCase(`before ${f} ${plugin}`)}`)
|
|
15
|
-
await mod.call(this)
|
|
16
|
-
await runHook(`bajo:${camelCase(`after ${f} ${plugin}`)}`)
|
|
17
|
-
}
|
|
18
|
-
if (f === 'init') freeze(this[plugin].config)
|
|
19
|
-
set(this, `${plugin}.state.${f}`, true)
|
|
20
|
-
})
|
|
21
|
-
await runHook(`bajo:${camelCase(`after ${f} all plugins`)}`)
|
|
22
|
-
}
|
|
23
|
-
log.debug('Loaded plugins: %s', join(map(config.plugins, b => camelCase(b))))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default run
|
package/boot/run-tool.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { isString, map, find } from 'lodash-es'
|
|
2
|
-
import Path from 'path'
|
|
3
|
-
const tools = []
|
|
4
|
-
|
|
5
|
-
async function runTool () {
|
|
6
|
-
const { getConfig, log, eachPlugins, importPkg, importModule, print } = this.bajo.helper
|
|
7
|
-
const config = getConfig()
|
|
8
|
-
await eachPlugins(async function checkCli ({ file, plugin, alias }) {
|
|
9
|
-
tools.push({ ns: plugin, file, nsAlias: alias })
|
|
10
|
-
}, { glob: 'tool.js', ns: 'bajoCli' })
|
|
11
|
-
this.bajo.tools = tools
|
|
12
|
-
if (!config.tool) return
|
|
13
|
-
log.debug('Run tool')
|
|
14
|
-
print.info('Sidetool is running...')
|
|
15
|
-
if (tools.length === 0) print.fatal('No tool found. Aborted!')
|
|
16
|
-
let name = config.tool
|
|
17
|
-
let toc = false
|
|
18
|
-
if (!isString(config.tool)) {
|
|
19
|
-
const select = await importPkg('bajoCli:@inquirer/select')
|
|
20
|
-
name = await select({
|
|
21
|
-
message: print.__('Please select tool provider:'),
|
|
22
|
-
choices: map(tools, t => ({ value: t.ns }))
|
|
23
|
-
})
|
|
24
|
-
toc = true
|
|
25
|
-
}
|
|
26
|
-
const [ns, path, ...params] = name.split(':')
|
|
27
|
-
const tool = find(tools, t => (t.ns === ns || t.nsAlias === ns))
|
|
28
|
-
if (!tool) print.fatal('Sidetool \'%s\' not found. Aborted!', name)
|
|
29
|
-
const opts = { ns, toc, path, params, args: config.args }
|
|
30
|
-
const mod = await importModule(tool.file)
|
|
31
|
-
if (mod === 'defCliHandler' && this.bajoCli) {
|
|
32
|
-
const { runToolMethod } = this.bajoCli.helper
|
|
33
|
-
const dir = `${Path.dirname(tool.file)}/tool`
|
|
34
|
-
await runToolMethod({ path, args: config.args, dir })
|
|
35
|
-
} else {
|
|
36
|
-
const handler = mod.handler ?? mod
|
|
37
|
-
await handler.call(this, opts)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default runTool
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: boot/build-config.js</title><!--[if lt IE 9]>
|
|
2
|
-
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
3
|
-
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="",baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body class="dark" data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">boot_build-config.js</h1></header><article><pre class="prettyprint source lang-js"><code>/**
|
|
4
|
-
* @module boot/buildConfig
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs-extra')
|
|
8
|
-
const _ = require('lodash')
|
|
9
|
-
const pathResolve = require('../helper/path-resolve')
|
|
10
|
-
const readConfig = require('../helper/read-config')
|
|
11
|
-
const getKeyByValue = require('../helper/get-key-by-value')
|
|
12
|
-
const error = require('../helper/error')
|
|
13
|
-
const envs = require('../helper/envs')
|
|
14
|
-
const parseArgsArgv = require('../lib/parse-args-argv')
|
|
15
|
-
const parseEnv = require('../lib/parse-env')
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Building configuration object. Read configurtion file from app data directory, program
|
|
19
|
-
* arguments and envoronment variables with following priority: ```Env > Args > Config file >
|
|
20
|
-
* defaults config```
|
|
21
|
-
*
|
|
22
|
-
* If data directory is provided and doesn't exist yet, it will be automatically created.
|
|
23
|
-
*
|
|
24
|
-
* Config file must be located in: ```<data dir>/config/bajo.<format>```, and support either
|
|
25
|
-
* ```.json``` or ```.js``` format. JS format must be a nodejs module that wrap an async
|
|
26
|
-
* function and return an object
|
|
27
|
-
*
|
|
28
|
-
* @instance
|
|
29
|
-
* @async
|
|
30
|
-
* @throws Will throw if data directory is not provided
|
|
31
|
-
*
|
|
32
|
-
* @returns {Object} config
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
async function buildConfig () {
|
|
36
|
-
const { args, argv } = parseArgsArgv()
|
|
37
|
-
const env = parseEnv()
|
|
38
|
-
let defConfig = {
|
|
39
|
-
dir: {},
|
|
40
|
-
log: {
|
|
41
|
-
level: 'info',
|
|
42
|
-
dateFormat: `UTC:yyyy-mm-dd'T'HH:MM:ss.l'Z'`,
|
|
43
|
-
report: ['sysreport', 'helper', 'hook'],
|
|
44
|
-
details: []
|
|
45
|
-
},
|
|
46
|
-
plugins: ['app'],
|
|
47
|
-
env: 'dev'
|
|
48
|
-
}
|
|
49
|
-
defConfig = _.defaultsDeep(env.root, argv.root, defConfig)
|
|
50
|
-
if (!defConfig.dir.data) throw error('No data directory provided', { code: 'BAJO_DATA_DIR_NOT_PROVIDED' })
|
|
51
|
-
defConfig.dir.data = pathResolve(defConfig.dir.data)
|
|
52
|
-
_.set(defConfig, 'dir.base', pathResolve(process.cwd()))
|
|
53
|
-
_.each(['tmp', 'lock'], k => {
|
|
54
|
-
if (!defConfig.dir[k]) defConfig.dir[k] = `${defConfig.dir.data}/${k}`
|
|
55
|
-
fs.ensureDirSync(defConfig.dir[k])
|
|
56
|
-
})
|
|
57
|
-
fs.ensureDirSync(defConfig.dir.data + '/config')
|
|
58
|
-
const resp = _.omit(await readConfig.call(this, `${defConfig.dir.data}/config/bajo.*`), ['dir'])
|
|
59
|
-
const config = _.defaultsDeep(resp, defConfig)
|
|
60
|
-
config.args = args
|
|
61
|
-
config.env = config.env.toLowerCase()
|
|
62
|
-
if (_.values(envs).includes(config.env)) config.env = getKeyByValue.handler(envs, config.env)
|
|
63
|
-
if (!_.keys(envs).includes(config.env)) config.env = 'dev'
|
|
64
|
-
process.env.NODE_ENV = envs[config.env]
|
|
65
|
-
if (_.isString(config.log.details)) config.log.details = _.map((argv.root['log-details'] || '').split(','), t => _.trim(t))
|
|
66
|
-
if (config.env === 'dev') config.log.level = 'debug'
|
|
67
|
-
if (config.verbose) config.log.level = 'trace'
|
|
68
|
-
|
|
69
|
-
if (!config.plugins.includes('app')) config.plugins.push('app')
|
|
70
|
-
config.plugins = _.filter(_.uniq(_.map(config.plugins, b => _.trim(b))), b => !_.isEmpty(b))
|
|
71
|
-
this.bajo.config = config
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
module.exports = buildConfig
|
|
75
|
-
</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: boot/create-scope.js</title><!--[if lt IE 9]>
|
|
2
|
-
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
3
|
-
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="",baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body class="dark" data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">boot_create-scope.js</h1></header><article><pre class="prettyprint source lang-js"><code>/**
|
|
4
|
-
* @module boot/createScope
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { EventEmitter } = require('events')
|
|
8
|
-
const event = new EventEmitter()
|
|
9
|
-
|
|
10
|
-
const bajo = {
|
|
11
|
-
event
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @instance
|
|
16
|
-
* @async
|
|
17
|
-
* @returns {Object} scope
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
function createScope () {
|
|
21
|
-
return { bajo }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = createScope
|
|
25
|
-
</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
|