@nexint/lumina 0.0.0-stage → 0.7.7
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/.env.example +22 -0
- package/.gitattributes +2 -0
- package/LICENSE +85 -0
- package/README.md +298 -2
- package/boot.js +227 -0
- package/config/core/core.js +25 -0
- package/config/core/framework.js +12 -0
- package/config/core/log.js +6 -0
- package/config/cosmetic/config.js +4 -0
- package/console/Restart.js +128 -0
- package/console/about.js +81 -0
- package/console/tests.js +57 -0
- package/databases/README.md +3 -0
- package/functions/README.md +3 -0
- package/functions/core/clearCache.js +34 -0
- package/functions/core/date.js +4 -0
- package/functions/core/delay.js +4 -0
- package/functions/core/dirs.js +12 -0
- package/functions/core/fatalShutdown.mjs +174 -0
- package/functions/core/getConfig.js +32 -0
- package/functions/core/gradient.js +36 -0
- package/functions/core/load.js +229 -0
- package/functions/core/log.mjs +174 -0
- package/functions/core/powerCycle.js +212 -0
- package/functions/core/update.js +78 -0
- package/index.js +65 -0
- package/package.json +28 -4
- package/plugins/README.md +3 -0
- package/preload/core/fileLog.js +124 -0
- package/preload/readline.js +8 -0
- package/start.bat +2 -0
- package/start.sh +3 -0
- package/test/sample/test.js +74 -0
- package/ver.txt +1 -0
- package/verName.txt +1 -0
package/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Small small bootstrap loader.
|
|
2
|
+
// If loading this goes wrong, you probably dont even have Node installed lol
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Safe writer
|
|
7
|
+
* Writes to stdout or stderr.
|
|
8
|
+
* @param {String} text
|
|
9
|
+
* @param {Number} [fd=1] File descriptor (1 = stdout, 2 = stderr).
|
|
10
|
+
*/
|
|
11
|
+
function safeWrite(text, fd = 1) {
|
|
12
|
+
try {
|
|
13
|
+
fs.writeSync(fd, `${text}\n`);
|
|
14
|
+
} catch {
|
|
15
|
+
// Output is unavailable. Silently continue.
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Default local time lol
|
|
21
|
+
*/
|
|
22
|
+
function timestamp() {
|
|
23
|
+
return new Date().toLocaleTimeString("en-US", {
|
|
24
|
+
hour: "numeric",
|
|
25
|
+
minute: "numeric",
|
|
26
|
+
second: "numeric"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Small logger that doesn't import external dependencies
|
|
32
|
+
* (allegedly)
|
|
33
|
+
*/
|
|
34
|
+
const log = {
|
|
35
|
+
event(text) {
|
|
36
|
+
safeWrite(`\x1b[94m[EVENT] [${timestamp()}] ${text}\x1b[0m`);
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
error(text, error) {
|
|
40
|
+
safeWrite(`\x1b[91m[ERROR] [${timestamp()}] ${text}\x1b[0m`, 2);
|
|
41
|
+
|
|
42
|
+
if (error) {
|
|
43
|
+
try {
|
|
44
|
+
safeWrite(error.stack || String(error), 2);
|
|
45
|
+
} catch {
|
|
46
|
+
safeWrite(`\x1b[91m[ERROR] [${timestamp()}] Unable to format error.\x1b[0m`, 2);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Bootstrapper that loads the files
|
|
54
|
+
* :sob:
|
|
55
|
+
*/
|
|
56
|
+
try {
|
|
57
|
+
log.event("Starting...")
|
|
58
|
+
const index = require("./boot.js");
|
|
59
|
+
module.exports = index
|
|
60
|
+
} catch (error) {
|
|
61
|
+
log.error("Loading failed.", error)
|
|
62
|
+
log.error("Check configuration deps and startup code.")
|
|
63
|
+
log.error("Code: 0x0000.")
|
|
64
|
+
process.exit(1)
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexint/lumina",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.7.7",
|
|
4
|
+
"description": "Node.js framework lol",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node index.js",
|
|
8
|
+
"test": "node --test"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "Nexint",
|
|
12
|
+
"license": "UNLICENSED",
|
|
13
|
+
"private": false,
|
|
14
|
+
"type": "commonjs",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./index.js",
|
|
17
|
+
"./core/*": "./functions/core/*.js",
|
|
18
|
+
"./core/*.mjs": "./functions/core/*.mjs",
|
|
19
|
+
"./framework": "./config/core/framework.js",
|
|
20
|
+
"./preload/*": "./preload/*.js"
|
|
21
|
+
},
|
|
22
|
+
"imports": {
|
|
23
|
+
"#config/*": "./config/*.js",
|
|
24
|
+
"#functions/*": "./functions/*.js",
|
|
25
|
+
"#functions/*.mjs": "./functions/*.mjs",
|
|
26
|
+
"#preload/*": "./preload/*.js",
|
|
27
|
+
"#console/*": "./console/*.js",
|
|
28
|
+
"#index": "./boot.js"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const { getConfig } = require("#functions/core/getConfig");
|
|
2
|
+
const { logDir } = getConfig("core/log");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const { log, forceShutdown } = require("../../functions/core/fatalShutdown.mjs");
|
|
6
|
+
const { frameName } = require("#config/core/framework");
|
|
7
|
+
|
|
8
|
+
let logFormat = process.env.PRISM_LOG_FORMAT;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let outputFileStream = {
|
|
12
|
+
/**
|
|
13
|
+
* Deliberately returns null to prevent program crashing if the output file stream does not exist.
|
|
14
|
+
* Note for future self: Do not export the original file stream. Export other stuff.
|
|
15
|
+
* @param {String} text
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
write: function (text) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Load the initial logger.
|
|
24
|
+
*/
|
|
25
|
+
const loadLogFile = async function () {
|
|
26
|
+
if (outputFileStream instanceof fs.WriteStream && !outputFileStream.destroyed) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const dirs = [logDir];
|
|
30
|
+
dirs.forEach((dir) => {
|
|
31
|
+
if (!fs.existsSync(dir)) {
|
|
32
|
+
log.event(`Creating directory: ${dir}`);
|
|
33
|
+
fs.mkdirSync(path.join(process.cwd(), dir), {
|
|
34
|
+
recursive: true
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
outputFileStream = fs.createWriteStream(path.join(process.cwd(), logDir, `${logFormat}.txt`), { 'flags': 'a' });
|
|
39
|
+
|
|
40
|
+
await new Promise((resolve, reject) => {
|
|
41
|
+
const onOpen = () => {
|
|
42
|
+
outputFileStream.off("error", onError);
|
|
43
|
+
resolve();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const onError = (err) => {
|
|
47
|
+
outputFileStream.off("open", onOpen);
|
|
48
|
+
reject(err);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
outputFileStream.once("open", onOpen);
|
|
52
|
+
outputFileStream.once("error", onError);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
outputFileStream.on("error", (err) => {
|
|
56
|
+
log.error("File logging failed:", err);
|
|
57
|
+
forceShutdown(`File Logging failed, ${frameName} is in an unstable state.`)
|
|
58
|
+
});
|
|
59
|
+
if (!process.send) {
|
|
60
|
+
outputFileStream.write(`-----------------Info-------------------\n`);
|
|
61
|
+
outputFileStream.write(`| These logs are for debug purposes. |\n`);
|
|
62
|
+
outputFileStream.write(`| Logging is optional with args. |\n`);
|
|
63
|
+
outputFileStream.write(`| Logs are turned on by default. |\n`);
|
|
64
|
+
outputFileStream.write(`----------------------------------------\n`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Log to a file
|
|
70
|
+
* @param {String} text
|
|
71
|
+
*/
|
|
72
|
+
const writeLogFile = async function (text) {
|
|
73
|
+
outputFileStream.write(`${text}\n`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
writeLogFile,
|
|
78
|
+
async execute() {
|
|
79
|
+
await loadLogFile()
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Closes the loader lol
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
async close() {
|
|
87
|
+
if (!(outputFileStream instanceof fs.WriteStream)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const stream = outputFileStream;
|
|
92
|
+
|
|
93
|
+
if (stream.writableFinished || stream.writableEnded || stream.destroyed) {
|
|
94
|
+
outputFileStream = {
|
|
95
|
+
write() {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await new Promise((resolve, reject) => {
|
|
103
|
+
const onError = (err) => {
|
|
104
|
+
stream.off("finish", onFinish);
|
|
105
|
+
reject(err);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const onFinish = () => {
|
|
109
|
+
stream.off("error", onError);
|
|
110
|
+
resolve();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
stream.once("error", onError);
|
|
114
|
+
stream.once("finish", onFinish);
|
|
115
|
+
stream.end();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
outputFileStream = {
|
|
119
|
+
write() {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
package/start.bat
ADDED
package/start.sh
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const assert = require("node:assert/strict");
|
|
2
|
+
const { log } = require("#functions/core/log.mjs");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sample test for Prism's testing infrastructure.
|
|
6
|
+
*/
|
|
7
|
+
const execute = async function () {
|
|
8
|
+
|
|
9
|
+
const start = performance.now();
|
|
10
|
+
|
|
11
|
+
// Test basic arithmetic
|
|
12
|
+
assert.equal(2 + 2, 4);
|
|
13
|
+
assert.equal(10 - 5, 5);
|
|
14
|
+
assert.equal(5 * 5, 25);
|
|
15
|
+
|
|
16
|
+
// Test boolean values
|
|
17
|
+
assert.ok(true);
|
|
18
|
+
assert.equal(false, false);
|
|
19
|
+
|
|
20
|
+
// Test objects
|
|
21
|
+
const user = {
|
|
22
|
+
name: "Miku",
|
|
23
|
+
balance: 1000
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
assert.deepEqual(user, {
|
|
27
|
+
name: "Miku",
|
|
28
|
+
balance: 1000
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Test arrays
|
|
32
|
+
const numbers = [1, 2, 3];
|
|
33
|
+
|
|
34
|
+
assert.equal(numbers.length, 3);
|
|
35
|
+
assert.deepEqual(numbers.map(n => n * 2), [2, 4, 6]);
|
|
36
|
+
|
|
37
|
+
// Test synchronous errors
|
|
38
|
+
assert.throws(() => {
|
|
39
|
+
throw new Error("Sample error");
|
|
40
|
+
}, {
|
|
41
|
+
message: "Sample error"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Test asynchronous functions
|
|
45
|
+
const asyncTest = async function () {
|
|
46
|
+
return 393939;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
assert.equal(await asyncTest(), 393939);
|
|
50
|
+
|
|
51
|
+
// Test asynchronous errors
|
|
52
|
+
await assert.rejects(async () => {
|
|
53
|
+
throw new Error("Sample async error");
|
|
54
|
+
}, {
|
|
55
|
+
message: "Sample async error"
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const elapsed = performance.now() - start;
|
|
59
|
+
|
|
60
|
+
assert.throws(() => {
|
|
61
|
+
assert.throws(() => {
|
|
62
|
+
assert.equal(1, 1);
|
|
63
|
+
});
|
|
64
|
+
}, {
|
|
65
|
+
code: "ERR_ASSERTION",
|
|
66
|
+
message: "Missing expected exception."
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
log.success(`Sample tests passed in ${elapsed.toFixed(3)}ms!`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
execute
|
|
74
|
+
}
|
package/ver.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
23
|
package/verName.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v0.7.5-dev
|