bajo 1.0.10 → 1.1.0
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/bajo/intl/en-US.json +5 -1
- package/bajo/intl/id.json +5 -1
- package/boot/class/app.js +3 -3
- package/boot/class/bajo-core/helper/boot-order.js +2 -2
- package/boot/class/bajo-core/helper/build-config.js +1 -1
- package/boot/class/bajo-core/helper/build-plugins.js +17 -4
- package/boot/class/bajo-core/method/is-valid-app.js +1 -1
- package/boot/class/bajo-core/method/is-valid-plugin.js +2 -2
- package/boot/class/bajo-core.js +2 -0
- package/boot/class/bajo-plugin/helper/attach-method.js +1 -1
- package/boot/class/bajo-plugin/helper/collect-exit-handlers.js +1 -1
- package/boot/class/bajo-plugin.js +12 -12
- package/boot/class/error.js +10 -2
- package/boot/class/log.js +5 -5
- package/boot/class/plugin.js +8 -12
- package/boot/class/print.js +15 -15
- package/package.json +1 -1
- package/boot/class/bajo-core/method/slice-string.js +0 -13
- package/boot/lib/translate.js +0 -19
package/bajo/intl/en-US.json
CHANGED
|
@@ -148,5 +148,9 @@
|
|
|
148
148
|
"or": "or",
|
|
149
149
|
"none": "none",
|
|
150
150
|
"isRequired%s": "'%s' is required",
|
|
151
|
-
"isDisabled%s": "'%s' is disabled"
|
|
151
|
+
"isDisabled%s": "'%s' is disabled",
|
|
152
|
+
"formSubmitted": "Form Submitted",
|
|
153
|
+
"formSubmittedInfo": "The form you entered has been successfully submitted and is stored securely in our system.",
|
|
154
|
+
"thankYou": "Thank you!",
|
|
155
|
+
"adminArea": "Admin Area"
|
|
152
156
|
}
|
package/bajo/intl/id.json
CHANGED
|
@@ -148,5 +148,9 @@
|
|
|
148
148
|
"or": "atau",
|
|
149
149
|
"none": "kosong",
|
|
150
150
|
"isRequired%s": "'%s' disyaratkan",
|
|
151
|
-
"isDisabled%s": "'%s' dimatikan"
|
|
151
|
+
"isDisabled%s": "'%s' dimatikan",
|
|
152
|
+
"formSubmitted": "Form Terkirim",
|
|
153
|
+
"formSubmittedInfo": "Form yang Anda masukkan telah sukses terkirim dan disimpan dengan aman di sistim kami.",
|
|
154
|
+
"thankYou": "Terima kasih!",
|
|
155
|
+
"adminArea": "Area Admin"
|
|
152
156
|
}
|
package/boot/class/app.js
CHANGED
|
@@ -28,12 +28,12 @@ class App {
|
|
|
28
28
|
this.cwd = cwd
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
addPlugin (plugin) {
|
|
31
|
+
addPlugin = (plugin) => {
|
|
32
32
|
if (this[plugin.name]) throw new Error(`Plugin '${plugin.name}' added already`)
|
|
33
33
|
this[plugin.name] = plugin
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
dump (...args) {
|
|
36
|
+
dump = (...args) => {
|
|
37
37
|
const terminate = last(args) === true
|
|
38
38
|
if (terminate) args.pop()
|
|
39
39
|
for (const arg of args) {
|
|
@@ -43,7 +43,7 @@ class App {
|
|
|
43
43
|
if (terminate) process.kill(process.pid, 'SIGINT')
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
async
|
|
46
|
+
boot = async () => {
|
|
47
47
|
// argv/args
|
|
48
48
|
const { args, argv } = await parseArgsArgv.call(this.app) ?? {}
|
|
49
49
|
this.argv = argv
|
|
@@ -16,10 +16,10 @@ async function bootOrder () {
|
|
|
16
16
|
for (let n of this.pluginPkgs) {
|
|
17
17
|
n = map(n.split(':'), m => trim(m))[0]
|
|
18
18
|
const dir = n === this.mainNs ? (`${this.dir.base}/${this.mainNs}`) : getModuleDir(n)
|
|
19
|
-
if (n !== this.mainNs && !fs.existsSync(`${dir}/
|
|
19
|
+
if (n !== this.mainNs && !fs.existsSync(`${dir}/plugin`)) throw this.error('packageNotFoundOrNotBajo%s', n)
|
|
20
20
|
norder[n] = NaN
|
|
21
21
|
try {
|
|
22
|
-
norder[n] = Number(trim(await fs.readFile(`${dir}/
|
|
22
|
+
norder[n] = Number(trim(await fs.readFile(`${dir}/plugin/.bootorder`, 'utf8')))
|
|
23
23
|
} catch (err) {}
|
|
24
24
|
}
|
|
25
25
|
const result = []
|
|
@@ -27,7 +27,7 @@ const defConfig = {
|
|
|
27
27
|
lookupOrder: [],
|
|
28
28
|
format: {
|
|
29
29
|
emptyValue: '',
|
|
30
|
-
datetime: { dateStyle: 'medium',
|
|
30
|
+
datetime: { dateStyle: 'medium', timeStyle: 'short' },
|
|
31
31
|
date: { dateStyle: 'medium' },
|
|
32
32
|
time: { timeStyle: 'short' },
|
|
33
33
|
float: { maximumFractionDigits: 2 },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import lodash from 'lodash'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import getModuleDir from '../method/get-module-dir.js'
|
|
4
|
-
import
|
|
4
|
+
import resolvePath from '../method/resolve-path.js'
|
|
5
5
|
|
|
6
6
|
const { isString, filter, map, trim, without, uniq, camelCase, isEmpty } = lodash
|
|
7
7
|
|
|
@@ -12,13 +12,26 @@ async function buildPlugins () {
|
|
|
12
12
|
if (fs.existsSync(pluginsFile)) {
|
|
13
13
|
pluginPkgs = pluginPkgs.concat(filter(map(trim(fs.readFileSync(pluginsFile, 'utf8')).split('\n'), p => trim(p)), b => !isEmpty(b)))
|
|
14
14
|
}
|
|
15
|
-
this.pluginPkgs = without(uniq(pluginPkgs), this.mainNs)
|
|
15
|
+
this.pluginPkgs = map(filter(without(uniq(pluginPkgs), this.mainNs), p => {
|
|
16
|
+
return p[0] !== '#'
|
|
17
|
+
}), p => {
|
|
18
|
+
return trim(p.split('#')[0])
|
|
19
|
+
})
|
|
16
20
|
this.pluginPkgs.push(this.mainNs)
|
|
17
21
|
for (const pkg of this.pluginPkgs) {
|
|
18
22
|
const ns = camelCase(pkg)
|
|
19
23
|
const dir = ns === this.mainNs ? (`${this.dir.base}/${this.mainNs}`) : getModuleDir.call(this, pkg)
|
|
20
|
-
if (ns !== this.mainNs && !fs.existsSync(`${dir}
|
|
21
|
-
|
|
24
|
+
if (ns !== this.mainNs && !fs.existsSync(`${dir}/plugin`)) throw new Error(`Package '${pkg}' isn't a valid Bajo package`)
|
|
25
|
+
let plugin
|
|
26
|
+
const factory = `${dir}/plugin/factory.js`
|
|
27
|
+
if (fs.existsSync(factory)) {
|
|
28
|
+
const { default: builder } = await import(resolvePath(factory, true))
|
|
29
|
+
const FactoryClass = await builder.call(this, pkg)
|
|
30
|
+
plugin = new FactoryClass()
|
|
31
|
+
if (!(plugin instanceof this.lib.BajoPlugin)) throw new Error(`Plugin package '${pkg}' should be an instance of BajoPlugin`)
|
|
32
|
+
} else {
|
|
33
|
+
plugin = new this.lib.BajoPlugin(pkg, this.app)
|
|
34
|
+
}
|
|
22
35
|
this.pluginNames.push(plugin.name)
|
|
23
36
|
this.app.addPlugin(plugin)
|
|
24
37
|
}
|
|
@@ -4,7 +4,7 @@ import resolvePath from './resolve-path.js'
|
|
|
4
4
|
const isValidApp = (dir) => {
|
|
5
5
|
if (!dir) dir = process.env.BAJOCWD
|
|
6
6
|
dir = resolvePath(dir)
|
|
7
|
-
const hasMainDir = fs.existsSync(`${dir}/main/
|
|
7
|
+
const hasMainDir = fs.existsSync(`${dir}/main/plugin`)
|
|
8
8
|
const hasPackageJson = fs.existsSync(`${dir}/package.json`)
|
|
9
9
|
return hasMainDir && hasPackageJson
|
|
10
10
|
}
|
|
@@ -4,9 +4,9 @@ import resolvePath from './resolve-path.js'
|
|
|
4
4
|
const isValidPlugin = (dir) => {
|
|
5
5
|
if (!dir) dir = process.env.BAJOCWD
|
|
6
6
|
dir = resolvePath(dir)
|
|
7
|
-
const
|
|
7
|
+
const hasPluginDir = fs.existsSync(`${dir}/plugin`)
|
|
8
8
|
const hasPackageJson = fs.existsSync(`${dir}/package.json`)
|
|
9
|
-
return
|
|
9
|
+
return hasPluginDir && hasPackageJson
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export default isValidPlugin
|
package/boot/class/bajo-core.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Plugin from './plugin.js'
|
|
2
|
+
import BajoPlugin from './bajo-plugin.js'
|
|
2
3
|
import dayjs from '../lib/dayjs.js'
|
|
3
4
|
import importModule from './bajo-core/method/import-module.js'
|
|
4
5
|
import readJson from './bajo-core/method/read-json.js'
|
|
@@ -18,6 +19,7 @@ class BajoCore extends Plugin {
|
|
|
18
19
|
this.runAt = new Date()
|
|
19
20
|
this.mainNs = 'main'
|
|
20
21
|
this.lib.dayjs = dayjs
|
|
22
|
+
this.lib.BajoPlugin = BajoPlugin
|
|
21
23
|
this.applets = []
|
|
22
24
|
this.pluginPkgs = []
|
|
23
25
|
this.pluginNames = []
|
|
@@ -6,7 +6,7 @@ async function attachMethod () {
|
|
|
6
6
|
me.bajo.log.debug('attachMethods')
|
|
7
7
|
await eachPlugins(async function ({ ns, pkgName }) {
|
|
8
8
|
const dir = ns === me.bajo.mainNs ? (`${me.bajo.dir.base}/${me.bajo.mainNs}`) : me.bajo.getModuleDir(pkgName)
|
|
9
|
-
const num = await createMethod.call(me[ns], `${dir}/
|
|
9
|
+
const num = await createMethod.call(me[ns], `${dir}/plugin/method`, pkgName)
|
|
10
10
|
me.bajo.log.trace('- %s (%d)', ns, num)
|
|
11
11
|
})
|
|
12
12
|
}
|
|
@@ -3,7 +3,7 @@ async function collectExitHandlers () {
|
|
|
3
3
|
if (!this.bajo.config.exitHandler) return
|
|
4
4
|
const nss = []
|
|
5
5
|
await eachPlugins(async function ({ ns, dir }) {
|
|
6
|
-
const mod = await importModule(`${dir}/
|
|
6
|
+
const mod = await importModule(`${dir}/plugin/exit.js`)
|
|
7
7
|
if (!mod) return undefined
|
|
8
8
|
this.app[ns].exitHandler = mod
|
|
9
9
|
nss.push(ns)
|
|
@@ -13,13 +13,13 @@ class BajoPlugin extends Plugin {
|
|
|
13
13
|
this.state = {}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
async
|
|
16
|
+
loadConfig = async () => {
|
|
17
17
|
const { log, getModuleDir, readJson, defaultsDeep } = this.app.bajo
|
|
18
18
|
log.trace('- %s', this.name)
|
|
19
19
|
const dir = this.name === this.app.bajo.mainNs ? (`${this.app.bajo.dir.base}/${this.app.bajo.mainNs}`) : getModuleDir(this.pkgName)
|
|
20
|
-
let cfg = await readAllConfigs.call(this.app, `${dir}/
|
|
21
|
-
this.alias = this.pkgName.slice(0, 5) === 'bajo-' ? this.pkgName.slice(5).toLowerCase() : this.name.toLowerCase()
|
|
22
|
-
const aliasFile = `${dir}/
|
|
20
|
+
let cfg = await readAllConfigs.call(this.app, `${dir}/plugin/config`)
|
|
21
|
+
this.alias = this.alias ?? (this.pkgName.slice(0, 5) === 'bajo-' ? this.pkgName.slice(5).toLowerCase() : this.name.toLowerCase())
|
|
22
|
+
const aliasFile = `${dir}/plugin/.alias`
|
|
23
23
|
if (fs.existsSync(aliasFile)) this.alias = fs.readFileSync(aliasFile, 'utf8')
|
|
24
24
|
this.alias = camelCase(this.alias)
|
|
25
25
|
|
|
@@ -41,19 +41,19 @@ class BajoPlugin extends Plugin {
|
|
|
41
41
|
cfg = defaultsDeep({}, omit(altCfg, omittedPluginKeys), cfg)
|
|
42
42
|
} catch (err) {}
|
|
43
43
|
const envArgv = defaultsDeep({}, omit(this.app.env[this.name] ?? {}, omittedPluginKeys) ?? {}, omit(this.app.argv[this.name] ?? {}, omittedPluginKeys) ?? {})
|
|
44
|
-
cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {})
|
|
44
|
+
cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {}, this.config ?? {})
|
|
45
45
|
this.title = this.title ?? cfg.title ?? titleize(this.alias)
|
|
46
46
|
|
|
47
|
-
this.dependencies = []
|
|
48
|
-
const depFile = `${dir}/
|
|
47
|
+
this.dependencies = this.dependencies ?? []
|
|
48
|
+
const depFile = `${dir}/plugin/.dependencies`
|
|
49
49
|
if (fs.existsSync(depFile)) this.dependencies = without(fs.readFileSync(depFile, 'utf8').split('\n').map(item => trim(item)), '')
|
|
50
50
|
this.config = omit(cfg, ['title', 'dependencies'])
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async
|
|
53
|
+
_onoff = async (item, ...args) => {
|
|
54
54
|
this.state[item] = false
|
|
55
55
|
const { runHook, importModule } = this.app.bajo
|
|
56
|
-
const mod = await importModule(`${this.dir.pkg}/
|
|
56
|
+
const mod = await importModule(`${this.dir.pkg}/plugin/${item}.js`)
|
|
57
57
|
if (mod) {
|
|
58
58
|
const text = this.print.write('plugin%s', this.print.write(item))
|
|
59
59
|
this.log.trace(text)
|
|
@@ -64,17 +64,17 @@ class BajoPlugin extends Plugin {
|
|
|
64
64
|
this.state[item] = true
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async
|
|
67
|
+
init = async () => {
|
|
68
68
|
await this._onoff('init')
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
async
|
|
71
|
+
start = async (...args) => {
|
|
72
72
|
const { freeze } = this.app.bajo
|
|
73
73
|
freeze(this.config)
|
|
74
74
|
await this._onoff('start', ...args)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
async
|
|
77
|
+
stop = async () => {
|
|
78
78
|
await this._onoff('stop')
|
|
79
79
|
}
|
|
80
80
|
}
|
package/boot/class/error.js
CHANGED
|
@@ -12,7 +12,7 @@ class BajoError {
|
|
|
12
12
|
this.write()
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
write (
|
|
15
|
+
write = () => {
|
|
16
16
|
let err
|
|
17
17
|
if (this.payload.class) err = this.payload.class(this.message)
|
|
18
18
|
else err = Error(this.message)
|
|
@@ -31,10 +31,18 @@ class BajoError {
|
|
|
31
31
|
err[key] = value
|
|
32
32
|
}
|
|
33
33
|
if (!isEmpty(values)) err.values = values
|
|
34
|
+
err.ns = this.plugin.name
|
|
35
|
+
err.orgMessage = this.orgMessage
|
|
34
36
|
return err
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
fatal = () => {
|
|
40
|
+
const err = this.write()
|
|
41
|
+
console.error(err)
|
|
42
|
+
process.kill(process.pid, 'SIGINT')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
formatErrorDetails = (value) => {
|
|
38
46
|
const { isString } = this.plugin.app.bajo.lib._
|
|
39
47
|
const result = {}
|
|
40
48
|
const me = this
|
package/boot/class/log.js
CHANGED
|
@@ -12,24 +12,24 @@ class Log {
|
|
|
12
12
|
this.format = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
init () {
|
|
15
|
+
init = () => {
|
|
16
16
|
this.bajoLog = this.plugin.app.bajo.config.log.logger ?? 'bajoLogger'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
write (text, ...args) {
|
|
19
|
+
write = (text, ...args) => {
|
|
20
20
|
return this.plugin.print.write(text, ...args)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
isExtLogger () {
|
|
23
|
+
isExtLogger = () => {
|
|
24
24
|
return this.plugin.app[this.bajoLog] && this.plugin.app[this.bajoLog].logger
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
child () {
|
|
27
|
+
child = () => {
|
|
28
28
|
if (this.isExtLogger()) return this.plugin.app[this.bajoLog].logger.child()
|
|
29
29
|
return this.plugin.app
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
formatMsg (level, ...params) {
|
|
32
|
+
formatMsg = (level, ...params) => {
|
|
33
33
|
if (this.plugin.app.bajo.config.log.level === 'silent') return
|
|
34
34
|
if (!isLogInRange.call(this.plugin.app.bajo, level)) return
|
|
35
35
|
let [data, msg, ...args] = params
|
package/boot/class/plugin.js
CHANGED
|
@@ -16,7 +16,7 @@ class Plugin {
|
|
|
16
16
|
this.exitHandler = undefined
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
getConfig (path, options = {}) {
|
|
19
|
+
getConfig = (path, options = {}) => {
|
|
20
20
|
let obj = isEmpty(path) ? this.config : get(this.config, path, options.defValue)
|
|
21
21
|
options.omit = options.omit ?? omittedPluginKeys
|
|
22
22
|
if (isPlainObject(obj) && !isEmpty(options.omit)) obj = omit(obj, options.omit)
|
|
@@ -24,30 +24,26 @@ class Plugin {
|
|
|
24
24
|
return obj
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
initLog () {
|
|
27
|
+
initLog = () => {
|
|
28
28
|
this.log = new Log(this)
|
|
29
29
|
this.log.init()
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
initPrint (opts) {
|
|
32
|
+
initPrint = (opts) => {
|
|
33
33
|
this.print = new Print(this, opts)
|
|
34
34
|
this.print.init()
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
error (msg, ...args) {
|
|
37
|
+
error = (msg, ...args) => {
|
|
38
38
|
if (!this.print) return new Error(msg, ...args)
|
|
39
39
|
const error = new BajoError(this, msg, ...args)
|
|
40
40
|
return error.write()
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
fatal (msg, ...args) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
e = error.write(true)
|
|
48
|
-
} else e = new Error(msg, ...args)
|
|
49
|
-
console.error(e)
|
|
50
|
-
process.kill(process.pid, 'SIGINT')
|
|
43
|
+
fatal = (msg, ...args) => {
|
|
44
|
+
if (!this.print) return new Error(msg, ...args)
|
|
45
|
+
const error = new BajoError(this, msg, ...args)
|
|
46
|
+
return error.fatal()
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
|
package/boot/class/print.js
CHANGED
|
@@ -18,7 +18,7 @@ class Print {
|
|
|
18
18
|
this.intl = {}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
init () {
|
|
21
|
+
init = () => {
|
|
22
22
|
for (const l of this.plugin.app.bajo.config.intl.supported) {
|
|
23
23
|
this.intl[l] = {}
|
|
24
24
|
const path = `${this.plugin.dir.pkg}/bajo/intl/${l}.json`
|
|
@@ -30,7 +30,7 @@ class Print {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
write (text, ...args) {
|
|
33
|
+
write = (text, ...args) => {
|
|
34
34
|
const opts = last(args)
|
|
35
35
|
let lang = this.plugin.app.bajo.config.lang
|
|
36
36
|
if (isPlainObject(opts)) {
|
|
@@ -67,7 +67,7 @@ class Print {
|
|
|
67
67
|
return sprintf(trans, ...params)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
setOpts (args = []) {
|
|
70
|
+
setOpts = (args = []) => {
|
|
71
71
|
const config = this.plugin.app.bajo.config
|
|
72
72
|
let opts = {}
|
|
73
73
|
if (isPlainObject(args.slice(-1)[0])) opts = args.pop()
|
|
@@ -75,7 +75,7 @@ class Print {
|
|
|
75
75
|
this.opts = defaultsDeep(opts, this.opts)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
setText (text, ...args) {
|
|
78
|
+
setText = (text, ...args) => {
|
|
79
79
|
text = this.write(text, ...args)
|
|
80
80
|
this.setOpts(args)
|
|
81
81
|
const prefixes = []
|
|
@@ -88,65 +88,65 @@ class Print {
|
|
|
88
88
|
return this
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
getElapsed (unit = 'hms') {
|
|
91
|
+
getElapsed = (unit = 'hms') => {
|
|
92
92
|
const u = unit === 'hms' ? 'second' : unit
|
|
93
93
|
const elapsed = this.plugin.app.bajo.lib.dayjs().diff(this.startTime, u)
|
|
94
94
|
return unit === 'hms' ? this.plugin.app.bajo.secToHms(elapsed) : elapsed
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
start (text, ...args) {
|
|
97
|
+
start = (text, ...args) => {
|
|
98
98
|
this.setOpts(args)
|
|
99
99
|
this.setText(text, ...args)
|
|
100
100
|
this.ora.start()
|
|
101
101
|
return this
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
stop () {
|
|
104
|
+
stop = () => {
|
|
105
105
|
this.ora.stop()
|
|
106
106
|
return this
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
succeed (text, ...args) {
|
|
109
|
+
succeed = (text, ...args) => {
|
|
110
110
|
this.setText(text, ...args)
|
|
111
111
|
this.ora.succeed()
|
|
112
112
|
return this
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
fail (text, ...args) {
|
|
115
|
+
fail = (text, ...args) => {
|
|
116
116
|
this.setText(text, ...args)
|
|
117
117
|
this.ora.fail()
|
|
118
118
|
return this
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
warn (text, ...args) {
|
|
121
|
+
warn = (text, ...args) => {
|
|
122
122
|
this.setText(text, ...args)
|
|
123
123
|
this.ora.warn()
|
|
124
124
|
return this
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
info (text, ...args) {
|
|
127
|
+
info = (text, ...args) => {
|
|
128
128
|
this.setText(text, ...args)
|
|
129
129
|
this.ora.info()
|
|
130
130
|
return this
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
clear () {
|
|
133
|
+
clear = () => {
|
|
134
134
|
this.ora.clear()
|
|
135
135
|
return this
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
render () {
|
|
138
|
+
render = () => {
|
|
139
139
|
this.ora.render()
|
|
140
140
|
return this
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
fatal (text, ...args) {
|
|
143
|
+
fatal = (text, ...args) => {
|
|
144
144
|
this.setText(text, ...args)
|
|
145
145
|
this.ora.fail()
|
|
146
146
|
process.kill(process.pid, 'SIGINT')
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
spinner () {
|
|
149
|
+
spinner = () => {
|
|
150
150
|
return new Print(this.plugin)
|
|
151
151
|
}
|
|
152
152
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
function sliceString (content, start, end) {
|
|
2
|
-
const idx1 = content.indexOf(start)
|
|
3
|
-
if (idx1 === -1) return false
|
|
4
|
-
let idx2 = content.indexOf(end)
|
|
5
|
-
if (idx2 === -1) return false
|
|
6
|
-
if (idx2 < idx1) {
|
|
7
|
-
const tmp = content.slice(idx1)
|
|
8
|
-
idx2 = tmp.indexOf(end) + idx1
|
|
9
|
-
}
|
|
10
|
-
return content.slice(idx1, idx2 + end.length)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default sliceString
|
package/boot/lib/translate.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
2
|
-
import Sprintf from 'sprintf-js'
|
|
3
|
-
const { sprintf } = Sprintf
|
|
4
|
-
const { get, isPlainObject } = lodash
|
|
5
|
-
|
|
6
|
-
function translate (instance, text, ...args) {
|
|
7
|
-
let ntext = text
|
|
8
|
-
if (text) {
|
|
9
|
-
const i18n = instance ?? get(this, 'app.bajoI18N.instance')
|
|
10
|
-
if (i18n) {
|
|
11
|
-
if (isPlainObject(args[0])) ntext = i18n.t(text, args[0])
|
|
12
|
-
else ntext = i18n.t(text, { ns: this.name, postProcess: 'sprintf', sprintf: args })
|
|
13
|
-
} else ntext = sprintf(text, ...args)
|
|
14
|
-
}
|
|
15
|
-
if (ntext === '') ntext = text
|
|
16
|
-
return ntext
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default translate
|