bajo 0.3.9 → 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 -44
- 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
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import yargs from 'yargs'
|
|
2
2
|
import { Parser } from 'yargs/helpers'
|
|
3
|
-
import
|
|
4
|
-
import isSet from '../
|
|
3
|
+
import { unflatten } from 'flat'
|
|
4
|
+
import isSet from '../class/bajo-core/method/is-set.js'
|
|
5
5
|
import dotenvParseVariables from 'dotenv-parse-variables'
|
|
6
|
-
import importModule from '../
|
|
6
|
+
import importModule from '../class/bajo-core/method/import-module.js'
|
|
7
7
|
import { find, each, set, camelCase, forOwn } from 'lodash-es'
|
|
8
8
|
import fs from 'fs-extra'
|
|
9
9
|
import path from 'path'
|
|
10
|
-
import currentLoc from '
|
|
11
|
-
|
|
12
|
-
const { unflatten } = flat
|
|
10
|
+
import currentLoc from './current-loc.js'
|
|
13
11
|
|
|
14
12
|
const parseItem = (data, delimiter) => {
|
|
15
13
|
return unflatten(data, {
|
|
@@ -45,23 +43,22 @@ const parseWithYargs = async () => {
|
|
|
45
43
|
})
|
|
46
44
|
.version().alias('version', 'v')
|
|
47
45
|
.help().alias('help', 'h')
|
|
48
|
-
.alias('
|
|
46
|
+
.alias('applet', 'a')
|
|
49
47
|
if (pkg.homepage) cli.epilog(`For more information please visit ${pkg.homepage}`)
|
|
50
48
|
return cli.argv
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
async function parseArgsArgv ({ delimiter = '-', splitter = '
|
|
51
|
+
async function parseArgsArgv ({ delimiter = '-', splitter = ':', useParser } = {}) {
|
|
54
52
|
if (!isSet(useParser)) useParser = find(process.argv, a => a.startsWith('--spawn'))
|
|
55
53
|
let argv = useParser ? await parseWithParser() : await parseWithYargs()
|
|
56
54
|
const args = argv._
|
|
57
55
|
delete argv._
|
|
58
56
|
delete argv.$0
|
|
59
57
|
argv = dotenvParseVariables(argv)
|
|
60
|
-
|
|
61
|
-
const all = { root: {} }
|
|
58
|
+
const all = { _: {} }
|
|
62
59
|
each(argv, (v, k) => {
|
|
63
60
|
const parts = k.split(splitter)
|
|
64
|
-
if (!parts[1]) all.
|
|
61
|
+
if (!parts[1]) all._[parts[0]] = v
|
|
65
62
|
else set(all, `${camelCase(parts[0])}.${parts[1]}`, v)
|
|
66
63
|
})
|
|
67
64
|
const result = {}
|
package/boot/lib/parse-env.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import dotenvParseVariables from 'dotenv-parse-variables'
|
|
2
|
-
import
|
|
2
|
+
import { unflatten } from 'flat'
|
|
3
3
|
import dotEnv from 'dotenv'
|
|
4
4
|
import { each, set, camelCase, forOwn } from 'lodash-es'
|
|
5
|
-
const { unflatten } = flat
|
|
6
5
|
|
|
7
6
|
const parse = (data, delimiter) => {
|
|
8
7
|
return unflatten(data, {
|
|
9
8
|
delimiter,
|
|
10
9
|
safe: true,
|
|
11
10
|
overwrite: true,
|
|
12
|
-
transformKey: k =>
|
|
11
|
+
transformKey: k => {
|
|
12
|
+
return camelCase(k.toLowerCase())
|
|
13
|
+
}
|
|
13
14
|
})
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export default function ({ delimiter = '
|
|
17
|
+
export default function ({ delimiter = '__', splitter = '.' } = {}) {
|
|
17
18
|
let env
|
|
18
19
|
try {
|
|
19
20
|
env = dotEnv.config()
|
|
@@ -22,10 +23,10 @@ export default function ({ delimiter = '_', splitter = '__' } = {}) {
|
|
|
22
23
|
env = { parsed: {} }
|
|
23
24
|
}
|
|
24
25
|
env = dotenvParseVariables(env.parsed, { assignToProcessEnv: false })
|
|
25
|
-
const all = {
|
|
26
|
+
const all = { _: {} }
|
|
26
27
|
each(env, (v, k) => {
|
|
27
28
|
const parts = k.split(splitter)
|
|
28
|
-
if (!parts[1]) all.
|
|
29
|
+
if (!parts[1]) all._[parts[0]] = v
|
|
29
30
|
else set(all, `${camelCase(parts[0])}.${parts[1]}`, v)
|
|
30
31
|
})
|
|
31
32
|
const result = {}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import readConfig from '../class/bajo-core/method/read-config.js'
|
|
2
|
+
import defaultsDeep from '../class/bajo-core/method/defaults-deep.js'
|
|
3
|
+
|
|
4
|
+
async function readAllConfigs (base) {
|
|
5
|
+
let cfg = {}
|
|
6
|
+
let ext = {}
|
|
7
|
+
// default config file
|
|
8
|
+
try {
|
|
9
|
+
cfg = await readConfig.call(this.bajo, `${base}.*`)
|
|
10
|
+
} catch (err) {
|
|
11
|
+
if (['BAJO_CONFIG_NO_PARSER'].includes(err.code)) throw err
|
|
12
|
+
}
|
|
13
|
+
// env based config file
|
|
14
|
+
try {
|
|
15
|
+
ext = await readConfig.call(this.bajo, `${base}-${this.bajo.config.env}.*`)
|
|
16
|
+
} catch (err) {
|
|
17
|
+
if (!['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) throw err
|
|
18
|
+
}
|
|
19
|
+
return defaultsDeep({}, ext, cfg)
|
|
20
|
+
/*
|
|
21
|
+
try {
|
|
22
|
+
cfg = await readConfig.call(this.bajo, `${base}-${this.bajo.config.env}.*`)
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (['BAJO_CONFIG_NO_PARSER'].includes(err.code)) throw err
|
|
25
|
+
if (['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) {
|
|
26
|
+
try {
|
|
27
|
+
cfg = await readConfig.call(this.bajo, `${base}.*`)
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (!['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) throw err
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
*/
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default readAllConfigs
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { get, isPlainObject } from 'lodash-es'
|
|
2
|
+
import Sprintf from 'sprintf-js'
|
|
3
|
+
const { sprintf } = Sprintf
|
|
4
|
+
|
|
5
|
+
function translate (instance, text, ...args) {
|
|
6
|
+
let ntext = text
|
|
7
|
+
if (text) {
|
|
8
|
+
const i18n = instance ?? get(this, 'app.bajoI18N.instance')
|
|
9
|
+
if (i18n) {
|
|
10
|
+
if (isPlainObject(args[0])) ntext = i18n.t(text, args[0])
|
|
11
|
+
else ntext = i18n.t(text, { ns: this.name, postProcess: 'sprintf', sprintf: args })
|
|
12
|
+
} else ntext = sprintf(text, ...args)
|
|
13
|
+
}
|
|
14
|
+
if (ntext === '') ntext = text
|
|
15
|
+
return ntext
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default translate
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Ecosystem
|
|
2
|
+
|
|
3
|
+
## Bajo Plugins
|
|
4
|
+
|
|
5
|
+
| Package | Name | Alias | Description |
|
|
6
|
+
| ------- | ---- | ----- | ----------- |
|
|
7
|
+
| [bajo-cache](https://github.com/ardhi/bajo-cache) | bajoCache | cache | General cache service for all bajo plugins |
|
|
8
|
+
| [bajo-config](https://github.com/ardhi/bajo-config) | bajoConfig | cfg | Add YAML & TOML support in config |
|
|
9
|
+
| [bajo-common-db](https://github.com/ardhi/bajo-common-db) | bajoCommonDb | cdb | Common database |
|
|
10
|
+
| [bajo-cli](https://github.com/ardhi/bajo-cli) | bajoCli | cli | Command line support & tools |
|
|
11
|
+
| [bajo-cron](https://github.com/ardhi/bajo-cron) | bajoCron | cron | Cron support |
|
|
12
|
+
| [bajo-emitter](https://github.com/ardhi/bajo-emitter) | bajoEmitter | emitter | Centralized event emitter & message broadcaster |
|
|
13
|
+
| [bajo-extra](https://github.com/ardhi/bajo-extra) | bajoExtra | extra | Extra necessary booster! |
|
|
14
|
+
| [bajo-i18n](https://github.com/ardhi/bajo-i18n) | bajoI18N | i18n | Localization & Internationalization |
|
|
15
|
+
| [bajo-logger](https://github.com/ardhi/bajo-logger) | bajoLogger | log | Pino logger support |
|
|
16
|
+
| [bajo-markdown](https://github.com/ardhi/bajo-markdown) | bajoMarkdown | md | Markdown support |
|
|
17
|
+
| [bajo-mqtt](https://github.com/ardhi/bajo-mqtt) | bajoMqtt | mqtt | MQTT binding |
|
|
18
|
+
| [bajo-udp](https://github.com/ardhi/bajo-udp) | bajoUdp | udp | UDP binding |
|
|
19
|
+
| [bajo-serialport](https://github.com/ardhi/bajo-serialport) | bajoSerialport | sp | Serialport binding |
|
|
20
|
+
| [bajo-sysinfo](https://github.com/ardhi/bajo-sysinfo) | bajoSysinfo | si | System information |
|
|
21
|
+
| [bajo-webdav](https://github.com/ardhi/bajo-webdav) | bajoWebdav | webdav | Webdav binding |
|
|
22
|
+
|
|
23
|
+
## Dobo DBMS Plugins
|
|
24
|
+
|
|
25
|
+
| Package | Name | Alias | Description |
|
|
26
|
+
| ------- | ---- | ----- | ----------- |
|
|
27
|
+
| [dobo](https://github.com/ardhi/dobo) | dobo | db | DBMS with built-in memory database |
|
|
28
|
+
| [dobo-couchdb](https://github.com/ardhi/dobo-couchdb) | doboCouchdb | dbcdb | CouchDB driver |
|
|
29
|
+
| [dobo-elasticsearch](https://github.com/ardhi/dobo-elasticsearch) | doboElasticsearch | dbes | Elasticsearch driver |
|
|
30
|
+
| [dobo-knex](https://github.com/ardhi/dobo-knex) | doboKnex | dbknex | Knex driver |
|
|
31
|
+
| [dobo-mongodb](https://github.com/ardhi/dobo-mongodb) | doboMongodb | dbmongo | MongoDB driver |
|
|
32
|
+
| [dobo-restproxy](https://github.com/ardhi/dobo-restproxy) | doboRestproxy | dbrpx | Restproxy driver |
|
|
33
|
+
| [dobo-restproxy-jsonserver](https://github.com/ardhi/dobo-restproxy-jsonserver) | doboRestproxyJsonserver | dbrpxjs | JsonServer support for doboRestproxy |
|
|
34
|
+
| [dobo-restproxy-ndut](https://github.com/ardhi/dobo-restproxy-ndut) | doboRestproxyNdut | dbrpxndut | NDUT support for doboRestproxy |
|
|
35
|
+
| [dobo-extra](https://github.com/ardhi/dobo-extra) | doboExtra | dbxtra | Extra tools & utility |
|
|
36
|
+
|
|
37
|
+
## Waibu Web Framework Plugins
|
|
38
|
+
|
|
39
|
+
| Package | Name | Alias | Description |
|
|
40
|
+
| ------- | ---- | ----- | ----------- |
|
|
41
|
+
| [waibu](https://github.com/ardhi/waibu) | waibu | wb | Web framework |
|
|
42
|
+
| [waibu-bootstrap](https://github.com/ardhi/waibu-bootstrap) | waibuBootstrap | wbbs | Bootstrap support for Waibu MPA |
|
|
43
|
+
| [waibu-bootstrap-icons](https://github.com/ardhi/waibu-bootstrap-icons) | waibuBootstrapIcons | wbbsi | Bootstrap Icons support for Waibu MPA |
|
|
44
|
+
| [waibu-bootswatch](https://github.com/ardhi/waibu-bootswatch) | waibuBootswatch | wbbw | Bootswatch support for Waibu MPA |
|
|
45
|
+
| [waibu-feather](https://github.com/ardhi/waibu-feather) | waibuFeather | wbft | Feather icons support for Waibu MPA |
|
|
46
|
+
| [waibu-fontawesome](https://github.com/ardhi/waibu-fontawesome) | waibuFontawesome | wbfa | Fontawesome support for Waibu MPA |
|
|
47
|
+
| [waibu-extra](https://github.com/ardhi/waibu-extra) | waibuExtra | wbxtra | Most used 3rd party libs for Waibu MPA |
|
|
48
|
+
| [waibu-mdi](https://github.com/ardhi/waibu-mdi) | waibuMdi | wbmdi | Material Design Icons (MDI) support for Waibu MPA |
|
|
49
|
+
| [waibu-mpa](https://github.com/ardhi/waibu-mpa) | waibuMpa | wbmpa | Multi pages app for for Waibu |
|
|
50
|
+
| [waibu-nunjucks](https://github.com/ardhi/waibu-nunjucks) | waibuNunjucks | wbnunjucks | Nunjucks support for Waibu MPA |
|
|
51
|
+
| [waibu-phosphor](https://github.com/ardhi/waibu-phosphor) | waibuPhosphor | wbmpp | Phosphoricons support for Waibu MPA |
|
|
52
|
+
| [waibu-rest-api](https://github.com/ardhi/waibu-rest-api) | waibuRestApi | wbrestapi | Rest API for Waibu |
|
|
53
|
+
| [waibu-socket.io](https://github.com/ardhi/waibu-socket.io) | waibuSocketIo | wbsio | Socket.io support for Waibu |
|
|
54
|
+
| [waibu-static](https://github.com/ardhi/waibu-static) | waibuStatic | wbstatic | Static asset support for Waibu |
|
|
55
|
+
| [waibu-swagger](https://github.com/ardhi/waibu-swagger) | waibuSwagger | wbswagger | Rest API Documentation for Waibu REST API |
|
package/docs/hook.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Hook
|
|
2
|
+
|
|
3
|
+
### ```<ns>:beforeBuildCollection (container)```
|
|
4
|
+
|
|
5
|
+
- ```ns```: Plugin name
|
|
6
|
+
- ```container```: Name of config key which hold collections array
|
|
7
|
+
|
|
8
|
+
### ```<ns>:beforeBuildCollection (container)```
|
|
9
|
+
|
|
10
|
+
- ```ns```: Plugin name
|
|
11
|
+
- ```container```: Name of config key which hold collections array
|
package/package.json
CHANGED
|
@@ -1,56 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bajo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A framework to build a giant monstrous app rapidly",
|
|
5
|
-
"main": "boot/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build-doc": "jsdoc -c .jsdoc.conf.json",
|
|
8
|
-
"test": "mocha"
|
|
9
|
-
},
|
|
10
|
-
"type": "module",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/ardhi/bajo.git"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"bajo",
|
|
17
|
-
"modular",
|
|
18
|
-
"nodejs",
|
|
19
|
-
"monolith"
|
|
20
|
-
],
|
|
21
|
-
"author": "Ardhi Lukianto <ardhi@lukianto.com>",
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/ardhi/bajo/issues"
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://github.com/ardhi/bajo#readme",
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"add-filename-increment": "^1.0.0",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"dotenv": "^
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "bajo",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A framework to build a giant monstrous app rapidly",
|
|
5
|
+
"main": "boot/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build-doc": "jsdoc -c .jsdoc.conf.json",
|
|
8
|
+
"test": "mocha"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ardhi/bajo.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"bajo",
|
|
17
|
+
"modular",
|
|
18
|
+
"nodejs",
|
|
19
|
+
"monolith"
|
|
20
|
+
],
|
|
21
|
+
"author": "Ardhi Lukianto <ardhi@lukianto.com>",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/ardhi/bajo/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/ardhi/bajo#readme",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"add-filename-increment": "^1.0.0",
|
|
29
|
+
"dayjs": "^1.11.13",
|
|
30
|
+
"deep-freeze-strict": "^1.1.1",
|
|
31
|
+
"delay": "^6.0.0",
|
|
32
|
+
"dotenv": "^16.4.7",
|
|
33
|
+
"dotenv-parse-variables": "^2.0.0",
|
|
34
|
+
"empty-dir": "^3.0.0",
|
|
35
|
+
"fast-glob": "^3.3.3",
|
|
36
|
+
"flat": "^6.0.1",
|
|
37
|
+
"fs-extra": "^11.2.0",
|
|
38
|
+
"global-modules-path": "^3.0.0",
|
|
39
|
+
"lodash-es": "^4.17.21",
|
|
40
|
+
"ms": "^2.1.3",
|
|
41
|
+
"nanoid": "^5.0.9",
|
|
42
|
+
"omit-deep": "^0.3.0",
|
|
43
|
+
"ora": "^8.1.1",
|
|
44
|
+
"outmatch": "^1.0.0",
|
|
45
|
+
"semver": "^7.6.3",
|
|
46
|
+
"sprintf-js": "^1.1.3",
|
|
47
|
+
"yargs": "^17.7.2"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@faker-js/faker": "^8.0.2",
|
|
51
|
+
"chai": "^4.3.7",
|
|
52
|
+
"clean-jsdoc-theme": "^4.2.7",
|
|
53
|
+
"sinon": "^15.1.2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const { faker } = require('@faker-js/faker')
|
|
3
|
-
const isSet = require('../helper/is-set')
|
|
1
|
+
/* global describe, context, it */
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
import { expect } from 'chai'
|
|
4
|
+
import { faker } from '@faker-js/faker'
|
|
5
|
+
import isSet from '../boot/core/method/is-set.js'
|
|
6
|
+
|
|
7
|
+
describe('isSet()', function () {
|
|
6
8
|
context('without argument', function () {
|
|
7
9
|
it("should return 'false'", function () {
|
|
8
10
|
expect(isSet()).to.equal(false)
|
package/boot/attach-helper.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import buildHelper from './lib/build-helper.js'
|
|
2
|
-
import logger from './lib/logger.js'
|
|
3
|
-
import print from './lib/print.js'
|
|
4
|
-
import deepFreeze from 'deep-freeze-strict'
|
|
5
|
-
import currentLoc from './helper/current-loc.js'
|
|
6
|
-
import dayjs from './lib/dayjs.js'
|
|
7
|
-
import fs from 'fs-extra'
|
|
8
|
-
import fastGlob from 'fast-glob'
|
|
9
|
-
import { sprintf } from 'sprintf-js'
|
|
10
|
-
import outmatch from 'outmatch'
|
|
11
|
-
|
|
12
|
-
export default async function () {
|
|
13
|
-
this.bajo.helper = await buildHelper.call(this, `${currentLoc(import.meta).dir}/helper`)
|
|
14
|
-
this.bajo.helper.freeze = (o, shallow) => {
|
|
15
|
-
if (shallow) Object.freeze(o)
|
|
16
|
-
else deepFreeze(o)
|
|
17
|
-
}
|
|
18
|
-
this.bajo.helper.dayjs = dayjs
|
|
19
|
-
this.bajo.helper.print = print.call(this)
|
|
20
|
-
this.bajo.helper.log = logger.call(this)
|
|
21
|
-
this.bajo.helper.setImmediate = function () {
|
|
22
|
-
return new Promise((resolve) => {
|
|
23
|
-
setImmediate(() => resolve())
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
// commonly used libraries
|
|
27
|
-
this.bajo.helper._ = await import('lodash-es')
|
|
28
|
-
this.bajo.helper.fs = fs
|
|
29
|
-
this.bajo.helper.fastGlob = fastGlob
|
|
30
|
-
this.bajo.helper.sprintf = sprintf
|
|
31
|
-
this.bajo.helper.outmatch = outmatch
|
|
32
|
-
// last cleanup
|
|
33
|
-
this.bajo.helper.freeze(this.bajo.helper, true)
|
|
34
|
-
if (!fs.existsSync(this.bajo.config.dir.data)) {
|
|
35
|
-
this.bajo.helper.log.warn('Data directory \'%s\' is not set yet!', this.bajo.config.dir.data)
|
|
36
|
-
}
|
|
37
|
-
if (this.bajo.config.env === 'dev') {
|
|
38
|
-
this.dump = this.bajo.helper.dump
|
|
39
|
-
}
|
|
40
|
-
}
|
package/boot/build-config.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module boot/buildConfig
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import os from 'os'
|
|
6
|
-
import fs from 'fs-extra'
|
|
7
|
-
import { get, set, pick, values, keys, uniq, without, filter, map, isEmpty, trim } from 'lodash-es'
|
|
8
|
-
import omitDeep from 'omit-deep'
|
|
9
|
-
import resolvePath from './helper/resolve-path.js'
|
|
10
|
-
import readConfig from './helper/read-config.js'
|
|
11
|
-
import getKeyByValue from './helper/get-key-by-value.js'
|
|
12
|
-
import envs from './helper/envs.js'
|
|
13
|
-
import defaultsDeep from './helper/defaults-deep.js'
|
|
14
|
-
import parseArgsArgv from './lib/parse-args-argv.js'
|
|
15
|
-
import parseEnv from './lib/parse-env.js'
|
|
16
|
-
import error from './helper/error.js'
|
|
17
|
-
import currentLoc from './helper/current-loc.js'
|
|
18
|
-
|
|
19
|
-
const configFilePick = ['log', 'plugins', 'env', 'run', 'exitHandler']
|
|
20
|
-
const configFileOmit = ['tool', 'spawn', 'cwd', 'name', 'alias']
|
|
21
|
-
|
|
22
|
-
const defConfig = {
|
|
23
|
-
dir: {},
|
|
24
|
-
log: {
|
|
25
|
-
dateFormat: 'YYYY-MM-DDTHH:MM:ss.SSS[Z]',
|
|
26
|
-
report: [],
|
|
27
|
-
tool: false
|
|
28
|
-
},
|
|
29
|
-
lang: Intl.DateTimeFormat().resolvedOptions().lang ?? 'en-US',
|
|
30
|
-
plugins: ['app'],
|
|
31
|
-
env: 'dev',
|
|
32
|
-
tool: false,
|
|
33
|
-
exitHandler: true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Building configuration object. Read configurtion file from app data directory, program
|
|
38
|
-
* arguments and envoronment variables with following priority: ```Env > Args > Config file >
|
|
39
|
-
* defaults config```
|
|
40
|
-
*
|
|
41
|
-
* If data directory is provided and doesn't exist yet, it will be automatically created.
|
|
42
|
-
*
|
|
43
|
-
* Config file must be located in: ```<data dir>/config/bajo.<format>```, and support either
|
|
44
|
-
* ```.json``` or ```.js``` format. JS format must be a nodejs module that wrap an async
|
|
45
|
-
* function and return an object
|
|
46
|
-
*
|
|
47
|
-
* If app run tool, by default log is in silent. To activate, set log.tool to true
|
|
48
|
-
*
|
|
49
|
-
* By default, if 'app' is a bajo app, it is always the last plugins to boot. To overide this
|
|
50
|
-
* behavior, you should configure it at plugin level (i.e. using .bootorder file)
|
|
51
|
-
*
|
|
52
|
-
* @instance
|
|
53
|
-
* @async
|
|
54
|
-
* @throws Will throw if data directory is not provided
|
|
55
|
-
*
|
|
56
|
-
* @returns {Object} config
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
async function buildConfig (cwd) {
|
|
60
|
-
const { args, argv } = await parseArgsArgv()
|
|
61
|
-
const env = parseEnv()
|
|
62
|
-
const envArgv = defaultsDeep({}, env.root, argv.root)
|
|
63
|
-
envArgv.name = 'bajo'
|
|
64
|
-
envArgv.alias = 'bajo'
|
|
65
|
-
// directories
|
|
66
|
-
set(envArgv, 'dir.base', cwd)
|
|
67
|
-
set(envArgv, 'dir.pkg', resolvePath(currentLoc(import.meta).dir + '/..'))
|
|
68
|
-
if (!get(envArgv, 'dir.data')) set(envArgv, 'dir.data', `${envArgv.dir.base}/data`)
|
|
69
|
-
envArgv.dir.data = resolvePath(envArgv.dir.data)
|
|
70
|
-
if (!envArgv.dir.tmp) {
|
|
71
|
-
envArgv.dir.tmp = resolvePath(os.tmpdir()) + '/bajo'
|
|
72
|
-
fs.ensureDirSync(envArgv.dir.tmp)
|
|
73
|
-
}
|
|
74
|
-
// config merging
|
|
75
|
-
let resp = await readConfig.call(this, `${envArgv.dir.data}/config/bajo.*`, { ignoreError: true })
|
|
76
|
-
resp = omitDeep(pick(resp, configFilePick), configFileOmit)
|
|
77
|
-
const config = defaultsDeep({}, envArgv, resp, defConfig)
|
|
78
|
-
// force init
|
|
79
|
-
config.args = args
|
|
80
|
-
config.env = config.env.toLowerCase()
|
|
81
|
-
if (values(envs).includes(config.env)) config.env = getKeyByValue(envs, config.env)
|
|
82
|
-
if (!keys(envs).includes(config.env)) config.env = 'dev'
|
|
83
|
-
process.env.NODE_ENV = envs[config.env]
|
|
84
|
-
if (!config.log.level) config.log.level = config.env === 'dev' ? 'debug' : 'info'
|
|
85
|
-
if (config.silent) config.log.level = 'silent'
|
|
86
|
-
// sanitize plugins
|
|
87
|
-
config.plugins = without(config.plugins, 'app')
|
|
88
|
-
// if (fs.existsSync(`${config.dir.base}/app/bajo`)) config.plugins.push('app')
|
|
89
|
-
config.plugins.push('app')
|
|
90
|
-
config.plugins = filter(uniq(map(config.plugins, b => trim(b))), b => !isEmpty(b))
|
|
91
|
-
if (config.tool) {
|
|
92
|
-
if (!config.plugins.includes('bajo-cli')) throw error('Sidetool needs to have \'bajo-cli\' package loaded first')
|
|
93
|
-
if (!config.log.tool) config.log.level = 'silent'
|
|
94
|
-
config.exitHandler = false
|
|
95
|
-
}
|
|
96
|
-
this.bajo.config = config
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export default buildConfig
|
package/boot/create-scope.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module boot/createScope
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { isFunction } from 'lodash-es'
|
|
6
|
-
import readJson from './helper/read-json.js'
|
|
7
|
-
import importModule from './helper/import-module.js'
|
|
8
|
-
|
|
9
|
-
async function defHandler (file) {
|
|
10
|
-
let mod = await importModule(file)
|
|
11
|
-
if (isFunction(mod)) mod = await mod.call(this)
|
|
12
|
-
return mod
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const configHandlers = [
|
|
16
|
-
{ ext: '.js', handler: defHandler },
|
|
17
|
-
{ ext: '.mjs', handler: defHandler },
|
|
18
|
-
{ ext: '.json', handler: readJson }
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
const bajo = {
|
|
22
|
-
runAt: new Date(),
|
|
23
|
-
configHandlers
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @instance
|
|
28
|
-
* @async
|
|
29
|
-
* @returns {Object} scope
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
function createScope () {
|
|
33
|
-
return { bajo }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default createScope
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isEmpty, find } from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
function breakNsPath (item = '', defaultNs = 'bajo') {
|
|
4
|
-
const { error } = this.bajo.helper
|
|
5
|
-
let [ns, ...path] = item.split(':')
|
|
6
|
-
path = path.join(':')
|
|
7
|
-
if (isEmpty(path)) {
|
|
8
|
-
path = ns
|
|
9
|
-
ns = defaultNs
|
|
10
|
-
}
|
|
11
|
-
if (ns.length === 1) return [ns, path].join(':') // windows fs
|
|
12
|
-
if (!this[ns]) {
|
|
13
|
-
const ref = find(this.bajo.pluginRefs ?? [], { alias: ns })
|
|
14
|
-
if (ref) ns = ref.plugin
|
|
15
|
-
}
|
|
16
|
-
if (!this[ns]) throw error('Unknown plugin \'%s\' or plugin isn\'t loaded yet', ns)
|
|
17
|
-
return [ns, path]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default breakNsPath
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { filter, isArray, each, pullAt, camelCase, has, find, set, get, cloneDeep } from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
async function buildCollections (options = {}) {
|
|
4
|
-
const { getConfig, getPluginName, fatal, runHook, error, join } = this.bajo.helper
|
|
5
|
-
let { plugin, handler, dupChecks = [], container = 'connections', useDefaultName } = options
|
|
6
|
-
useDefaultName = useDefaultName ?? true
|
|
7
|
-
if (!plugin) plugin = getPluginName(4)
|
|
8
|
-
const config = getConfig()
|
|
9
|
-
const cfg = getConfig(plugin, { full: true })
|
|
10
|
-
let data = get(cfg, container)
|
|
11
|
-
if (!data) return []
|
|
12
|
-
if (!isArray(data)) data = [data]
|
|
13
|
-
await runHook(`${plugin}:${camelCase(`before build ${container}`)}`)
|
|
14
|
-
const deleted = []
|
|
15
|
-
for (const index in data) {
|
|
16
|
-
const item = data[index]
|
|
17
|
-
if (config.tool && item.skipOnTool) continue
|
|
18
|
-
if (useDefaultName) {
|
|
19
|
-
if (!has(item, 'name')) {
|
|
20
|
-
if (find(data, { name: 'default' })) throw error('Collection \'default\' already exists')
|
|
21
|
-
else item.name = 'default'
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const result = await handler.call(this, { item, index, cfg })
|
|
25
|
-
if (result) data[index] = result
|
|
26
|
-
else if (result === false) deleted.push(index)
|
|
27
|
-
if (config.tool && item.skipOnTool && !deleted.includes(index)) deleted.push(index)
|
|
28
|
-
}
|
|
29
|
-
if (deleted.length > 0) pullAt(data, deleted)
|
|
30
|
-
|
|
31
|
-
// check for duplicity
|
|
32
|
-
each(data, c => {
|
|
33
|
-
each(dupChecks, d => {
|
|
34
|
-
const checker = set({}, d, c[d])
|
|
35
|
-
const match = filter(data, checker)
|
|
36
|
-
if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, join(dupChecks))
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
|
|
40
|
-
set(cfg, container, data)
|
|
41
|
-
return cloneDeep(data)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default buildCollections
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { isString, isFunction, keys, camelCase, kebabCase, snakeCase } from 'lodash-es'
|
|
3
|
-
import pascalCase from './pascal-case.js'
|
|
4
|
-
const converter = { camelCase, kebabCase, snakeCase, pascalCase }
|
|
5
|
-
|
|
6
|
-
function buildName (file, options = {}) {
|
|
7
|
-
if (isString(options)) options = { base: options }
|
|
8
|
-
if (!options.base) options.base = path.dirname(file)
|
|
9
|
-
if (!keys(converter).includes(options.converter)) options.converter = 'camelCase'
|
|
10
|
-
let name = file.replace(options.base, '')
|
|
11
|
-
name = name.slice(0, name.indexOf(path.extname(name)))
|
|
12
|
-
if (isFunction(options.converter)) name = options.converter.call(this, name)
|
|
13
|
-
else name = converter[options.converter](name)
|
|
14
|
-
return name
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default buildName
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { isString, isFunction } from 'lodash-es'
|
|
2
|
-
import getHelper from './get-helper.js'
|
|
3
|
-
|
|
4
|
-
async function callHelperOrHandler (nameOrFn, ...args) {
|
|
5
|
-
let result
|
|
6
|
-
if (isString(nameOrFn)) {
|
|
7
|
-
const helper = getHelper.call(this, nameOrFn)
|
|
8
|
-
if (isFunction(helper)) result = await helper(...args)
|
|
9
|
-
} else if (isFunction(nameOrFn)) {
|
|
10
|
-
result = await nameOrFn.call(this, ...args)
|
|
11
|
-
}
|
|
12
|
-
return result
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default callHelperOrHandler
|
package/boot/helper/dump.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import util from 'util'
|
|
2
|
-
import { last } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
const dump = (...args) => {
|
|
5
|
-
const terminate = last(args) === true
|
|
6
|
-
if (terminate) args.pop()
|
|
7
|
-
for (const arg of args) {
|
|
8
|
-
const result = util.inspect(arg, false, null, true)
|
|
9
|
-
console.log(result)
|
|
10
|
-
}
|
|
11
|
-
if (terminate) process.kill(process.pid, 'SIGINT')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default dump
|