bajo 2.1.0 → 2.2.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 (99) hide show
  1. package/.github/FUNDING.yml +0 -0
  2. package/.github/workflows/repo-lockdown.yml +0 -0
  3. package/.jsdoc.conf.json +0 -0
  4. package/.mocharc.json +4 -0
  5. package/LICENSE +0 -0
  6. package/README.md +0 -0
  7. package/class/{misc → app}/log.js +8 -2
  8. package/class/app.js +63 -50
  9. package/class/bajo.js +43 -211
  10. package/class/base.js +25 -22
  11. package/class/helper/bajo.js +55 -53
  12. package/class/helper/base.js +37 -75
  13. package/class/{misc → plugin}/err.js +23 -18
  14. package/class/{misc → plugin}/print.js +7 -16
  15. package/class/plugin/tools.js +42 -0
  16. package/class/plugin.js +58 -54
  17. package/docs/App.html +0 -0
  18. package/docs/Bajo.html +0 -0
  19. package/docs/Base.html +0 -0
  20. package/docs/Err.html +0 -0
  21. package/docs/Log.html +0 -0
  22. package/docs/Plugin.html +0 -0
  23. package/docs/Print.html +0 -0
  24. package/docs/class_app.js.html +0 -0
  25. package/docs/class_bajo.js.html +0 -0
  26. package/docs/class_base.js.html +0 -0
  27. package/docs/class_helper_bajo.js.html +0 -0
  28. package/docs/class_helper_base.js.html +0 -0
  29. package/docs/class_misc_err.js.html +0 -0
  30. package/docs/class_misc_log.js.html +0 -0
  31. package/docs/class_misc_print.js.html +0 -0
  32. package/docs/class_plugin.js.html +0 -0
  33. package/docs/data/search.json +0 -0
  34. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  35. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  36. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  37. package/docs/global.html +0 -0
  38. package/docs/index.html +0 -0
  39. package/docs/index.js.html +0 -0
  40. package/docs/lib_current-loc.js.html +0 -0
  41. package/docs/lib_formats.js.html +0 -0
  42. package/docs/lib_import-module.js.html +0 -0
  43. package/docs/lib_log-levels.js.html +0 -0
  44. package/docs/lib_parse-args-argv.js.html +0 -0
  45. package/docs/lib_parse-env.js.html +0 -0
  46. package/docs/lib_resolve-path.js.html +0 -0
  47. package/docs/lib_shim.js.html +0 -0
  48. package/docs/module-Helper_Bajo.html +0 -0
  49. package/docs/module-Helper_Base.html +0 -0
  50. package/docs/module-Lib.html +0 -0
  51. package/docs/scripts/core.js +476 -477
  52. package/docs/scripts/core.min.js +0 -0
  53. package/docs/scripts/resize.js +36 -36
  54. package/docs/scripts/search.js +105 -105
  55. package/docs/scripts/search.min.js +0 -0
  56. package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
  57. package/docs/scripts/third-party/fuse.js +1 -1
  58. package/docs/scripts/third-party/hljs-line-num-original.js +282 -285
  59. package/docs/scripts/third-party/hljs-line-num.js +1 -1
  60. package/docs/scripts/third-party/hljs-original.js +1195 -1202
  61. package/docs/scripts/third-party/hljs.js +1 -1
  62. package/docs/scripts/third-party/popper.js +1 -1
  63. package/docs/scripts/third-party/tippy.js +1 -1
  64. package/docs/scripts/third-party/tocbot.js +508 -509
  65. package/docs/scripts/third-party/tocbot.min.js +0 -0
  66. package/docs/static/bitcoin.jpeg +0 -0
  67. package/docs/static/home.md +0 -0
  68. package/docs/static/logo-ecosystem.png +0 -0
  69. package/docs/static/logo.png +0 -0
  70. package/docs/styles/clean-jsdoc-theme-base.css +0 -0
  71. package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
  72. package/docs/styles/clean-jsdoc-theme-light.css +0 -0
  73. package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  74. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  75. package/docs/styles/clean-jsdoc-theme.min.css +0 -0
  76. package/extend/bajo/intl/en-US.json +10 -5
  77. package/extend/bajo/intl/id.json +10 -5
  78. package/extend/waibuStatic/virtual.json +0 -0
  79. package/index.js +9 -1
  80. package/lib/find-deep.js +24 -0
  81. package/lib/formats.js +0 -0
  82. package/lib/freeze.js +16 -0
  83. package/lib/import-module.js +5 -3
  84. package/lib/index.js +6 -0
  85. package/lib/log-levels.js +0 -0
  86. package/package.json +5 -11
  87. package/test/base.test.js +108 -0
  88. package/wiki/CHANGES.md +68 -0
  89. package/wiki/CONFIG.md +0 -0
  90. package/wiki/CONTRIBUTING.md +0 -0
  91. package/wiki/DEV_GUIDE.md +0 -0
  92. package/wiki/ECOSYSTEM.md +0 -0
  93. package/wiki/GETTING-STARTED.md +1 -1
  94. package/wiki/USER-GUIDE.md +0 -0
  95. package/lib/current-loc.js +0 -33
  96. package/lib/parse-args-argv.js +0 -80
  97. package/lib/parse-env.js +0 -50
  98. package/lib/resolve-path.js +0 -24
  99. package/lib/shim.js +0 -37
package/class/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import lodash from 'lodash'
2
- import Err from './misc/err.js'
2
+ import Err from './plugin/err.js'
3
3
 
