@nexint/lumina 0.7.7 → 0.7.8
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 +158 -33
- package/boot.js +3 -2
- package/config/core/core.js +3 -1
- package/config/cosmetic/config.js +2 -2
- package/console/Restart.js +1 -1
- package/functions/core/clearCache.js +9 -0
- package/functions/core/getConfig.js +27 -3
- package/functions/core/load.js +2 -2
- package/functions/core/log.mjs +61 -9
- package/functions/core/powerCycle.js +3 -1
- package/functions/core/update.js +9 -5
- package/package.json +11 -2
- package/ver.txt +1 -1
package/README.md
CHANGED
|
@@ -12,14 +12,17 @@ Lumina is designed to be flexible and is not restricted to any particular applic
|
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
+
- Zero external runtime dependencies.
|
|
15
16
|
- Modular application architecture.
|
|
16
17
|
- Automatic and recursive module discovery.
|
|
17
18
|
- Application lifecycle management.
|
|
18
19
|
- Graceful shutdown, restarting and reloading.
|
|
20
|
+
- Selective module cache persistence.
|
|
19
21
|
- Configurable error handling policies.
|
|
20
22
|
- Integrated logging utilities.
|
|
21
23
|
- Extensible console commands.
|
|
22
24
|
- Environment variable and configuration management.
|
|
25
|
+
- Framework configuration defaults with application-specific overrides.
|
|
23
26
|
- Support for CommonJS and compatible ECMAScript modules.
|
|
24
27
|
|
|
25
28
|
## Deployments
|
|
@@ -47,7 +50,7 @@ The vast majority of code in this project is my own, however AI assisted with pe
|
|
|
47
50
|
|
|
48
51
|
This readme was primarily generated with AI.
|
|
49
52
|
|
|
50
|
-
Node.js 24 or later is recommended.
|
|
53
|
+
Node.js 24 or later is recommended. Some features may require newer versions of Node.js. Earlier versions have not been tested.
|
|
51
54
|
|
|
52
55
|
### Security
|
|
53
56
|
|
|
@@ -57,20 +60,32 @@ Only install and execute modules from trusted sources. Developers are responsibl
|
|
|
57
60
|
|
|
58
61
|
## Getting Started
|
|
59
62
|
|
|
60
|
-
Install the
|
|
63
|
+
Install the package from npm:
|
|
61
64
|
|
|
62
65
|
```sh
|
|
63
|
-
npm install
|
|
66
|
+
npm install @nexint/lumina
|
|
64
67
|
```
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
Alternatively, install the latest development release:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
npm install @nexint/lumina@dev
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Create your start file (for this example, it's `index.js`):
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
require("@nexint/lumina");
|
|
79
|
+
```
|
|
67
80
|
|
|
68
81
|
To start Lumina:
|
|
69
82
|
|
|
70
83
|
```sh
|
|
71
|
-
|
|
84
|
+
node index.js
|
|
72
85
|
```
|
|
73
86
|
|
|
87
|
+
Lumina automatically creates the required application directories upon startup. Application files and configuration are resolved relative to the current working directory.
|
|
88
|
+
|
|
74
89
|
## Integrating with Lumina
|
|
75
90
|
|
|
76
91
|
Lumina offers four primary integration mechanisms: applications, plugins, preloads and console commands.
|
|
@@ -84,7 +99,7 @@ Applications can expose lifecycle methods that Lumina invokes during startup, re
|
|
|
84
99
|
Create a file under `apps/`, such as `apps/example.js`:
|
|
85
100
|
|
|
86
101
|
```js
|
|
87
|
-
const { log } = require("
|
|
102
|
+
const { log } = require("@nexint/lumina/core/log.mjs");
|
|
88
103
|
|
|
89
104
|
module.exports = {
|
|
90
105
|
async execute() {
|
|
@@ -106,7 +121,7 @@ The following lifecycle methods are supported:
|
|
|
106
121
|
| Method | Description |
|
|
107
122
|
|---|---|
|
|
108
123
|
| `execute()` | Initializes the application. |
|
|
109
|
-
| `reload()` | Executes application-specific
|
|
124
|
+
| `reload()` | Executes application-specific refresh logic. |
|
|
110
125
|
| `close()` | Releases resources and shuts down the application. |
|
|
111
126
|
|
|
112
127
|
Developers are responsible for implementing the behaviour of each lifecycle method. For example, a web server should stop accepting connections and close its server instance when `close()` is called.
|
|
@@ -122,7 +137,7 @@ Plugins can be used to initialize services, register handlers, prepare applicati
|
|
|
122
137
|
Create a file under `plugins/`:
|
|
123
138
|
|
|
124
139
|
```js
|
|
125
|
-
const { log } = require("
|
|
140
|
+
const { log } = require("@nexint/lumina/core/log.mjs");
|
|
126
141
|
|
|
127
142
|
module.exports = {
|
|
128
143
|
async execute() {
|
|
@@ -137,7 +152,7 @@ Plugins are loaded before applications.
|
|
|
137
152
|
|
|
138
153
|
### 3. Preloads
|
|
139
154
|
|
|
140
|
-
The `preload/` directory contains modules that must be initialized before plugins and applications.
|
|
155
|
+
The `preload/` directory contains modules that must be initialized before application plugins and applications.
|
|
141
156
|
|
|
142
157
|
Preloads are particularly useful for:
|
|
143
158
|
|
|
@@ -157,7 +172,7 @@ module.exports = {
|
|
|
157
172
|
};
|
|
158
173
|
```
|
|
159
174
|
|
|
160
|
-
|
|
175
|
+
Preloads remain initialized during normal refresh and reload operations and are closed during shutdown.
|
|
161
176
|
|
|
162
177
|
### 4. Console Commands
|
|
163
178
|
|
|
@@ -166,7 +181,7 @@ Developers can extend Lumina's console interface by creating modules under `cons
|
|
|
166
181
|
Each console command exposes a `command()` method that receives the input entered into the console.
|
|
167
182
|
|
|
168
183
|
```js
|
|
169
|
-
const { log } = require("
|
|
184
|
+
const { log } = require("@nexint/lumina/core/log.mjs");
|
|
170
185
|
|
|
171
186
|
module.exports = {
|
|
172
187
|
async command(input) {
|
|
@@ -190,8 +205,10 @@ The optional `help()` method provides information about the available command.
|
|
|
190
205
|
|
|
191
206
|
Lumina separates application logic from framework functionality.
|
|
192
207
|
|
|
208
|
+
A typical application using Lumina may have the following directory structure:
|
|
209
|
+
|
|
193
210
|
```text
|
|
194
|
-
|
|
211
|
+
Application/
|
|
195
212
|
├── apps/
|
|
196
213
|
├── appHelpers/
|
|
197
214
|
├── config/
|
|
@@ -199,13 +216,12 @@ Lumina/
|
|
|
199
216
|
├── console/
|
|
200
217
|
├── databases/
|
|
201
218
|
├── functions/
|
|
202
|
-
│ └── core/
|
|
203
219
|
├── logs/
|
|
204
220
|
├── plugins/
|
|
205
221
|
├── preload/
|
|
206
222
|
├── test/
|
|
223
|
+
├── node_modules/
|
|
207
224
|
├── .env
|
|
208
|
-
├── boot.js
|
|
209
225
|
├── index.js
|
|
210
226
|
└── package.json
|
|
211
227
|
```
|
|
@@ -214,7 +230,7 @@ Lumina/
|
|
|
214
230
|
|---|---|
|
|
215
231
|
| `apps/` | Managed applications and services. |
|
|
216
232
|
| `appHelpers/` | Application-specific helper modules. |
|
|
217
|
-
| `config/` |
|
|
233
|
+
| `config/` | Application configuration and framework configuration overrides. |
|
|
218
234
|
| `console/` | Custom console commands. |
|
|
219
235
|
| `databases/` | Database-related files. |
|
|
220
236
|
| `functions/` | Shared functions and utilities. |
|
|
@@ -227,12 +243,16 @@ Lumina/
|
|
|
227
243
|
|
|
228
244
|
Lumina initializes its components in the following order:
|
|
229
245
|
|
|
230
|
-
1. Framework bootstrap and configuration.
|
|
231
|
-
2.
|
|
232
|
-
3.
|
|
233
|
-
4.
|
|
234
|
-
5. Application initialization.
|
|
235
|
-
6.
|
|
246
|
+
1. Framework bootstrap, environment and configuration loading.
|
|
247
|
+
2. Directory preparation.
|
|
248
|
+
3. Framework preload initialization.
|
|
249
|
+
4. Framework plugin initialization.
|
|
250
|
+
5. Application preload initialization.
|
|
251
|
+
6. Application plugin initialization.
|
|
252
|
+
7. Application initialization.
|
|
253
|
+
8. Initial update checking, console interface and periodic update checking, when enabled.
|
|
254
|
+
|
|
255
|
+
When running Lumina as a standalone framework, framework and application directories are treated as the same directories and are not initialized twice.
|
|
236
256
|
|
|
237
257
|
Modules within the same directory should not assume a particular loading order. Explicit dependencies should be imported directly where necessary.
|
|
238
258
|
|
|
@@ -250,25 +270,130 @@ ECMAScript modules may also be used, provided they are compatible with the Node.
|
|
|
250
270
|
|
|
251
271
|
Modules intended for automatic startup must expose an `execute()` method and must not expose a `data` property.
|
|
252
272
|
|
|
253
|
-
|
|
273
|
+
### Module Persistence
|
|
254
274
|
|
|
255
|
-
|
|
275
|
+
Modules can opt out of Lumina's cache invalidation mechanism by exporting `persist: true`.
|
|
256
276
|
|
|
257
277
|
```js
|
|
258
|
-
|
|
259
|
-
|
|
278
|
+
module.exports = {
|
|
279
|
+
persist: true
|
|
280
|
+
};
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
This is particularly useful for stateful utilities, lifecycle controllers and other modules that must retain their identity throughout the process lifetime.
|
|
284
|
+
|
|
285
|
+
Persistent modules are not removed from the CommonJS module cache during Lumina's refresh and reload operations.
|
|
286
|
+
|
|
287
|
+
Persistence does not prevent lifecycle methods from being invoked, nor does it automatically preserve the caches of a module's dependencies. Existing references to those dependencies may also remain unchanged.
|
|
288
|
+
|
|
289
|
+
A full process restart is required to reliably update persistent modules.
|
|
290
|
+
|
|
291
|
+
### Refreshing and Reloading
|
|
292
|
+
|
|
293
|
+
Lumina provides several built-in console commands for managing application lifecycles.
|
|
294
|
+
|
|
295
|
+
| Command | Description |
|
|
296
|
+
|---|---|
|
|
297
|
+
| `/refresh` | Clears selected module caches and invokes application `refresh()` methods. |
|
|
298
|
+
| `/reload` | Closes applications and plugins, clears selected module caches and initializes them again. |
|
|
299
|
+
| `/restart` | Shuts down the current instance and launches the configured restart command. |
|
|
300
|
+
| `/stop` | Shuts down the current instance. |
|
|
301
|
+
|
|
302
|
+
Refresh and reload operations may also invalidate framework module caches, allowing developers to work on Lumina itself.
|
|
303
|
+
|
|
304
|
+
Refreshing and reloading are experimental features. Existing module references may remain unchanged, and ECMAScript modules cannot be reliably reloaded through CommonJS cache invalidation.
|
|
305
|
+
|
|
306
|
+
A full restart is recommended when updating the framework, persistent modules or ECMAScript modules.
|
|
307
|
+
|
|
308
|
+
## Configuration
|
|
309
|
+
|
|
310
|
+
Lumina provides default framework configuration files. Applications may override these defaults by creating corresponding files under their own `config/` directory.
|
|
311
|
+
|
|
312
|
+
Configuration should be accessed using the `getConfig()` utility:
|
|
313
|
+
|
|
314
|
+
```js
|
|
315
|
+
const { getConfig } = require("@nexint/lumina/core/getConfig");
|
|
316
|
+
|
|
317
|
+
const { verbose, devMode } = getConfig("core/core");
|
|
260
318
|
```
|
|
261
319
|
|
|
262
|
-
|
|
320
|
+
The following built-in configurations are available:
|
|
263
321
|
|
|
264
|
-
|
|
|
322
|
+
| Configuration | Purpose |
|
|
265
323
|
|---|---|
|
|
266
|
-
|
|
|
267
|
-
|
|
|
268
|
-
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
324
|
+
| `core/core` | Framework behaviour and error handling. |
|
|
325
|
+
| `core/log` | Logging configuration. |
|
|
326
|
+
| `cosmetic/config` | Application name and version information. |
|
|
327
|
+
|
|
328
|
+
For example, an application may create `config/core/core.js`:
|
|
329
|
+
|
|
330
|
+
```js
|
|
331
|
+
module.exports = {
|
|
332
|
+
verbose: true,
|
|
333
|
+
autoUpdate: false
|
|
334
|
+
};
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Lumina merges these values with the default framework configuration. Applications do not need to copy the entire framework configuration.
|
|
338
|
+
|
|
339
|
+
Configuration merging is shallow. Overriding a nested object replaces that object rather than merging its individual properties.
|
|
340
|
+
|
|
341
|
+
The `getConfig()` utility also supports arbitrary application-specific configuration files:
|
|
342
|
+
|
|
343
|
+
```js
|
|
344
|
+
const config = getConfig("example/settings");
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Built-in configurations provide JSDoc type information for compatible editors. Application-specific configurations are dynamically resolved and are not automatically typed.
|
|
348
|
+
|
|
349
|
+
If neither a framework configuration nor an application configuration exists for the requested path, an empty object is returned.
|
|
350
|
+
|
|
351
|
+
Framework metadata can be accessed separately:
|
|
352
|
+
|
|
353
|
+
```js
|
|
354
|
+
const {
|
|
355
|
+
frameName,
|
|
356
|
+
frameVer,
|
|
357
|
+
frameID
|
|
358
|
+
} = require("@nexint/lumina/framework");
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Import Aliases
|
|
362
|
+
|
|
363
|
+
Lumina uses import aliases internally to simplify accessing shared resources without long relative paths.
|
|
364
|
+
|
|
365
|
+
Applications consuming Lumina through npm can directly access its exported modules:
|
|
366
|
+
|
|
367
|
+
```js
|
|
368
|
+
const { log } = require("@nexint/lumina/core/log.mjs");
|
|
369
|
+
const { getConfig } = require("@nexint/lumina/core/getConfig");
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Applications may also define their own import aliases in their `package.json`:
|
|
373
|
+
|
|
374
|
+
```json
|
|
375
|
+
{
|
|
376
|
+
"imports": {
|
|
377
|
+
"#config/*": "./config/*.js",
|
|
378
|
+
"#functions/core/*.mjs": "@nexint/lumina/core/*.mjs",
|
|
379
|
+
"#functions/core/*": "@nexint/lumina/core/*",
|
|
380
|
+
"#functions/*": "./functions/*.js",
|
|
381
|
+
"#preload/*": "./preload/*.js",
|
|
382
|
+
"#console/*": "./console/*.js",
|
|
383
|
+
"#apps/*": "./apps/*.js",
|
|
384
|
+
"#appHelpers/*": "./appHelpers/*.js"
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
This allows applications to use shorter imports:
|
|
390
|
+
|
|
391
|
+
```js
|
|
392
|
+
const { log } = require("#functions/core/log.mjs");
|
|
393
|
+
const { getConfig } = require("#functions/core/getConfig");
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Import aliases are scoped to the package that defines them. Lumina's internal aliases are not automatically inherited by consuming applications.
|
|
272
397
|
|
|
273
398
|
## Error Handling
|
|
274
399
|
|
package/boot.js
CHANGED
|
@@ -25,7 +25,7 @@ const { logFormat } = getConfig("core/log");
|
|
|
25
25
|
if (!process.env.PRISM_LOG_FORMAT) {
|
|
26
26
|
process.env.PRISM_LOG_FORMAT = logFormat
|
|
27
27
|
}
|
|
28
|
-
const { log } = require('#functions/core/log.mjs');
|
|
28
|
+
const { log, setReadline, print } = require('#functions/core/log.mjs');
|
|
29
29
|
|
|
30
30
|
log.event(`Loading configs...`)
|
|
31
31
|
const { autoUpdate, errorPolicy } = getConfig("core/core");
|
|
@@ -45,6 +45,7 @@ const rl = readline.createInterface({
|
|
|
45
45
|
input: process.stdin,
|
|
46
46
|
output: process.stdout
|
|
47
47
|
});
|
|
48
|
+
setReadline(rl);
|
|
48
49
|
const prompt = (query) => new Promise((resolve) => rl.question(query, resolve));
|
|
49
50
|
|
|
50
51
|
// Start loading
|
|
@@ -172,7 +173,7 @@ const main = async () => {
|
|
|
172
173
|
} else {
|
|
173
174
|
log.success(`Done in ${(elapsed / 1000).toFixed(3)} seconds!`);
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
+
print("Server is running.")
|
|
176
177
|
|
|
177
178
|
await updateCheck(true)
|
|
178
179
|
|
package/config/core/core.js
CHANGED
|
@@ -10,7 +10,9 @@ module.exports = {
|
|
|
10
10
|
verbose: false, // Extra Logging Info
|
|
11
11
|
autoUpdate: true,
|
|
12
12
|
|
|
13
|
-
restart:
|
|
13
|
+
restart: process.platform === "win32"
|
|
14
|
+
? "start start.bat"
|
|
15
|
+
: "sh start.sh", // Restart command. This would be different on a linux based system. It would be "sh start.sh".
|
|
14
16
|
// args: ['--', 'bash', '-c', "./start.sh"],
|
|
15
17
|
|
|
16
18
|
/*
|
package/console/Restart.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
'The help menu can be expanded upon by other plugins.',
|
|
29
29
|
'/info (page) - Opens a neat info menu!',
|
|
30
30
|
'This function can\'t be expanded upon by other plugins.',
|
|
31
|
-
'/reload -
|
|
31
|
+
'/reload - Reloads the entire app (nearly from scratch)',
|
|
32
32
|
'/refresh - Refreshes commands, etc.',
|
|
33
33
|
'/restart - Restarts the bot. Recommended when updating.',
|
|
34
34
|
'/rs - Mirror of /restart',
|
|
@@ -16,6 +16,15 @@ const clearDirectory = function (dir, root = process.cwd()) {
|
|
|
16
16
|
const relative = path.relative(root, filename);
|
|
17
17
|
|
|
18
18
|
if (relative.startsWith(dir + path.sep)) {
|
|
19
|
+
|
|
20
|
+
// Preserve persistent modules
|
|
21
|
+
if (require.cache[filename]?.exports?.persist === true) {
|
|
22
|
+
if (verbose) {
|
|
23
|
+
log.info(`Preserved cache for ${filename}`);
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
delete require.cache[filename];
|
|
20
29
|
|
|
21
30
|
if (verbose) {
|
|
@@ -3,9 +3,33 @@ const path = require("node:path");
|
|
|
3
3
|
const { root, frameworkDir, standalone } = require("./dirs");
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {
|
|
8
|
-
* @returns {
|
|
6
|
+
* @overload
|
|
7
|
+
* @param {"core/core"} name
|
|
8
|
+
* @returns {typeof import("../../config/core/core")}
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @overload
|
|
13
|
+
* @param {"core/log"} name
|
|
14
|
+
* @returns {typeof import("../../config/core/log")}
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @overload
|
|
19
|
+
* @param {"cosmetic/config"} name
|
|
20
|
+
* @returns {typeof import("../../config/cosmetic/config")}
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @overload
|
|
25
|
+
* @param {string} name
|
|
26
|
+
* @returns {Record<string, any>}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get configuration with application overrides.
|
|
31
|
+
* @param {string} name
|
|
32
|
+
* @returns {any}
|
|
9
33
|
*/
|
|
10
34
|
const getConfig = function (name) {
|
|
11
35
|
|
package/functions/core/load.js
CHANGED
|
@@ -202,8 +202,8 @@ const close = async function (dir, root) {
|
|
|
202
202
|
const refresh = async function (dir, root) {
|
|
203
203
|
|
|
204
204
|
const refreshHelper = async (plugin, file) => {
|
|
205
|
-
if ('
|
|
206
|
-
await plugin.
|
|
205
|
+
if ('refresh' in plugin) {
|
|
206
|
+
await plugin.refresh();
|
|
207
207
|
|
|
208
208
|
if (verbose) {
|
|
209
209
|
log.info(`Refreshed file: ${path.join(dir, file)}`);
|
package/functions/core/log.mjs
CHANGED
|
@@ -4,6 +4,58 @@ const { dateOptions } = getConfig("core/core");
|
|
|
4
4
|
import { styleText, inspect } from "node:util";
|
|
5
5
|
import { forceShutdown } from "./fatalShutdown.mjs";
|
|
6
6
|
import { writeLogFile } from "#preload/core/fileLog";
|
|
7
|
+
import { clearLine, cursorTo } from "node:readline";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @type {import("node:readline").Interface | null}
|
|
11
|
+
*/
|
|
12
|
+
let rl = null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Register the readline interface.
|
|
16
|
+
* @param {import("node:readline").Interface | null} instance
|
|
17
|
+
*/
|
|
18
|
+
const setReadline = function (instance) {
|
|
19
|
+
rl = instance;
|
|
20
|
+
|
|
21
|
+
if (instance) {
|
|
22
|
+
instance.once("close", () => {
|
|
23
|
+
if (rl === instance) {
|
|
24
|
+
if (process.stdout.isTTY) {
|
|
25
|
+
clearLine(process.stdout, 0);
|
|
26
|
+
cursorTo(process.stdout, 0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
rl = null;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Print Helper lol
|
|
37
|
+
* @param {Function} output
|
|
38
|
+
* @param {...any} args
|
|
39
|
+
*/
|
|
40
|
+
const printHelper = function (output, ...args) {
|
|
41
|
+
const interactive = rl && process.stdout.isTTY;
|
|
42
|
+
|
|
43
|
+
if (interactive) {
|
|
44
|
+
clearLine(process.stdout, 0);
|
|
45
|
+
cursorTo(process.stdout, 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
output(...args);
|
|
49
|
+
|
|
50
|
+
if (interactive) {
|
|
51
|
+
rl.prompt(true);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Helper functions
|
|
56
|
+
const print = (...args) => printHelper(console.log, ...args);
|
|
57
|
+
const printErr = (...args) => printHelper(console.error, ...args);
|
|
58
|
+
|
|
7
59
|
const DateFormatter = new Intl.DateTimeFormat(undefined, dateOptions)
|
|
8
60
|
let infoCount = 0;
|
|
9
61
|
let successCount = 0;
|
|
@@ -19,7 +71,7 @@ const log = {
|
|
|
19
71
|
* @param {String} text
|
|
20
72
|
*/
|
|
21
73
|
info: function (text) {
|
|
22
|
-
|
|
74
|
+
print(`[INFO] [${DateFormatter.format(Date.now())}] ${text}`);
|
|
23
75
|
infoCount += 1;
|
|
24
76
|
},
|
|
25
77
|
|
|
@@ -34,7 +86,7 @@ const log = {
|
|
|
34
86
|
]
|
|
35
87
|
|
|
36
88
|
for (const message of messages) {
|
|
37
|
-
|
|
89
|
+
print(styleText("greenBright", message))
|
|
38
90
|
writeLogFile(message)
|
|
39
91
|
}
|
|
40
92
|
successCount += 1;
|
|
@@ -51,7 +103,7 @@ const log = {
|
|
|
51
103
|
]
|
|
52
104
|
|
|
53
105
|
for (const message of messages) {
|
|
54
|
-
|
|
106
|
+
print(styleText("blueBright", message))
|
|
55
107
|
writeLogFile(message)
|
|
56
108
|
}
|
|
57
109
|
eventCount += 1;
|
|
@@ -68,7 +120,7 @@ const log = {
|
|
|
68
120
|
]
|
|
69
121
|
|
|
70
122
|
for (const message of messages) {
|
|
71
|
-
|
|
123
|
+
print(styleText("yellowBright", message))
|
|
72
124
|
writeLogFile(message)
|
|
73
125
|
}
|
|
74
126
|
warnCount += 1;
|
|
@@ -86,12 +138,12 @@ const log = {
|
|
|
86
138
|
]
|
|
87
139
|
|
|
88
140
|
for (const message of messages) {
|
|
89
|
-
|
|
141
|
+
printErr(styleText("redBright", message))
|
|
90
142
|
writeLogFile(message)
|
|
91
143
|
}
|
|
92
144
|
|
|
93
145
|
if (error) {
|
|
94
|
-
|
|
146
|
+
printErr(error)
|
|
95
147
|
|
|
96
148
|
const formatted = inspect(error, {
|
|
97
149
|
depth: null,
|
|
@@ -127,12 +179,12 @@ const log = {
|
|
|
127
179
|
]
|
|
128
180
|
|
|
129
181
|
for (const message of messages) {
|
|
130
|
-
|
|
182
|
+
printErr(styleText("red", message))
|
|
131
183
|
writeLogFile(message)
|
|
132
184
|
}
|
|
133
185
|
|
|
134
186
|
if (error) {
|
|
135
|
-
|
|
187
|
+
printErr(error)
|
|
136
188
|
|
|
137
189
|
const formatted = inspect(error, {
|
|
138
190
|
depth: null,
|
|
@@ -171,4 +223,4 @@ const getFatal = function () {
|
|
|
171
223
|
return fatalCount
|
|
172
224
|
}
|
|
173
225
|
|
|
174
|
-
export { log, getInfo, getSuccess, getWarn, getError, getEvent, getFatal };
|
|
226
|
+
export { log, getInfo, getSuccess, getWarn, getError, getEvent, getFatal, setReadline, print };
|
|
@@ -14,6 +14,7 @@ let otherState = null;
|
|
|
14
14
|
* @param {Boolean} exit
|
|
15
15
|
*/
|
|
16
16
|
const gracefulShutdown = async function (cause, exit) {
|
|
17
|
+
|
|
17
18
|
if (shutDownState) {
|
|
18
19
|
await log.fatal(`Additional shutdown requested during active shutdown. Escalating to forced shutdown. Cause: ${cause}`, null, 0x0004, true);
|
|
19
20
|
process.exit(1) // again, this shouldnt happen in any circumstance, but just a failsafe :)
|
|
@@ -208,5 +209,6 @@ const refreshCycle = async function (cause) {
|
|
|
208
209
|
module.exports = {
|
|
209
210
|
gracefulShutdown,
|
|
210
211
|
reload,
|
|
211
|
-
refreshCycle
|
|
212
|
+
refreshCycle,
|
|
213
|
+
persist: true
|
|
212
214
|
}
|
package/functions/core/update.js
CHANGED
|
@@ -9,13 +9,17 @@ const { frameName, frameVer, frameID, updateSource, updateURL } = require('#conf
|
|
|
9
9
|
const getUpdateVersion = async function () {
|
|
10
10
|
try {
|
|
11
11
|
// Update Versions
|
|
12
|
-
const update = await fetch(updateSource + "/ver.txt"
|
|
12
|
+
const update = await fetch(updateSource + "/ver.txt", {
|
|
13
|
+
signal: AbortSignal.timeout(5000)
|
|
14
|
+
});
|
|
13
15
|
if (!update.ok) {
|
|
14
16
|
throw new Error(`HTTP ${update.status}: ${update.statusText}`);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
// Update Version
|
|
18
|
-
const updateName = await fetch(updateSource + "/verName.txt"
|
|
20
|
+
const updateName = await fetch(updateSource + "/verName.txt", {
|
|
21
|
+
signal: AbortSignal.timeout(5000)
|
|
22
|
+
});
|
|
19
23
|
if (!updateName.ok) {
|
|
20
24
|
throw new Error(`HTTP ${updateName.status}: ${updateName.statusText}`);
|
|
21
25
|
}
|
|
@@ -55,16 +59,16 @@ const updateCheck = async function (initial) {
|
|
|
55
59
|
const [versionName, latestVersion] = check
|
|
56
60
|
|
|
57
61
|
if (frameID < latestVersion) {
|
|
58
|
-
log.warn(`You're running an outdated version of ${frameName}! (You are ${latestVersion - frameID}
|
|
62
|
+
log.warn(`You're running an outdated version of ${frameName}! (You are ${latestVersion - frameID} revisions behind)`)
|
|
59
63
|
log.warn(`Update now at ${updateURL} to make sure that ${frameName} has the latest security fixes!`)
|
|
60
64
|
if ((latestVersion - frameID) >= 5) {
|
|
61
|
-
log.warn(`You are over 5
|
|
65
|
+
log.warn(`You are over 5 revisions behind. Update to the latest version as soon as possible.`)
|
|
62
66
|
}
|
|
63
67
|
log.warn(`Current version: v${frameVer} / Latest Version: ${versionName}`)
|
|
64
68
|
} else if (latestVersion <= 0) {
|
|
65
69
|
log.warn(`This instance of ${frameName} is fetching an invalid version.`)
|
|
66
70
|
} else if (frameID > latestVersion) {
|
|
67
|
-
log.warn(`You're running an experimental version of ${frameName}! (You are ${frameID - latestVersion}
|
|
71
|
+
log.warn(`You're running an experimental version of ${frameName}! (You are ${frameID - latestVersion} revisions ahead)`)
|
|
68
72
|
log.warn(`Here be dragons!~`)
|
|
69
73
|
log.warn(`Current version: v${frameVer} / Latest Version: ${versionName}`)
|
|
70
74
|
} else if (initial) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexint/lumina",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.8",
|
|
4
4
|
"description": "Node.js framework lol",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node index.js",
|
|
8
|
-
"test": "node --test"
|
|
8
|
+
"test": "node --test",
|
|
9
|
+
"publish:dev": "npm version patch --no-git-tag-version && git add -A && git commit -m \"Development release\" && git push origin dev && npm publish --tag dev"
|
|
9
10
|
},
|
|
10
11
|
"keywords": [],
|
|
11
12
|
"author": "Nexint",
|
|
@@ -26,5 +27,13 @@
|
|
|
26
27
|
"#preload/*": "./preload/*.js",
|
|
27
28
|
"#console/*": "./console/*.js",
|
|
28
29
|
"#index": "./boot.js"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/Nexint-Labs/Lumina.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/Nexint-Labs/Lumina",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/Nexint-Labs/Lumina/issues"
|
|
29
38
|
}
|
|
30
39
|
}
|
package/ver.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
24
|