@quangnv13/nonstop 1.0.12 → 1.0.14
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/dist/index.js +19 -0
- package/dist/ui.js +95 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -5,12 +5,31 @@ const config_js_1 = require("./config.js");
|
|
|
5
5
|
const logger_js_1 = require("./logger.js");
|
|
6
6
|
const runtime_js_1 = require("./runtime.js");
|
|
7
7
|
const ui_js_1 = require("./ui.js");
|
|
8
|
+
const runtime_manager_js_1 = require("./runtime-manager.js");
|
|
8
9
|
async function main() {
|
|
9
10
|
(0, config_js_1.ensureEnvExampleFile)();
|
|
10
11
|
const args = new Set(process.argv.slice(2));
|
|
11
12
|
const isBackground = args.has('--background');
|
|
13
|
+
const isStop = args.has('--stop');
|
|
12
14
|
const config = (0, config_js_1.loadConfigFromDisk)();
|
|
13
15
|
(0, config_js_1.applyConfigToProcessEnv)(config);
|
|
16
|
+
if (isStop) {
|
|
17
|
+
const status = (0, runtime_manager_js_1.getRuntimeStatus)();
|
|
18
|
+
if (status.running && status.snapshot) {
|
|
19
|
+
try {
|
|
20
|
+
const msg = (0, runtime_manager_js_1.stopBackgroundRuntime)(status.snapshot);
|
|
21
|
+
console.log(msg);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log('nonstop background runtime is not running.');
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
14
33
|
if (isBackground) {
|
|
15
34
|
const missingFields = (0, config_js_1.getMissingConfigFields)(config);
|
|
16
35
|
if (missingFields.length > 0) {
|
package/dist/ui.js
CHANGED
|
@@ -39,6 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.launchControlCenter = launchControlCenter;
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
|
+
const os = __importStar(require("os"));
|
|
43
|
+
const child_process_1 = require("child_process");
|
|
42
44
|
const readline = __importStar(require("node:readline"));
|
|
43
45
|
const promises_1 = require("node:readline/promises");
|
|
44
46
|
const node_process_1 = require("node:process");
|
|
@@ -177,11 +179,104 @@ function renderDashboardHeader(config, snapshot) {
|
|
|
177
179
|
console.log('');
|
|
178
180
|
console.log(chalk_1.default.bold.blue(' ' + t('dashboard.menu')));
|
|
179
181
|
}
|
|
182
|
+
function getCurrentVersion() {
|
|
183
|
+
try {
|
|
184
|
+
const pkgPath = path.join(__dirname, '..', 'package.json');
|
|
185
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
186
|
+
return pkg.version;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return '1.0.13';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function checkForUpdate(currentVersion) {
|
|
193
|
+
return new Promise((resolve) => {
|
|
194
|
+
const timer = setTimeout(() => {
|
|
195
|
+
resolve(null);
|
|
196
|
+
}, 4000);
|
|
197
|
+
(0, child_process_1.exec)('npm view @quangnv13/nonstop version', (error, stdout) => {
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
if (error) {
|
|
200
|
+
resolve(null);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const latest = stdout.trim();
|
|
204
|
+
if (latest && latest !== currentVersion) {
|
|
205
|
+
resolve(latest);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
resolve(null);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async function executeUpgrade(latestVersion, isVi) {
|
|
214
|
+
clearScreen();
|
|
215
|
+
console.log(titleBox(isVi ? 'Đang nâng cấp nonstop' : 'Upgrading nonstop'));
|
|
216
|
+
console.log('');
|
|
217
|
+
const platform = os.platform();
|
|
218
|
+
if (platform === 'win32') {
|
|
219
|
+
console.log(chalk_1.default.yellow(isVi
|
|
220
|
+
? ' Đang mở cửa sổ PowerShell mới để nâng cấp. Tiến trình hiện tại sẽ tự đóng...'
|
|
221
|
+
: ' Opening new PowerShell window for upgrade. Current process will exit...'));
|
|
222
|
+
const cmd = 'cmd.exe';
|
|
223
|
+
const args = [
|
|
224
|
+
'/c',
|
|
225
|
+
'start',
|
|
226
|
+
'powershell',
|
|
227
|
+
'-NoProfile',
|
|
228
|
+
'-Command',
|
|
229
|
+
`Start-Sleep -Seconds 1; Write-Host 'Đang nâng cấp @quangnv13/nonstop lên phiên bản ${latestVersion}...'; npm install -g @quangnv13/nonstop@latest; Write-Host 'Hoàn tất! Cửa sổ này sẽ tự đóng sau 3 giây...'; Start-Sleep -Seconds 3`
|
|
230
|
+
];
|
|
231
|
+
(0, child_process_1.spawn)(cmd, args, {
|
|
232
|
+
detached: true,
|
|
233
|
+
stdio: 'ignore',
|
|
234
|
+
shell: true
|
|
235
|
+
}).unref();
|
|
236
|
+
process.exit(0);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
console.log(chalk_1.default.blue(isVi ? ' Đang chạy lệnh cài đặt...' : ' Running install command...'));
|
|
240
|
+
try {
|
|
241
|
+
(0, child_process_1.execSync)('npm install -g @quangnv13/nonstop@latest', { stdio: 'inherit' });
|
|
242
|
+
console.log(chalk_1.default.green(isVi ? '\n ✓ Nâng cấp thành công! Vui lòng khởi động lại nonstop.' : '\n ✓ Upgrade successful! Please restart nonstop.'));
|
|
243
|
+
await pause();
|
|
244
|
+
process.exit(0);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
console.error(chalk_1.default.red(isVi ? '\n ❌ Lỗi nâng cấp: ' : '\n ❌ Upgrade failed: '), error);
|
|
248
|
+
await pause();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
180
252
|
async function launchControlCenter() {
|
|
181
253
|
(0, config_js_1.ensureEnvExampleFile)();
|
|
182
254
|
let config = (0, config_js_1.loadConfigFromDisk)();
|
|
183
255
|
const isTTY = process.stdin.isTTY;
|
|
184
256
|
const wasRaw = process.stdin.isRaw;
|
|
257
|
+
// 1. Kiểm tra cập nhật khi khởi chạy
|
|
258
|
+
const currentVersion = getCurrentVersion();
|
|
259
|
+
console.log(chalk_1.default.gray(`\n ${config.language === 'vi' ? 'Đang kiểm tra cập nhật' : 'Checking for updates'} (v${currentVersion})...`));
|
|
260
|
+
const latestVersion = await checkForUpdate(currentVersion);
|
|
261
|
+
if (latestVersion) {
|
|
262
|
+
clearScreen();
|
|
263
|
+
const isVi = config.language === 'vi';
|
|
264
|
+
const upgradeChoice = await runSelectionMenu(() => {
|
|
265
|
+
console.log(titleBox(isVi ? 'Có bản cập nhật mới!' : 'Update Available!'));
|
|
266
|
+
console.log('');
|
|
267
|
+
console.log(` ${isVi ? 'Phiên bản hiện tại:' : 'Current version:'} ${chalk_1.default.yellow(currentVersion)}`);
|
|
268
|
+
console.log(` ${isVi ? 'Phiên bản mới nhất:' : 'Latest version:'} ${chalk_1.default.green(latestVersion)}`);
|
|
269
|
+
console.log('');
|
|
270
|
+
console.log(chalk_1.default.bold(` ${isVi ? 'Bạn có muốn nâng cấp ngay bây giờ không?' : 'Do you want to upgrade now?'}`));
|
|
271
|
+
}, [
|
|
272
|
+
{ label: isVi ? 'Có, nâng cấp ngay' : 'Yes, upgrade now', value: true },
|
|
273
|
+
{ label: isVi ? 'Không, để sau' : 'No, skip for now', value: false }
|
|
274
|
+
], 0);
|
|
275
|
+
if (upgradeChoice) {
|
|
276
|
+
await executeUpgrade(latestVersion, isVi);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
185
280
|
try {
|
|
186
281
|
if ((0, config_js_1.getMissingConfigFields)(config).length > 0) {
|
|
187
282
|
config = await runSetupWizard(config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quangnv13/nonstop",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"preferGlobal": true,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"build": "tsc -p tsconfig.json",
|
|
42
42
|
"start": "node dist/index.js",
|
|
43
43
|
"test": "node --import tsx --test src/*.test.ts",
|
|
44
|
-
"preinstall": "node scripts/preinstall.js"
|
|
44
|
+
"preinstall": "node scripts/preinstall.js",
|
|
45
|
+
"preuninstall": "node scripts/preinstall.js"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"boxen": "^5.1.2",
|