bajo 0.3.10 → 1.0.2
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 +5 -6
- 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/get-global-module-path.js +189 -0
- 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 +54 -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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// based on global-modules-path, patching it to work on Node LTS
|
|
2
|
+
import { spawnSync } from 'child_process'
|
|
3
|
+
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
|
|
7
|
+
const supportedPlatforms = [
|
|
8
|
+
'win32',
|
|
9
|
+
'linux',
|
|
10
|
+
'darwin'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
const nodeModulesDirName = 'node_modules'
|
|
14
|
+
|
|
15
|
+
const getNpmExecutable = (platform) => {
|
|
16
|
+
let npmExecutableName = 'npm'
|
|
17
|
+
if (platform === 'win32') npmExecutableName += '.cmd'
|
|
18
|
+
return npmExecutableName
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const spawnSyncWrapper = (command, commandArgs) => {
|
|
22
|
+
const result = spawnSync(command, commandArgs, { shell: true })
|
|
23
|
+
if (!result) return null
|
|
24
|
+
if (result.error) throw result.error
|
|
25
|
+
if (result.stdout) return result.stdout.toString().trim()
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getNpmPrefix = (pathToNpm) => {
|
|
30
|
+
try {
|
|
31
|
+
const npmPrefixStdout = spawnSyncWrapper(pathToNpm, ['config', 'get', 'prefix'])
|
|
32
|
+
return npmPrefixStdout && npmPrefixStdout.toString().trim()
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(err.message)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getPathFromNpmConfig = (platform, packageName) => {
|
|
41
|
+
const pathToNpm = getNpmExecutable(platform)
|
|
42
|
+
const npmConfigPrefix = getNpmPrefix(pathToNpm)
|
|
43
|
+
|
|
44
|
+
if (npmConfigPrefix) {
|
|
45
|
+
let nodeModulesPath = path.join(npmConfigPrefix, nodeModulesDirName)
|
|
46
|
+
|
|
47
|
+
if (platform !== 'win32') {
|
|
48
|
+
nodeModulesPath = path.join(npmConfigPrefix, 'lib', nodeModulesDirName)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const packagePath = path.join(nodeModulesPath, packageName)
|
|
52
|
+
const verifiedPath = getVerifiedPath(packagePath, packageName)
|
|
53
|
+
|
|
54
|
+
if (verifiedPath) {
|
|
55
|
+
return verifiedPath
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const getPathFromCmdContent = (packageName, pathToExecutable) => {
|
|
63
|
+
if (fs.existsSync(pathToExecutable)) {
|
|
64
|
+
const executableContent = fs.readFileSync(pathToExecutable).toString()
|
|
65
|
+
|
|
66
|
+
let fullPath
|
|
67
|
+
|
|
68
|
+
let windowsPathRegExp = /(%~dp0[\w\\.-]+node_modules).*?'/g
|
|
69
|
+
let match = windowsPathRegExp.exec(executableContent)
|
|
70
|
+
|
|
71
|
+
if (match && match[1]) {
|
|
72
|
+
const realPath = path.normalize(match[1].replace('%~dp0', path.dirname(pathToExecutable)))
|
|
73
|
+
fullPath = path.join(realPath, packageName)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!fullPath) {
|
|
77
|
+
windowsPathRegExp = new RegExp(`(%~dp0[\\w\\\\.-]+?${packageName})(?:\\\\|')`, 'g')
|
|
78
|
+
match = windowsPathRegExp.exec(executableContent)
|
|
79
|
+
if (match && match[1]) fullPath = path.normalize(match[1].replace('%~dp0', path.dirname(pathToExecutable)))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (fullPath) {
|
|
83
|
+
const pathToPackage = getVerifiedPath(fullPath, packageName)
|
|
84
|
+
if (pathToPackage) return pathToPackage
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const getVerifiedPath = (suggestedPath, packageName) => {
|
|
90
|
+
const pathToPackageJson = path.join(suggestedPath, 'package.json')
|
|
91
|
+
if (fs.existsSync(suggestedPath) && fs.existsSync(pathToPackageJson)) {
|
|
92
|
+
try {
|
|
93
|
+
const packageJsonContent = JSON.parse(fs.readFileSync(pathToPackageJson))
|
|
94
|
+
if (packageJsonContent.name === packageName) return suggestedPath
|
|
95
|
+
} catch (err) {
|
|
96
|
+
// do nothing
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const getPathFromExecutableNameOnWindows = (packageName, executableName) => {
|
|
102
|
+
try {
|
|
103
|
+
const whereResult = (spawnSyncWrapper('where', [executableName]) || '').split('\n')
|
|
104
|
+
for (const line of whereResult) {
|
|
105
|
+
const pathToExecutable = line && line.trim()
|
|
106
|
+
|
|
107
|
+
if (pathToExecutable) {
|
|
108
|
+
const pathToLib = path.join(path.dirname(pathToExecutable), nodeModulesDirName, packageName)
|
|
109
|
+
const verifiedPath = getVerifiedPath(pathToLib, packageName)
|
|
110
|
+
if (verifiedPath) return verifiedPath
|
|
111
|
+
const pathToExecutableFromContent = getPathFromCmdContent(packageName, pathToExecutable)
|
|
112
|
+
if (pathToExecutableFromContent) return pathToExecutableFromContent
|
|
113
|
+
|
|
114
|
+
const resolvedPath = getPathWhenExecutableIsAddedDirectlyToPath(packageName, pathToExecutable)
|
|
115
|
+
if (resolvedPath) return resolvedPath
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.error(err.message)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const getPathFromExecutableNameOnNonWindows = (packageName, executableName) => {
|
|
126
|
+
try {
|
|
127
|
+
const whichResult = spawnSyncWrapper('which', [executableName])
|
|
128
|
+
const lsLResult = spawnSyncWrapper('ls', ['-l', whichResult])
|
|
129
|
+
|
|
130
|
+
if (whichResult && lsLResult) {
|
|
131
|
+
const regex = new RegExp(`${whichResult}\\s+->\\s+(.*?)$`)
|
|
132
|
+
const match = lsLResult.match(regex)
|
|
133
|
+
|
|
134
|
+
if (match && match[1]) {
|
|
135
|
+
const pathToRealExecutable = fs.realpathSync(path.join(path.dirname(whichResult), match[1]))
|
|
136
|
+
const packagePathMatch = pathToRealExecutable.match(new RegExp(`(.*?${path.join(nodeModulesDirName, packageName)}).*$`))
|
|
137
|
+
if (packagePathMatch) {
|
|
138
|
+
const verifiedPath = getVerifiedPath(packagePathMatch[1], packageName)
|
|
139
|
+
if (verifiedPath) return verifiedPath
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return getPathWhenExecutableIsAddedDirectlyToPath(packageName, whichResult)
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
console.error(err.message)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return null
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const getPathWhenExecutableIsAddedDirectlyToPath = (packageName, executablePath) => {
|
|
153
|
+
const pathToPackageJson = path.join(path.dirname(executablePath), '..', 'package.json')
|
|
154
|
+
if (fs.existsSync(pathToPackageJson)) {
|
|
155
|
+
const packageNameFromPackageJson = JSON.parse(fs.readFileSync(pathToPackageJson)).name
|
|
156
|
+
if (packageNameFromPackageJson === packageName) return path.dirname(pathToPackageJson)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const getPath = (packageName, executableName) => {
|
|
163
|
+
const platform = process.platform
|
|
164
|
+
|
|
165
|
+
if (supportedPlatforms.indexOf(platform) === -1) {
|
|
166
|
+
throw new Error(`OS '${platform}' is not supported.'`)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let foundPath = null
|
|
170
|
+
|
|
171
|
+
if (executableName) {
|
|
172
|
+
foundPath = platform === 'win32' ?
|
|
173
|
+
getPathFromExecutableNameOnWindows(packageName, executableName) :
|
|
174
|
+
getPathFromExecutableNameOnNonWindows(packageName, executableName)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!foundPath) foundPath = getPathFromNpmConfig(platform, packageName)
|
|
178
|
+
if (foundPath) {
|
|
179
|
+
try {
|
|
180
|
+
foundPath = fs.realpathSync(foundPath)
|
|
181
|
+
} catch (err) {
|
|
182
|
+
console.error(err.message)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return foundPath
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export default getPath
|
|
@@ -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,54 @@
|
|
|
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.2",
|
|
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
|
+
"lodash-es": "^4.17.21",
|
|
39
|
+
"ms": "^2.1.3",
|
|
40
|
+
"nanoid": "^5.0.9",
|
|
41
|
+
"omit-deep": "^0.3.0",
|
|
42
|
+
"ora": "^8.1.1",
|
|
43
|
+
"outmatch": "^1.0.0",
|
|
44
|
+
"semver": "^7.6.3",
|
|
45
|
+
"sprintf-js": "^1.1.3",
|
|
46
|
+
"yargs": "^17.7.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@faker-js/faker": "^8.0.2",
|
|
50
|
+
"chai": "^4.3.7",
|
|
51
|
+
"clean-jsdoc-theme": "^4.2.7",
|
|
52
|
+
"sinon": "^15.1.2"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -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
|
-
}
|