bajo 1.2.9 → 2.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.
Files changed (166) hide show
  1. package/.jsdoc.conf.json +6 -3
  2. package/README.md +8 -148
  3. package/class/app.js +113 -0
  4. package/{boot/class/bajo-core.js → class/bajo.js} +448 -35
  5. package/{boot/class/error.js → class/base/err.js} +29 -3
  6. package/class/base/log.js +205 -0
  7. package/class/base/plugin.js +168 -0
  8. package/class/base/print.js +272 -0
  9. package/class/helper/bajo.js +344 -0
  10. package/class/helper/plugin.js +169 -0
  11. package/{boot/class/bajo-plugin.js → class/plugin.js} +60 -3
  12. package/docs/App.html +3 -0
  13. package/docs/Bajo.html +15 -0
  14. package/docs/BasePlugin.html +5 -0
  15. package/docs/Err.html +3 -0
  16. package/docs/Log.html +3 -0
  17. package/docs/Plugin.html +3 -0
  18. package/docs/Print.html +3 -0
  19. package/docs/bitcoin.jpeg +0 -0
  20. package/docs/class_app.js.html +116 -0
  21. package/docs/class_bajo.js.html +1100 -0
  22. package/docs/class_base_err.js.html +99 -0
  23. package/docs/class_base_log.js.html +208 -0
  24. package/docs/class_base_plugin.js.html +180 -0
  25. package/docs/class_base_print.js.html +275 -0
  26. package/docs/class_helper_bajo.js.html +347 -0
  27. package/docs/class_helper_plugin.js.html +172 -0
  28. package/docs/class_plugin.js.html +121 -0
  29. package/docs/data/search.json +1 -0
  30. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  31. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  32. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  33. package/docs/global.html +3 -0
  34. package/docs/index.html +3 -0
  35. package/docs/lib_create-method.js.html +42 -0
  36. package/docs/lib_formats.js.html +68 -0
  37. package/docs/lib_log-levels.js.html +28 -0
  38. package/docs/lib_resolve-path.js.html +30 -0
  39. package/docs/lib_shim.js.html +35 -0
  40. package/docs/module-class_helper_bajo.html +3 -0
  41. package/docs/module-class_helper_plugin.html +3 -0
  42. package/docs/module-lib_create-method.html +3 -0
  43. package/docs/module-lib_formats.html +3 -0
  44. package/docs/module-lib_log-levels.html +3 -0
  45. package/docs/module-lib_resolve-path.html +3 -0
  46. package/docs/module-lib_shim.html +3 -0
  47. package/docs/scripts/core.js +726 -0
  48. package/docs/scripts/core.min.js +23 -0
  49. package/docs/scripts/resize.js +90 -0
  50. package/docs/scripts/search.js +265 -0
  51. package/docs/scripts/search.min.js +6 -0
  52. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  53. package/docs/scripts/third-party/fuse.js +9 -0
  54. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  55. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  56. package/docs/scripts/third-party/hljs-original.js +5171 -0
  57. package/docs/scripts/third-party/hljs.js +1 -0
  58. package/docs/scripts/third-party/popper.js +5 -0
  59. package/docs/scripts/third-party/tippy.js +1 -0
  60. package/docs/scripts/third-party/tocbot.js +672 -0
  61. package/docs/scripts/third-party/tocbot.min.js +1 -0
  62. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  63. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  64. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  65. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  66. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  67. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  68. package/docs/tutorial-contribution.html +3 -0
  69. package/docs/tutorial-ecosystem.html +3 -0
  70. package/docs/tutorial-getting-started.html +13 -0
  71. package/docs/tutorial-plugin-dev.html +3 -0
  72. package/docs/tutorial-user-guide.html +3 -0
  73. package/lib/create-method.js +39 -0
  74. package/{boot/lib → lib}/formats.js +28 -0
  75. package/{boot/lib → lib}/log-levels.js +16 -0
  76. package/{boot/lib → lib}/parse-args-argv.js +1 -1
  77. package/{boot/lib → lib}/resolve-path.js +12 -0
  78. package/{boot/lib → lib}/shim.js +10 -0
  79. package/misc-docs/bitcoin.jpeg +0 -0
  80. package/misc-docs/contribution.md +20 -0
  81. package/{docs → misc-docs}/ecosystem.md +41 -12
  82. package/misc-docs/getting-started.md +142 -0
  83. package/misc-docs/plugin-dev.md +0 -0
  84. package/misc-docs/toc.json +17 -0
  85. package/misc-docs/user-guide.md +1 -0
  86. package/package.json +14 -13
  87. package/bajoBook/book/doc/.metadata.json +0 -28
  88. package/bajoBook/book/doc/How-to-Make-a-Paper-Boat-564x400@2x.jpg +0 -0
  89. package/bajoBook/book/doc/pages/guides/definition.md +0 -7
  90. package/bajoBook/book/doc/pages/guides/intro.md +0 -3
  91. package/bajoBook/book/doc/pages/guides/setup.md +0 -22
  92. package/bajoBook/book/reference/.metadata.json +0 -152
  93. package/bajoBook/book/reference/concept-leadership-business-with-paper-boats.jpg +0 -0
  94. package/bajoBook/book/reference/pages/configuration/configuration-file.md +0 -52
  95. package/bajoBook/book/reference/pages/helper/break-ns-path.md +0 -24
  96. package/bajoBook/book/reference/pages/helper/build-collections.md +0 -19
  97. package/bajoBook/book/reference/pages/helper/call-helper-or-handler.md +0 -35
  98. package/bajoBook/book/reference/pages/helper/current-loc.md +0 -28
  99. package/bajoBook/book/reference/pages/helper/dayjs.md +0 -13
  100. package/bajoBook/book/reference/pages/helper/defaults-deep.md +0 -29
  101. package/bajoBook/book/reference/pages/helper/dump.md +0 -32
  102. package/bajoBook/book/reference/pages/helper/each-plugins.md +0 -24
  103. package/bajoBook/book/reference/pages/helper/envs.md +0 -11
  104. package/bajoBook/book/reference/pages/helper/error.md +0 -29
  105. package/bajoBook/book/reference/pages/helper/fatal.md +0 -18
  106. package/bajoBook/book/reference/pages/helper/freeze.md +0 -13
  107. package/bajoBook/book/reference/pages/helper/generate-id.md +0 -36
  108. package/bajoBook/book/reference/pages/helper/get-config.md +0 -27
  109. package/bajoBook/book/reference/pages/helper/get-global-module-dir.md +0 -13
  110. package/bajoBook/book/reference/pages/helper/get-helper.md +0 -13
  111. package/bajoBook/book/reference/pages/helper/get-item-by-name.md +0 -13
  112. package/bajoBook/book/reference/pages/helper/get-key-by-value.md +0 -13
  113. package/bajoBook/book/reference/pages/helper/get-module-dir.md +0 -13
  114. package/bajoBook/book/reference/pages/helper/get-plugin-data-dir.md +0 -13
  115. package/bajoBook/book/reference/pages/helper/get-plugin-name.md +0 -13
  116. package/bajoBook/book/reference/pages/helper/get-plugin.md +0 -13
  117. package/bajoBook/book/reference/pages/helper/import-module.md +0 -13
  118. package/bajoBook/book/reference/pages/helper/import-pkg.md +0 -13
  119. package/bajoBook/book/reference/pages/helper/is-empty-dir.md +0 -13
  120. package/bajoBook/book/reference/pages/helper/is-log-in-range.md +0 -13
  121. package/bajoBook/book/reference/pages/helper/is-set.md +0 -13
  122. package/bajoBook/book/reference/pages/helper/is-valid-app.md +0 -13
  123. package/bajoBook/book/reference/pages/helper/is-valid-plugin.md +0 -13
  124. package/bajoBook/book/reference/pages/helper/log-levels.md +0 -13
  125. package/bajoBook/book/reference/pages/helper/log.md +0 -13
  126. package/bajoBook/book/reference/pages/helper/paginate.md +0 -13
  127. package/bajoBook/book/reference/pages/helper/pascal-case.md +0 -13
  128. package/bajoBook/book/reference/pages/helper/print.md +0 -13
  129. package/bajoBook/book/reference/pages/helper/read-config.md +0 -13
  130. package/bajoBook/book/reference/pages/helper/read-json.md +0 -13
  131. package/bajoBook/book/reference/pages/helper/resolve-path.md +0 -13
  132. package/bajoBook/book/reference/pages/helper/resolve-tpl-path.md +0 -13
  133. package/bajoBook/book/reference/pages/helper/run-hook.md +0 -13
  134. package/bajoBook/book/reference/pages/helper/save-as-download.md +0 -13
  135. package/bajoBook/book/reference/pages/helper/titleize.md +0 -13
  136. package/bajoBook/book/reference/pages/helper/white-space.md +0 -13
  137. package/boot/class/app.js +0 -67
  138. package/boot/class/bajo-core/boot-order.js +0 -35
  139. package/boot/class/bajo-core/boot-plugins.js +0 -17
  140. package/boot/class/bajo-core/build-config.js +0 -86
  141. package/boot/class/bajo-core/build-plugins.js +0 -44
  142. package/boot/class/bajo-core/collect-config-handlers.js +0 -20
  143. package/boot/class/bajo-core/exit-handler.js +0 -53
  144. package/boot/class/bajo-core/run-as-applet.js +0 -26
  145. package/boot/class/bajo-plugin/attach-method.js +0 -14
  146. package/boot/class/bajo-plugin/build-config.js +0 -15
  147. package/boot/class/bajo-plugin/check-clash.js +0 -18
  148. package/boot/class/bajo-plugin/check-dependency.js +0 -39
  149. package/boot/class/bajo-plugin/collect-hooks.js +0 -31
  150. package/boot/class/bajo-plugin/run.js +0 -23
  151. package/boot/class/log.js +0 -96
  152. package/boot/class/plugin.js +0 -79
  153. package/boot/class/print.js +0 -153
  154. package/boot/lib/create-method.js +0 -33
  155. package/test/method/isSet.js +0 -43
  156. /package/{bajo → extend/bajo}/intl/en-US.json +0 -0
  157. /package/{bajo → extend/bajo}/intl/id.json +0 -0
  158. /package/{waibuStatic → extend/waibuStatic}/virtual.json +0 -0
  159. /package/{boot/index.js → index.js} +0 -0
  160. /package/{boot/lib → lib}/current-loc.js +0 -0
  161. /package/{boot/lib → lib}/dayjs.js +0 -0
  162. /package/{boot/lib → lib}/import-module.js +0 -0
  163. /package/{boot/lib → lib}/omitted-plugin-keys.js +0 -0
  164. /package/{boot/lib → lib}/parse-env.js +0 -0
  165. /package/{boot/lib → lib}/read-all-configs.js +0 -0
  166. /package/{docs/hook.md → misc-docs/.hook.md} +0 -0
