@nitronjs/framework 0.2.22 → 0.2.24
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/cli/njs.js +5 -3
- package/lib/Console/UpdateChecker.js +31 -13
- package/package.json +1 -1
package/cli/njs.js
CHANGED
|
@@ -91,14 +91,16 @@ async function run() {
|
|
|
91
91
|
|
|
92
92
|
switch (command) {
|
|
93
93
|
case "dev": {
|
|
94
|
-
import("../lib/Console/UpdateChecker.js")
|
|
94
|
+
const { startPeriodicCheck } = await import("../lib/Console/UpdateChecker.js");
|
|
95
|
+
startPeriodicCheck();
|
|
95
96
|
const { default: Dev } = await import("../lib/Console/Commands/DevCommand.js");
|
|
96
97
|
await Dev();
|
|
97
98
|
break;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
case "start": {
|
|
101
|
-
import("../lib/Console/UpdateChecker.js")
|
|
102
|
+
const { startPeriodicCheck } = await import("../lib/Console/UpdateChecker.js");
|
|
103
|
+
startPeriodicCheck();
|
|
102
104
|
const { default: Start } = await import("../lib/Console/Commands/StartCommand.js");
|
|
103
105
|
await Start();
|
|
104
106
|
break;
|
|
@@ -181,7 +183,7 @@ async function run() {
|
|
|
181
183
|
if (exitCode !== null) {
|
|
182
184
|
const { default: checkForUpdates } = await import("../lib/Console/UpdateChecker.js");
|
|
183
185
|
await checkForUpdates();
|
|
184
|
-
process.
|
|
186
|
+
process.exitCode = exitCode;
|
|
185
187
|
}
|
|
186
188
|
} catch (error) {
|
|
187
189
|
console.error(`${COLORS.red}Error: ${error.message}${COLORS.reset}`);
|
|
@@ -49,9 +49,9 @@ function readCache(cachePath) {
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function writeCache(cachePath,
|
|
52
|
+
function writeCache(cachePath, data) {
|
|
53
53
|
try {
|
|
54
|
-
fs.writeFileSync(cachePath, JSON.stringify(
|
|
54
|
+
fs.writeFileSync(cachePath, JSON.stringify(data));
|
|
55
55
|
}
|
|
56
56
|
catch {}
|
|
57
57
|
}
|
|
@@ -73,23 +73,33 @@ async function fetchLatestVersion() {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
function stripAnsi(str) {
|
|
77
|
+
return str.replace(/\x1b\[[\d;]*m/g, "");
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
function printUpdateNotice(current, latest) {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
+
const boxWidth = 70;
|
|
82
|
+
const border = C.yellow;
|
|
83
|
+
const pad = (content, length) => content + " ".repeat(Math.max(0, length - stripAnsi(content).length));
|
|
84
|
+
|
|
85
|
+
const lines = [
|
|
86
|
+
`${border}${C.bold}!${C.reset} ${C.bold}Update available${C.reset}`,
|
|
87
|
+
"",
|
|
88
|
+
`${C.bold}Current:${C.reset} ${current}`,
|
|
89
|
+
`${C.bold}Latest:${C.reset} ${C.green}${C.bold}${latest}${C.reset}`,
|
|
90
|
+
"",
|
|
91
|
+
`${C.bold}Run:${C.reset} ${C.cyan}npm update @nitronjs/framework --save${C.reset}`
|
|
92
|
+
];
|
|
81
93
|
|
|
82
94
|
console.log();
|
|
83
|
-
console.log(`${
|
|
95
|
+
console.log(`${border}\u250C${"\u2500".repeat(boxWidth - 2)}\u2510${C.reset}`);
|
|
84
96
|
|
|
85
97
|
for (const line of lines) {
|
|
86
|
-
|
|
87
|
-
const pad = maxLen - 2 - rawLen;
|
|
88
|
-
console.log(`${C.yellow}│${C.reset} ${line}${" ".repeat(Math.max(0, pad))} ${C.yellow}│${C.reset}`);
|
|
98
|
+
console.log(`${border}\u2502${C.reset} ${pad(line, boxWidth - 4)} ${border}\u2502${C.reset}`);
|
|
89
99
|
}
|
|
90
100
|
|
|
91
|
-
console.log(`${C.
|
|
92
|
-
console.log();
|
|
101
|
+
console.log(`${border}\u2502${C.reset} ${" ".repeat(boxWidth - 4)} ${border}\u2502${C.reset}`);
|
|
102
|
+
console.log(`${border}\u2514${"\u2500".repeat(boxWidth - 2)}\u2518${C.reset}`);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
export default async function checkForUpdates() {
|
|
@@ -106,7 +116,7 @@ export default async function checkForUpdates() {
|
|
|
106
116
|
|
|
107
117
|
if (fetched) {
|
|
108
118
|
latestVersion = fetched;
|
|
109
|
-
writeCache(cachePath, fetched);
|
|
119
|
+
writeCache(cachePath, { lastCheck: Date.now(), latestVersion: fetched });
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
@@ -116,3 +126,11 @@ export default async function checkForUpdates() {
|
|
|
116
126
|
}
|
|
117
127
|
catch {}
|
|
118
128
|
}
|
|
129
|
+
|
|
130
|
+
export function startPeriodicCheck() {
|
|
131
|
+
const initial = setTimeout(() => checkForUpdates(), 10_000);
|
|
132
|
+
initial.unref();
|
|
133
|
+
|
|
134
|
+
const interval = setInterval(() => checkForUpdates(), CHECK_INTERVAL);
|
|
135
|
+
interval.unref();
|
|
136
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitronjs/framework",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.24",
|
|
4
4
|
"description": "NitronJS is a modern and extensible Node.js MVC framework built on Fastify. It focuses on clean architecture, modular structure, and developer productivity, offering built-in routing, middleware, configuration management, CLI tooling, and native React integration for scalable full-stack applications.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"njs": "./cli/njs.js"
|