bajo 1.2.8 → 2.0.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/.jsdoc.conf.json +6 -3
- package/README.md +8 -148
- package/class/app.js +113 -0
- package/{boot/class/bajo-core.js → class/bajo.js} +449 -37
- package/{boot/class/error.js → class/base/err.js} +29 -3
- package/class/base/log.js +205 -0
- package/class/base/plugin.js +177 -0
- package/class/base/print.js +272 -0
- package/class/helper/bajo.js +344 -0
- package/class/helper/plugin.js +169 -0
- package/{boot/class/bajo-plugin.js → class/plugin.js} +60 -3
- package/docs/App.html +3 -0
- package/docs/Bajo.html +15 -0
- package/docs/BasePlugin.html +5 -0
- package/docs/Err.html +3 -0
- package/docs/Log.html +3 -0
- package/docs/Plugin.html +3 -0
- package/docs/Print.html +3 -0
- package/docs/bitcoin.jpeg +0 -0
- package/docs/class_app.js.html +116 -0
- package/docs/class_bajo.js.html +1100 -0
- package/docs/class_base_err.js.html +99 -0
- package/docs/class_base_log.js.html +208 -0
- package/docs/class_base_plugin.js.html +180 -0
- package/docs/class_base_print.js.html +275 -0
- package/docs/class_helper_bajo.js.html +347 -0
- package/docs/class_helper_plugin.js.html +172 -0
- package/docs/class_plugin.js.html +121 -0
- package/docs/data/search.json +1 -0
- 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/global.html +3 -0
- package/docs/index.html +3 -0
- package/docs/lib_create-method.js.html +42 -0
- package/docs/lib_formats.js.html +68 -0
- package/docs/lib_log-levels.js.html +28 -0
- package/docs/lib_resolve-path.js.html +30 -0
- package/docs/lib_shim.js.html +35 -0
- package/docs/module-class_helper_bajo.html +3 -0
- package/docs/module-class_helper_plugin.html +3 -0
- package/docs/module-lib_create-method.html +3 -0
- package/docs/module-lib_formats.html +3 -0
- package/docs/module-lib_log-levels.html +3 -0
- package/docs/module-lib_resolve-path.html +3 -0
- package/docs/module-lib_shim.html +3 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/tutorial-contribution.html +3 -0
- package/docs/tutorial-ecosystem.html +3 -0
- package/docs/tutorial-getting-started.html +13 -0
- package/docs/tutorial-plugin-dev.html +3 -0
- package/docs/tutorial-user-guide.html +3 -0
- package/lib/create-method.js +39 -0
- package/{boot/lib → lib}/formats.js +28 -0
- package/lib/log-levels.js +25 -0
- package/{boot/lib → lib}/parse-args-argv.js +1 -1
- package/{boot/lib → lib}/resolve-path.js +12 -0
- package/{boot/lib → lib}/shim.js +10 -0
- package/misc-docs/bitcoin.jpeg +0 -0
- package/misc-docs/contribution.md +20 -0
- package/{docs → misc-docs}/ecosystem.md +41 -12
- package/misc-docs/getting-started.md +142 -0
- package/misc-docs/plugin-dev.md +0 -0
- package/misc-docs/toc.json +17 -0
- package/misc-docs/user-guide.md +1 -0
- package/package.json +14 -12
- package/bajoBook/book/doc/.metadata.json +0 -28
- package/bajoBook/book/doc/How-to-Make-a-Paper-Boat-564x400@2x.jpg +0 -0
- package/bajoBook/book/doc/pages/guides/definition.md +0 -7
- package/bajoBook/book/doc/pages/guides/intro.md +0 -3
- package/bajoBook/book/doc/pages/guides/setup.md +0 -22
- package/bajoBook/book/reference/.metadata.json +0 -152
- package/bajoBook/book/reference/concept-leadership-business-with-paper-boats.jpg +0 -0
- package/bajoBook/book/reference/pages/configuration/configuration-file.md +0 -52
- package/bajoBook/book/reference/pages/helper/break-ns-path.md +0 -24
- package/bajoBook/book/reference/pages/helper/build-collections.md +0 -19
- package/bajoBook/book/reference/pages/helper/call-helper-or-handler.md +0 -35
- package/bajoBook/book/reference/pages/helper/current-loc.md +0 -28
- package/bajoBook/book/reference/pages/helper/dayjs.md +0 -13
- package/bajoBook/book/reference/pages/helper/defaults-deep.md +0 -29
- package/bajoBook/book/reference/pages/helper/dump.md +0 -32
- package/bajoBook/book/reference/pages/helper/each-plugins.md +0 -24
- package/bajoBook/book/reference/pages/helper/envs.md +0 -11
- package/bajoBook/book/reference/pages/helper/error.md +0 -29
- package/bajoBook/book/reference/pages/helper/fatal.md +0 -18
- package/bajoBook/book/reference/pages/helper/freeze.md +0 -13
- package/bajoBook/book/reference/pages/helper/generate-id.md +0 -36
- package/bajoBook/book/reference/pages/helper/get-config.md +0 -27
- package/bajoBook/book/reference/pages/helper/get-global-module-dir.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-helper.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-item-by-name.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-key-by-value.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-module-dir.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-plugin-data-dir.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-plugin-name.md +0 -13
- package/bajoBook/book/reference/pages/helper/get-plugin.md +0 -13
- package/bajoBook/book/reference/pages/helper/import-module.md +0 -13
- package/bajoBook/book/reference/pages/helper/import-pkg.md +0 -13
- package/bajoBook/book/reference/pages/helper/is-empty-dir.md +0 -13
- package/bajoBook/book/reference/pages/helper/is-log-in-range.md +0 -13
- package/bajoBook/book/reference/pages/helper/is-set.md +0 -13
- package/bajoBook/book/reference/pages/helper/is-valid-app.md +0 -13
- package/bajoBook/book/reference/pages/helper/is-valid-plugin.md +0 -13
- package/bajoBook/book/reference/pages/helper/log-levels.md +0 -13
- package/bajoBook/book/reference/pages/helper/log.md +0 -13
- package/bajoBook/book/reference/pages/helper/paginate.md +0 -13
- package/bajoBook/book/reference/pages/helper/pascal-case.md +0 -13
- package/bajoBook/book/reference/pages/helper/print.md +0 -13
- package/bajoBook/book/reference/pages/helper/read-config.md +0 -13
- package/bajoBook/book/reference/pages/helper/read-json.md +0 -13
- package/bajoBook/book/reference/pages/helper/resolve-path.md +0 -13
- package/bajoBook/book/reference/pages/helper/resolve-tpl-path.md +0 -13
- package/bajoBook/book/reference/pages/helper/run-hook.md +0 -13
- package/bajoBook/book/reference/pages/helper/save-as-download.md +0 -13
- package/bajoBook/book/reference/pages/helper/titleize.md +0 -13
- package/bajoBook/book/reference/pages/helper/white-space.md +0 -13
- package/boot/class/app.js +0 -67
- package/boot/class/bajo-core/boot-order.js +0 -35
- package/boot/class/bajo-core/boot-plugins.js +0 -17
- package/boot/class/bajo-core/build-config.js +0 -85
- package/boot/class/bajo-core/build-plugins.js +0 -44
- package/boot/class/bajo-core/collect-config-handlers.js +0 -20
- package/boot/class/bajo-core/exit-handler.js +0 -53
- package/boot/class/bajo-core/run-as-applet.js +0 -26
- package/boot/class/bajo-plugin/attach-method.js +0 -14
- package/boot/class/bajo-plugin/build-config.js +0 -15
- package/boot/class/bajo-plugin/check-clash.js +0 -18
- package/boot/class/bajo-plugin/check-dependency.js +0 -39
- package/boot/class/bajo-plugin/collect-hooks.js +0 -31
- package/boot/class/bajo-plugin/run.js +0 -23
- package/boot/class/log.js +0 -90
- package/boot/class/plugin.js +0 -79
- package/boot/class/print.js +0 -153
- package/boot/lib/create-method.js +0 -33
- package/boot/lib/log-levels.js +0 -1
- package/test/method/isSet.js +0 -43
- /package/{bajo → extend/bajo}/intl/en-US.json +0 -0
- /package/{bajo → extend/bajo}/intl/id.json +0 -0
- /package/{waibuStatic → extend/waibuStatic}/virtual.json +0 -0
- /package/{boot/index.js → index.js} +0 -0
- /package/{boot/lib → lib}/current-loc.js +0 -0
- /package/{boot/lib → lib}/dayjs.js +0 -0
- /package/{boot/lib → lib}/import-module.js +0 -0
- /package/{boot/lib → lib}/omitted-plugin-keys.js +0 -0
- /package/{boot/lib → lib}/parse-env.js +0 -0
- /package/{boot/lib → lib}/read-all-configs.js +0 -0
- /package/{docs/hook.md → misc-docs/.hook.md} +0 -0
package/.jsdoc.conf.json
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
"plugins": ["plugins/markdown"],
|
|
3
3
|
"opts": {
|
|
4
4
|
"encoding": "utf8",
|
|
5
|
-
"readme": "./README.md",
|
|
6
5
|
"recurse": true,
|
|
7
6
|
"verbose": true,
|
|
8
7
|
"destination": "./docs",
|
|
9
8
|
"template": "node_modules/clean-jsdoc-theme",
|
|
9
|
+
"tutorials": "./misc-docs",
|
|
10
10
|
"theme_opts": {
|
|
11
|
-
"default_theme": "
|
|
11
|
+
"default_theme": "light",
|
|
12
12
|
"display-module-header": true,
|
|
13
13
|
"title": "Bajo Framework",
|
|
14
14
|
"homepageTitle": "Bajo Framework",
|
|
15
15
|
"menu": [{
|
|
16
|
+
"title": "Bajo.app",
|
|
17
|
+
"link": "https://bajo.app"
|
|
18
|
+
}, {
|
|
16
19
|
"title": "NPM",
|
|
17
20
|
"link": "https://www.npmjs.com/package/bajo"
|
|
18
21
|
}, {
|
|
@@ -24,7 +27,7 @@
|
|
|
24
27
|
"source": {
|
|
25
28
|
"include": ["."],
|
|
26
29
|
"includePattern": ".+\\.js(doc|x)?$",
|
|
27
|
-
"exclude": ["node_modules", "
|
|
30
|
+
"exclude": ["node_modules", "docs", "test", "api-docs"]
|
|
28
31
|
},
|
|
29
32
|
"markdown": {
|
|
30
33
|
"hardwrap": false,
|
package/README.md
CHANGED
|
@@ -2,156 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
 
|
|
4
4
|
|
|
5
|
-
> <br />**Attention**: I do NOT accept any pull request at the moment, thanks
|
|
5
|
+
> <br />**Attention**: I do NOT accept any pull request at the moment, thanks! ([Why?](misc-docs/contribution.md))<br /><br />
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Documentations
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- ```<plugin>```: plugin name, which is camel cased version of package name
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
Open your terminal and type:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
$ npm install bajo
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Fire up!
|
|
26
|
-
|
|
27
|
-
Create a new empty directory, this will be your project directory or your ```<bajo-base-dir>```. Now goto your newly created directory, and type:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
$ npm init
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
You'll be asked to name your project etc. **IMPORTANT**: don't forget to mark your project as ES6 project by setting ```type``` key in your ```package.json``` to ```module```.
|
|
34
|
-
|
|
35
|
-
After completing those steps, move on the the next one: crating bajo bootstrap.
|
|
36
|
-
|
|
37
|
-
Inside your ```<bajo-base-dir>```, create the ```index.js``` file and put these lines below:
|
|
38
|
-
|
|
39
|
-
```js
|
|
40
|
-
import bajo from 'bajo'
|
|
41
|
-
await bajo.default()
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
A bajo app **ALWAYS** needs a data directory to put configuration files, etc. This
|
|
45
|
-
could be located inside or outside your ```<bajo-base-dir>```.
|
|
46
|
-
|
|
47
|
-
Lets assume you're going to put your data directory inside your ```<bajo-base-dir>```. So please
|
|
48
|
-
create a new directory called ```data``` first. After that, just type in your terminal:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
$ node index.js --dir-data=data
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Or you could utilize ```dotenv``` by creating ```.env``` file in the same directory as ```index.js```, and put this inside:
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
DIR_DATA = ./data
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Now you can omit calling node with arguments, you just need to type:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
$ node index.js
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Configuration
|
|
67
|
-
|
|
68
|
-
### General rules
|
|
69
|
-
|
|
70
|
-
- All configuration files must be placed in ```<bajo-data-dir>/config/``` subfolder
|
|
71
|
-
- Config files should be named after its plugin name
|
|
72
|
-
- File format should be in ```.json``` or ```.js``` format
|
|
73
|
-
- If ```.js``` file is used, it should be in ES6 format and should export either plain javascript object or a function (sync or async both supported)
|
|
74
|
-
- If it returns a function, this function will be called within its plugin scope and should return a plain js object
|
|
75
|
-
- Other formats (```.yml```, ```.yaml``` and ```.toml```) can also be used by installing [bajoConfig](https://github.com/ardhi/bajo-config) plugin
|
|
76
|
-
- Order of precedence: ```.js``` > ```.json``` > ```.yml``` > ```.yaml``` > ```.toml```
|
|
77
|
-
|
|
78
|
-
### Main configuration File
|
|
79
|
-
|
|
80
|
-
It should be named ```bajo.json``` with following keys:
|
|
81
|
-
|
|
82
|
-
| Key | Type | Required | Default | Description |
|
|
83
|
-
| --- | ---- | -------- | ------- | ----------- |
|
|
84
|
-
| ```env``` | ```string``` | no | ```dev``` | App environment: ```dev``` or ```prod``` |
|
|
85
|
-
| ```log``` | ```object``` | no || Logger setting |
|
|
86
|
-
| ```dateFormat``` | ```string``` | no | ```YYYY-MM-DDTHH:MM:ss.SSS[Z]```| Date format accoding to [dayjs](https://github.com/iamkun/dayjs) |
|
|
87
|
-
| ```tool``` | ```boolean``` | no | ```false``` | Set to ```true``` if you want to show log even in [tool mode](#tool-mode) |
|
|
88
|
-
| ```level``` | ```string``` | no || Set one of these: ```trace```, ```debug```, ```info```, ```warn```, ```error```, ```fatal``` and ```silent```. If it isn't set, it will auto selected based on environment |
|
|
89
|
-
| ```lang``` | ```string``` | no || Language to use. If not set, it will be auto detected |
|
|
90
|
-
| ```exitHandler``` | ```boolean``` | no | ```true``` | Set to ```false``` if you want your app **NOT** to exit gracefully |
|
|
91
|
-
|
|
92
|
-
### Installed Plugins
|
|
93
|
-
|
|
94
|
-
Plugins are what make Bajo Framework so great and flexible: they extends app features!
|
|
95
|
-
|
|
96
|
-
To use plugins:
|
|
97
|
-
|
|
98
|
-
1. Install with ```npm install <package>```
|
|
99
|
-
2. Optionally create ```<bajo-data-dir>/config/<plugin>.json``` to customize plugin settings
|
|
100
|
-
3. Open/create ```<bajo-data-dir>/config/.plugins``` and put ```<package>``` in it, line by line
|
|
101
|
-
|
|
102
|
-
Example below will load ```bajoConfig```, ```bajoLogger``` and ```bajoMqtt```:
|
|
103
|
-
|
|
104
|
-
```
|
|
105
|
-
bajo-config
|
|
106
|
-
bajo-logger
|
|
107
|
-
bajo-mqtt
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
If you later decide to NOT load one or more plugins from your app, you just need to remove those from ```.plugins``` file and restart your app.
|
|
111
|
-
|
|
112
|
-
> **Warning**: please do not confuse between ```<package>``` and ```<plugin>```. Plugin package is the name of JS package listed on npm, while plugin name is the name of a plugin - a camel cased version of plugin package
|
|
113
|
-
|
|
114
|
-
### Configuration Overrides
|
|
115
|
-
|
|
116
|
-
You can override ANY settings on ANY configuration files with dotenv variables and program's argument switches easily.
|
|
117
|
-
|
|
118
|
-
Order of importance: dotenv variable > args switches > config files
|
|
119
|
-
|
|
120
|
-
#### dotenv
|
|
121
|
-
|
|
122
|
-
- Create/open ```<bajo-base-dir>/.env```
|
|
123
|
-
- Use ```__``` (double underscores) as the replacement of the dot in object
|
|
124
|
-
- ```DIR__DATA```: Set ```<bajo-data-dir>``` data directory
|
|
125
|
-
- ```DIR__TMP```: Set ```<bajo-tmp-dir>``` temp directory
|
|
126
|
-
- For every key in ```bajo.json```, use its snake cased, upper cased version, e.g:
|
|
127
|
-
- ```env``` => ```ENV```
|
|
128
|
-
- ```log.dateFormat``` => ```LOG__DATE_FORMAT```
|
|
129
|
-
- ```exitHandler``` => ```EXIT_HANDLER```
|
|
130
|
-
- To override plugins config, prepend every key in plugin config with snake cased, upper cased version of the plugin name followed by a dot, e.g:
|
|
131
|
-
- ```key``` in ```myPlugin``` => ```MY_PLUGIN.KEY```
|
|
132
|
-
- ```key.subKey.subSubKey``` in ```myPlugin``` => ```MY_PLUGIN.KEY__SUB_KEY__SUB_SUB_KEY```
|
|
133
|
-
|
|
134
|
-
#### Program argument switches
|
|
135
|
-
- Execute with switches, e.g: ```node index.js --xxx=one --yyy=two```
|
|
136
|
-
- Every switches must be prefixed with ```--```
|
|
137
|
-
- Use ```-``` as the replacement of the dot in object
|
|
138
|
-
- ```--dir-data```: Set ```<bajo-data-dir>``` data directory
|
|
139
|
-
- ```--dir-tmp```: Set ```<bajo-tmp-dir>``` temp directory
|
|
140
|
-
- For every key in ```bajo.json```, add prefix ```--``` e.g:
|
|
141
|
-
- ```env``` => ```--env=prod```
|
|
142
|
-
- ```log.dateFormat``` => ```--log-dateFormat=xxx```
|
|
143
|
-
- ```exitHandler``` => ```--exitHandler```
|
|
144
|
-
- To override plugins config, prepend every key in plugin config with the plugin name followed by a ```:```, e.g:
|
|
145
|
-
- ```key``` in ```myPlugin``` => ```--myPlugin:key```
|
|
146
|
-
- ```key.subKey.subSubKey``` in ```myPlugin``` => ```--myPlugin:key-subKey-subSubKey```
|
|
147
|
-
|
|
148
|
-
## More Documentations
|
|
149
|
-
|
|
150
|
-
- [Tutorial](docs/tutorial.md)
|
|
151
|
-
- [User Guide](docs/user-guide.md)
|
|
152
|
-
- [Plugin Development](docs/plugin-dev.md)
|
|
153
|
-
- [API](docs/api.md)
|
|
154
|
-
- [Ecosystem](docs/ecosystem.md)
|
|
9
|
+
- [Getting Started](misc-docs/getting-started.md)
|
|
10
|
+
- [User Guide](misc-docs/user-guide.md)
|
|
11
|
+
- [Plugin Development](misc-docs/plugin-dev.md)
|
|
12
|
+
- [Ecosystem](misc-docs/ecosystem.md)
|
|
13
|
+
- [Contribution](misc-docs/contribution.md)
|
|
14
|
+
- [API](docs)
|
|
155
15
|
|
|
156
16
|
## License
|
|
157
17
|
|
package/class/app.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import util from 'util'
|
|
2
|
+
import lodash from 'lodash'
|
|
3
|
+
import Bajo from './bajo.js'
|
|
4
|
+
import resolvePath from '../lib/resolve-path.js'
|
|
5
|
+
import parseArgsArgv from '../lib/parse-args-argv.js'
|
|
6
|
+
import parseEnv from '../lib/parse-env.js'
|
|
7
|
+
import {
|
|
8
|
+
buildBaseConfig,
|
|
9
|
+
buildExtConfig,
|
|
10
|
+
buildPlugins,
|
|
11
|
+
collectConfigHandlers,
|
|
12
|
+
bootOrder,
|
|
13
|
+
bootPlugins,
|
|
14
|
+
exitHandler,
|
|
15
|
+
runAsApplet
|
|
16
|
+
} from './helper/bajo.js'
|
|
17
|
+
|
|
18
|
+
const { last } = lodash
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* App class. This is where everything starts, the boot process:
|
|
22
|
+
*
|
|
23
|
+
* 1. Parsing all arguments and environment values
|
|
24
|
+
* 2. Create {@link Bajo|Bajo} instance
|
|
25
|
+
* 3. Building {@link module:class/helper/bajo.buildBaseConfig|base config}
|
|
26
|
+
* 4. {@link module:class/helper/bajo.buildPlugins|Building plugins}
|
|
27
|
+
* 5. Collect all {@link module:class/helper/bajo.collectConfigHandlers|config handler}
|
|
28
|
+
* 6. Building {@link module:class/helper/bajo.buildExtConfig|extra config}
|
|
29
|
+
* 7. Setup {@link module:class/helper/bajo.bootOrder|boot order}
|
|
30
|
+
* 8. {@link module:class/helper/bajo.bootPlugins|Boot loaded plugins}
|
|
31
|
+
* 9. Attach {@link module:class/helper/bajo.exitHandler|exit handlers}
|
|
32
|
+
* 10. Finish
|
|
33
|
+
*
|
|
34
|
+
* After boot process is completed, event ```bajo:afterBootComplete``` is emitted.
|
|
35
|
+
*
|
|
36
|
+
* If app mode is ```applet```, it runs your choosen applet instead.
|
|
37
|
+
*
|
|
38
|
+
* @class
|
|
39
|
+
*/
|
|
40
|
+
class App {
|
|
41
|
+
/**
|
|
42
|
+
* Class constructor
|
|
43
|
+
*
|
|
44
|
+
* @param {string} cwd - Current working dirctory
|
|
45
|
+
*/
|
|
46
|
+
constructor (cwd) {
|
|
47
|
+
if (!cwd) cwd = process.cwd()
|
|
48
|
+
const l = last(process.argv)
|
|
49
|
+
if (l.startsWith('--cwd')) {
|
|
50
|
+
const parts = l.split('=')
|
|
51
|
+
cwd = parts[1]
|
|
52
|
+
}
|
|
53
|
+
this.dir = resolvePath(cwd)
|
|
54
|
+
process.env.APPDIR = this.dir
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Add a plugin to the app
|
|
59
|
+
*
|
|
60
|
+
* @method
|
|
61
|
+
* @param {Object} plugin - A valid bajo plugin
|
|
62
|
+
*/
|
|
63
|
+
addPlugin = (plugin) => {
|
|
64
|
+
if (this[plugin.name]) throw new Error(`Plugin '${plugin.name}' added already`)
|
|
65
|
+
this[plugin.name] = plugin
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Dumping variable on screen
|
|
70
|
+
*
|
|
71
|
+
* @method
|
|
72
|
+
* @param {...any} args - any arguments passed will be displayed on screen. If the last argument is a boolean 'true', app will quit rightaway
|
|
73
|
+
*/
|
|
74
|
+
dump = (...args) => {
|
|
75
|
+
const terminate = last(args) === true
|
|
76
|
+
if (terminate) args.pop()
|
|
77
|
+
for (const arg of args) {
|
|
78
|
+
const result = util.inspect(arg, false, null, true)
|
|
79
|
+
console.log(result)
|
|
80
|
+
}
|
|
81
|
+
if (terminate) process.kill(process.pid, 'SIGINT')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Booting the app
|
|
86
|
+
*
|
|
87
|
+
* @method
|
|
88
|
+
* @async
|
|
89
|
+
*/
|
|
90
|
+
boot = async () => {
|
|
91
|
+
// argv/args
|
|
92
|
+
const { args, argv } = await parseArgsArgv.call(this.app) ?? {}
|
|
93
|
+
this.argv = argv
|
|
94
|
+
this.args = args
|
|
95
|
+
this.env = parseEnv() ?? {}
|
|
96
|
+
|
|
97
|
+
const bajo = new Bajo(this)
|
|
98
|
+
await buildBaseConfig.call(bajo)
|
|
99
|
+
await buildPlugins.call(bajo)
|
|
100
|
+
await collectConfigHandlers.call(bajo)
|
|
101
|
+
await buildExtConfig.call(bajo)
|
|
102
|
+
await bootOrder.call(bajo)
|
|
103
|
+
await bootPlugins.call(bajo)
|
|
104
|
+
await exitHandler.call(bajo)
|
|
105
|
+
// boot complete
|
|
106
|
+
const elapsed = new Date() - bajo.runAt
|
|
107
|
+
bajo.log.info('bootCompleted%s', bajo.lib.aneka.secToHms(elapsed, true))
|
|
108
|
+
await bajo.runHook('bajo:afterBootComplete')
|
|
109
|
+
if (bajo.applet) await runAsApplet.call(bajo)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default App
|