@@ -1,153 +0,0 @@
1
- import ora from 'ora'
2
- import lodash from 'lodash'
3
- import fs from 'fs-extra'
4
- import Sprintf from 'sprintf-js'
5
- const { sprintf } = Sprintf
6
- let unknownLangWarning = false
7
-
8
- const { isString, last, isPlainObject, get, without, reverse, map } = lodash
9
-
10
- class Print {
11
- constructor (plugin, opts = {}) {
12
- this.opts = opts
13
- this.plugin = plugin
14
- this.startTime = this.plugin.app.bajo.lib.dayjs()
15
- this.setOpts()
16
- this.ora = ora(this.opts)
17
- this.intl = {}
18
- }
19
-
20
- init = () => {
21
- for (const l of this.plugin.app.bajo.config.intl.supported) {
22
- this.intl[l] = {}
23
- const path = `${this.plugin.dir.pkg}/bajo/intl/${l}.json`
24
- if (!fs.existsSync(path)) continue
25
- const trans = fs.readFileSync(path, 'utf8')
26
- try {
27
- this.intl[l] = JSON.parse(trans)
28
- } catch (err) {}
29
- }
30
- }
31
-
32
- write = (text, ...args) => {
33
- const opts = last(args)
34
- let lang = this.plugin.app.bajo.config.lang
35
- if (isPlainObject(opts)) {
36
- args.pop()
37
- if (opts.lang) lang = opts.lang
38
- }
39
- const { fallback, supported } = this.plugin.app.bajo.config.intl
40
- if (!unknownLangWarning && !supported.includes(lang)) {
41
- unknownLangWarning = true
42
- this.plugin.app.bajo.log.warn('unsupportedLangFallbackTo%s', fallback)
43
- }
44
- const plugins = reverse(without([...this.plugin.app.bajo.pluginNames], this.plugin.name))
45
- plugins.unshift(this.plugin.name)
46
- plugins.push('bajo')
47
-
48
- let trans
49
- for (const p of plugins) {
50
- const root = get(this, `plugin.app.${p}.print.intl.${lang}`, {})
51
- trans = get(root, text)
52
- if (trans) break
53
- }
54
- if (!trans) {
55
- for (const p of plugins) {
56
- const root = get(this, `plugin.app.${p}.print.intl.${fallback}`, {})
57
- trans = get(root, text)
58
- if (trans) break
59
- }
60
- }
61
- if (!trans) trans = text
62
- const params = map(args, a => {
63
- if (!isString(a)) return a
64
- return a
65
- })
66
- return sprintf(trans, ...params)
67
- }
68
-
69
- setOpts = (args = []) => {
70
- const config = this.plugin.app.bajo.config
71
- let opts = {}
72
- if (isPlainObject(args.slice(-1)[0])) opts = args.pop()
73
- this.opts.isSilent = !!(config.silent || this.opts.isSilent)
74
- this.opts = this.plugin.lib.aneka.defaultsDeep(opts, this.opts)
75
- }
76
-
77
- setText = (text, ...args) => {
78
- text = this.write(text, ...args)
79
- this.setOpts(args)
80
- const prefixes = []
81
- const texts = []
82
- if (this.opts.showDatetime) prefixes.push('[' + this.plugin.app.bajo.lib.dayjs().toISOString() + ']')
83
- if (this.opts.showCounter) texts.push('[' + this.getElapsed() + ']')
84
- if (prefixes.length > 0) this.ora.prefixText = this.ora.prefixText + prefixes.join(' ')
85
- if (texts.length > 0) text = texts.join(' ') + ' ' + text
86
- this.ora.text = text
87
- return this
88
- }
89
-
90
- getElapsed = (unit = 'hms') => {
91
- const u = unit === 'hms' ? 'second' : unit
92
- const elapsed = this.plugin.lib.dayjs().diff(this.startTime, u)
93
- return unit === 'hms' ? this.plugin.lib.aneka.secToHms(elapsed) : elapsed
94
- }
95
-
96
- start = (text, ...args) => {
97
- this.setOpts(args)
98
- this.setText(text, ...args)
99
- this.ora.start()
100
- return this
101
- }
102
-
103
- stop = () => {
104
- this.ora.stop()
105
- return this
106
- }
107
-
108
- succeed = (text, ...args) => {
109
- this.setText(text, ...args)
110
- this.ora.succeed()
111
- return this
112
- }
113
-
114
- fail = (text, ...args) => {
115
- this.setText(text, ...args)
116
- this.ora.fail()
117
- return this
118
- }
119
-
120
- warn = (text, ...args) => {
121
- this.setText(text, ...args)
122
- this.ora.warn()
123
- return this
124
- }
125
-
126
- info = (text, ...args) => {
127
- this.setText(text, ...args)
128
- this.ora.info()
129
- return this
130
- }
131
-
132
- clear = () => {
133
- this.ora.clear()
134
- return this
135
- }
136
-
137
- render = () => {
138
- this.ora.render()
139
- return this
140
- }
141
-
142
- fatal = (text, ...args) => {
143
- this.setText(text, ...args)
144
- this.ora.fail()
145
- process.kill(process.pid, 'SIGINT')
146
- }
147
-
148
- spinner = () => {
149
- return new Print(this.plugin)
150
- }
151
- }
152
-
153
- export default Print
@@ -1,33 +0,0 @@
1
- import fastGlob from 'fast-glob'
2
- import path from 'path'
3
- import lodash from 'lodash'
4
- import resolvePath from './resolve-path.js'
5
-
6
- const { camelCase, isFunction } = lodash
7
-
8
- export default async function (dir, pkg = 'bajo') {
9
- dir = resolvePath(dir)
10
- const files = await fastGlob([`!${dir}/**/_*.{js,json}`, `${dir}/**/*.{js,json}`])
11
- const me = this
12
- for (const f of files) {
13
- const ext = path.extname(f)
14
- const base = f.replace(dir, '').replace(ext, '')
15
- const name = camelCase(base)
16
- let mod
17
- if (ext === '.json') mod = this.app.bajo.readJson(f)
18
- else mod = await this.app.bajo.importModule(f)
19
- if (isFunction(mod)) {
20
- const fn = mod.bind(this)
21
- if (mod.constructor.name === 'AsyncFunction') {
22
- mod = async (...args) => {
23
- await me.app.bajo.runHook(`${me.name}.${name}:beforeExec`, ...args)
24
- const result = await fn(...args)
25
- await me.app.bajo.runHook(`${me.name}.${name}:afterExec`, result, ...args)
26
- return result
27
- }
28
- } else mod = fn
29
- }
30
- this[name] = mod
31
- }
32
- return files.length
33
- }
@@ -1,43 +0,0 @@
1
- /* global describe, context, it */
2
-
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 () {
8
- context('without argument', function () {
9
- it("should return 'false'", function () {
10
- expect(isSet()).to.equal(false)
11
- })
12
- })
13
- context("with 'null' as argument", function () {
14
- it("should return 'false'", function () {
15
- expect(isSet(null)).to.equal(false)
16
- })
17
- })
18
- context("with 'undefined' as argument", function () {
19
- it("should return 'false'", function () {
20
- expect(isSet(undefined)).to.equal(false)
21
- })
22
- })
23
- context('with any number as argument', function () {
24
- it("should return 'true'", function () {
25
- expect(isSet(faker.number.float())).to.equal(true)
26
- })
27
- })
28
- context('with any string as argument', function () {
29
- it("should return 'true'", function () {
30
- expect(isSet(faker.string.alphanumeric())).to.equal(true)
31
- })
32
- })
33
- context('with empty object as argument', function () {
34
- it("should return 'true'", function () {
35
- expect(isSet({})).to.equal(true)
36
- })
37
- })
38
- context('with non empty object as argument', function () {
39
- it("should return 'true'", function () {
40
- expect(isSet({ a: 1, b: 2 })).to.equal(true)
41
- })
42
- })
43
- })
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes