@quangnv13/nonstop 1.0.2 → 1.0.3
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/ui.js +91 -99
- package/package.json +1 -1
package/dist/ui.js
CHANGED
|
@@ -172,67 +172,65 @@ async function launchControlCenter() {
|
|
|
172
172
|
let config = (0, config_js_1.loadConfigFromDisk)();
|
|
173
173
|
const isTTY = process.stdin.isTTY;
|
|
174
174
|
const wasRaw = process.stdin.isRaw;
|
|
175
|
+
const rl = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
175
176
|
try {
|
|
176
177
|
if ((0, config_js_1.getMissingConfigFields)(config).length > 0) {
|
|
177
|
-
config = await runSetupWizard(config);
|
|
178
|
+
config = await runSetupWizard(config, rl);
|
|
178
179
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
180
|
+
let lastSelection = 0;
|
|
181
|
+
while (true) {
|
|
182
|
+
config = (0, config_js_1.loadConfigFromDisk)();
|
|
183
|
+
const t = (0, i18n_js_1.createTranslator)(config.language);
|
|
184
|
+
const isRunning = (0, runtime_manager_js_1.getRuntimeStatus)().running;
|
|
185
|
+
const isVi = config.language === 'vi';
|
|
186
|
+
const toggleLabel = isRunning
|
|
187
|
+
? (isVi ? 'Tắt runtime nền' : 'Dừng background runtime')
|
|
188
|
+
: (isVi ? 'Bật runtime nền' : 'Chạy background runtime');
|
|
189
|
+
const options = [
|
|
190
|
+
{ label: toggleLabel, value: 'toggle' },
|
|
191
|
+
{ label: t('menu.settings'), value: 'settings' },
|
|
192
|
+
{ label: t('menu.workspaces'), value: 'workspaces' },
|
|
193
|
+
{ label: t('menu.startup'), value: 'startup' },
|
|
194
|
+
{ label: t('menu.language'), value: 'language' },
|
|
195
|
+
{ label: t('menu.logs'), value: 'logs' },
|
|
196
|
+
{ label: t('menu.exit'), value: 'exit' }
|
|
197
|
+
];
|
|
198
|
+
rl.pause();
|
|
199
|
+
const choice = await runSelectionMenu(() => renderDashboardHeader(config, (0, runtime_manager_js_1.getRuntimeStatus)().snapshot), options, lastSelection);
|
|
200
|
+
rl.resume();
|
|
201
|
+
lastSelection = options.findIndex(opt => opt.value === choice);
|
|
202
|
+
if (lastSelection < 0)
|
|
203
|
+
lastSelection = 0;
|
|
204
|
+
if (choice === 'exit')
|
|
205
|
+
break;
|
|
206
|
+
if (choice === 'toggle') {
|
|
207
|
+
await handleToggleRuntime(config, rl);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (choice === 'settings') {
|
|
211
|
+
config = await editConfig(config, rl);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (choice === 'workspaces') {
|
|
215
|
+
await manageWorkspaces(rl, config.language);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (choice === 'startup') {
|
|
219
|
+
config = await configureStartup(config, rl);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (choice === 'language') {
|
|
223
|
+
config = await switchLanguage(config, rl);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (choice === 'logs') {
|
|
227
|
+
await showRecentLogs(rl);
|
|
228
|
+
continue;
|
|
229
229
|
}
|
|
230
|
-
}
|
|
231
|
-
finally {
|
|
232
|
-
rl.close();
|
|
233
230
|
}
|
|
234
231
|
}
|
|
235
232
|
finally {
|
|
233
|
+
rl.close();
|
|
236
234
|
process.stdout.write('\u001b[?25h');
|
|
237
235
|
if (isTTY) {
|
|
238
236
|
try {
|
|
@@ -244,7 +242,8 @@ async function launchControlCenter() {
|
|
|
244
242
|
console.log(chalk_1.default.gray('Đã thoát nonstop client.'));
|
|
245
243
|
}
|
|
246
244
|
}
|
|
247
|
-
async function runSetupWizard(currentConfig) {
|
|
245
|
+
async function runSetupWizard(currentConfig, rl) {
|
|
246
|
+
rl.pause();
|
|
248
247
|
const language = await runSelectionMenu(() => {
|
|
249
248
|
console.log(titleBox('Thiết lập nonstop'));
|
|
250
249
|
console.log(chalk_1.default.gray(' Chọn ngôn ngữ / Choose language:'));
|
|
@@ -252,52 +251,39 @@ async function runSetupWizard(currentConfig) {
|
|
|
252
251
|
{ label: 'Tiếng Việt (vi)', value: 'vi' },
|
|
253
252
|
{ label: 'English (en)', value: 'en' }
|
|
254
253
|
], currentConfig.language === 'en' ? 1 : 0);
|
|
254
|
+
rl.resume();
|
|
255
255
|
const t = (0, i18n_js_1.createTranslator)(language);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
clearScreen();
|
|
257
|
+
console.log(titleBox(t('wizard.title')));
|
|
258
|
+
console.log('');
|
|
259
|
+
const telegramBotToken = await askWithDefault(rl, t('wizard.token'), currentConfig.telegramBotToken);
|
|
260
|
+
const adminUsername = await askWithDefault(rl, t('wizard.admin'), currentConfig.adminUsername);
|
|
261
|
+
const clientName = await askWithDefault(rl, t('wizard.clientName'), currentConfig.clientName);
|
|
262
|
+
rl.pause();
|
|
263
|
+
const startupMode = await runSelectionMenu(() => {
|
|
259
264
|
console.log(titleBox(t('wizard.title')));
|
|
260
|
-
console.log('');
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
(0, config_js_1.saveConfigToDisk)(nextConfig);
|
|
283
|
-
const rl2 = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
284
|
-
try {
|
|
285
|
-
clearScreen();
|
|
286
|
-
console.log(titleBox(t('wizard.title')));
|
|
287
|
-
console.log(`\n${chalk_1.default.green(t('wizard.complete'))}`);
|
|
288
|
-
await pause(rl2);
|
|
289
|
-
}
|
|
290
|
-
finally {
|
|
291
|
-
rl2.close();
|
|
292
|
-
}
|
|
293
|
-
return nextConfig;
|
|
294
|
-
}
|
|
295
|
-
finally {
|
|
296
|
-
try {
|
|
297
|
-
rl.close();
|
|
298
|
-
}
|
|
299
|
-
catch { /* already closed */ }
|
|
300
|
-
}
|
|
265
|
+
console.log(chalk_1.default.gray(` ${t('wizard.startupMode')}:`));
|
|
266
|
+
}, [
|
|
267
|
+
{ label: `Tắt (disabled)`, value: 'disabled' },
|
|
268
|
+
{ label: `Chạy nền (background)`, value: 'background' },
|
|
269
|
+
{ label: `Mở giao diện (open-ui)`, value: 'open-ui' }
|
|
270
|
+
], 0);
|
|
271
|
+
rl.resume();
|
|
272
|
+
const nextConfig = {
|
|
273
|
+
...currentConfig,
|
|
274
|
+
language,
|
|
275
|
+
telegramBotToken,
|
|
276
|
+
adminUsername,
|
|
277
|
+
telegramUsername: adminUsername,
|
|
278
|
+
clientName,
|
|
279
|
+
startupMode
|
|
280
|
+
};
|
|
281
|
+
(0, config_js_1.saveConfigToDisk)(nextConfig);
|
|
282
|
+
clearScreen();
|
|
283
|
+
console.log(titleBox(t('wizard.title')));
|
|
284
|
+
console.log(`\n${chalk_1.default.green(t('wizard.complete'))}`);
|
|
285
|
+
await pause(rl);
|
|
286
|
+
return nextConfig;
|
|
301
287
|
}
|
|
302
288
|
async function handleToggleRuntime(config, rl) {
|
|
303
289
|
const status = (0, runtime_manager_js_1.getRuntimeStatus)();
|
|
@@ -358,10 +344,12 @@ async function manageWorkspaces(rl, language) {
|
|
|
358
344
|
})),
|
|
359
345
|
{ label: isVi ? '← Quay lại menu chính' : '← Back', value: { type: 'back' } }
|
|
360
346
|
];
|
|
347
|
+
rl.pause();
|
|
361
348
|
const selection = await runSelectionMenu(() => {
|
|
362
349
|
console.log(titleBox(isVi ? 'Quản lý Workspace' : 'Manage Workspaces'));
|
|
363
350
|
console.log(chalk_1.default.gray(` ${isVi ? 'Chọn workspace hoặc thêm mới:' : 'Select workspace or add new:'}`));
|
|
364
351
|
}, options);
|
|
352
|
+
rl.resume();
|
|
365
353
|
if (selection.type === 'back')
|
|
366
354
|
return;
|
|
367
355
|
if (selection.type === 'add') {
|
|
@@ -428,6 +416,7 @@ async function manageWorkspaces(rl, language) {
|
|
|
428
416
|
}
|
|
429
417
|
async function configureStartup(config, rl) {
|
|
430
418
|
const isVi = config.language === 'vi';
|
|
419
|
+
rl.pause();
|
|
431
420
|
const nextMode = await runSelectionMenu(() => {
|
|
432
421
|
console.log(titleBox(isVi ? 'Cấu hình khởi động' : 'Configure startup'));
|
|
433
422
|
console.log(chalk_1.default.gray(` ${isVi ? 'Chế độ hiện tại:' : 'Current mode:'} ${config.startupMode}`));
|
|
@@ -436,6 +425,7 @@ async function configureStartup(config, rl) {
|
|
|
436
425
|
{ label: isVi ? 'Chạy nền (background)' : 'Background', value: 'background' },
|
|
437
426
|
{ label: isVi ? 'Mở giao diện (open-ui)' : 'Open UI', value: 'open-ui' }
|
|
438
427
|
], ['disabled', 'background', 'open-ui'].indexOf(config.startupMode));
|
|
428
|
+
rl.resume();
|
|
439
429
|
const entryScriptPath = path.join(process.cwd(), 'dist', 'index.js');
|
|
440
430
|
const result = (0, startup_js_1.applyStartupMode)(nextMode, entryScriptPath, process.cwd());
|
|
441
431
|
const nextConfig = { ...config, startupMode: nextMode };
|
|
@@ -447,6 +437,7 @@ async function configureStartup(config, rl) {
|
|
|
447
437
|
return nextConfig;
|
|
448
438
|
}
|
|
449
439
|
async function switchLanguage(config, rl) {
|
|
440
|
+
rl.pause();
|
|
450
441
|
const language = await runSelectionMenu(() => {
|
|
451
442
|
console.log(titleBox('Đổi ngôn ngữ / Switch language'));
|
|
452
443
|
console.log(chalk_1.default.gray(` Hiện tại: ${config.language}`));
|
|
@@ -454,6 +445,7 @@ async function switchLanguage(config, rl) {
|
|
|
454
445
|
{ label: 'Tiếng Việt (vi)', value: 'vi' },
|
|
455
446
|
{ label: 'English (en)', value: 'en' }
|
|
456
447
|
], config.language === 'en' ? 1 : 0);
|
|
448
|
+
rl.resume();
|
|
457
449
|
const nextConfig = { ...config, language };
|
|
458
450
|
(0, config_js_1.saveConfigToDisk)(nextConfig);
|
|
459
451
|
return nextConfig;
|