4
4
  const { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } = lodash
5
5
 
@@ -14,39 +14,36 @@ const { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } = lodash
14
14
  * @class
15
15
  */
16
16
  class Plugin {
17
- /**
18
- * Package name, the one from package.json
19
- *
20
- * @memberof Plugin
21
- * @constant {string}
22
- */
23
- static pkgName
24
-
25
- /**
26
- * Namespace (ns) or plugin's name. Simply the camel cased version of plugin's package name
27
- *
28
- * @memberof Plugin
29
- * @constant {string}
30
- */
31
- static ns
32
-
33
- /**
34
- * Plugin alias. Derived plugin must provide its own, unique alias. If it left blank,
35
- * Bajo will provide this automatically (by using the kebab-cased version of plugin name)
36
- *
37
- * @readonly
38
- * @memberof Plugin
39
- * @type {string}
40
- */
41
- static alias = ''
42
-
43
17
  /**
44
18
  * @param {string} pkgName - Package name (the one you use in package.json)
45
19
  * @param {Object} app - App instance reference. Usefull to call app method inside a plugin
46
20
  */
47
21
  constructor (pkgName, app) {
48
- this.constructor.pkgName = pkgName
49
- this.constructor.ns = camelCase(pkgName)
22
+ /**
23
+ * Package name, the one from package.json
24
+ *
25
+ * @memberof Plugin
26
+ * @constant {string}
27
+ */
28
+ this.pkgName = pkgName
29
+
30
+ /**
31
+ * Namespace (ns) or plugin's name. Simply the camel cased version of plugin's package name
32
+ *
33
+ * @memberof Plugin
34
+ * @constant {string}
35
+ */
36
+ this.ns = camelCase(pkgName)
37
+
38
+ /**
39
+ * Plugin alias. Derived plugin must provide its own, unique alias. If it left blank,
40
+ * Bajo will provide this automatically (by using the kebab-cased version of plugin name)
41
+ *
42
+ * @readonly
43
+ * @memberof Plugin
44
+ * @type {string}
45
+ */
46
+ this.alias = null
50
47
 
51
48
  /**
52
49
  * Reference to app instance
@@ -79,6 +76,21 @@ class Plugin {
79
76
  }
80
77
  }
81
78
 
79
+ /**
80
+ * Get package info
81
+ *
82
+ * @method
83
+ * @param {string} [dir] - Package directory. Defaults to the current plugin's package dir
84
+ * @param {Array} [keys=['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo']] - Field keys to be use. Set empty to use all keys.
85
+ */
86
+ getPkgInfo = (dir, keys = ['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo']) => {
87
+ const { pick, isEmpty } = this.app.lib._
88
+ const { fs } = this.app.lib
89
+ const file = `${dir ?? this.dir.pkg}/package.json`
90
+ const pkg = fs.readJsonSync(file)
91
+ return isEmpty(keys) ? pkg : pick(pkg, keys)
92
+ }
93
+
82
94
  /**
83
95
  * Get plugin's config value
84
96
  *
@@ -127,43 +139,35 @@ class Plugin {
127
139
  }
128
140
 
129
141
  /**
130
- * Getter for plugin's package name
142
+ * Translate text and interpolate with given ```args```.
131
143
  *
132
- * @type {string}
133
- */
134
- get pkgName () {
135
- return this.constructor.pkgName
136
- }
137
-
138
- /**
139
- * Getter for plugin's ns
144
+ * Shortcut to {@link App#t} with ns parameter set to this plugin namespace.
140
145
  *
141
- * @type {string}
146
+ * @param {string} text - Text to translate
147
+ * @param {...any} params - Variables to interpolate to ```text```
148
+ * @returns {string}
142
149
  */
143
- get ns () {
144
- return this.constructor.ns
150
+ t = (text, ...params) => {
151
+ return this.app.t(this.ns, text, ...params)
145
152
  }
146
153
 
147
154
  /**
148
- * Getter for plugin's alias
155
+ * Force bind methods to self (```this```)
149
156
  *
150
- * @type {string}
157
+ * @param {string[]} names - Method's names
151
158
  */
152
- get alias () {
153
- return this.constructor.alias
159
+ selfBind (names) {
160
+ for (const name of names) {
161
+ this[name] = this[name].bind(this)
162
+ }
154
163
  }
155
164
 
156
165
  /**
157
- * Translate text and interpolate with given ```args```.
158
- *
159
- * Shortcut to {@link App#t} with ns parameter set to this plugin namespace.
160
- *
161
- * @param {string} text - Text to translate
162
- * @param {...any} params - Variables to interpolate to ```text```
163
- * @returns {string}
166
+ * Dispose internal references
164
167
  */
165
- t = (text, ...params) => {
166
- return this.app.t(this.ns, text, ...params)
168
+ dispose = () => {
169
+ this.app = null
170
+ this.config = null
167
171
  }
168
172
  }
169
173
 
package/docs/App.html CHANGED
File without changes
package/docs/Bajo.html CHANGED
File without changes
package/docs/Base.html CHANGED
File without changes
package/docs/Err.html CHANGED
File without changes
package/docs/Log.html CHANGED
File without changes
package/docs/Plugin.html CHANGED
File without changes
package/docs/Print.html CHANGED
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
File without changes
File without changes
File without changes
File without changes
package/docs/global.html CHANGED
File without changes
package/docs/index.html CHANGED
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
File without changes
File without changes
File without changes