xiaozuoassistant 0.1.59 → 0.1.61
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/bin/cli.js +63 -7
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ const args = process.argv.slice(2);
|
|
|
28
28
|
const command = args[0];
|
|
29
29
|
const commandArgs = args.slice(1);
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const EXPORT_FILENAME_PREFIX = 'xiaozuoAssistant-backup';
|
|
32
32
|
const PRODUCTION_PORT = 3021; // 生产环境(CLI)默认端口
|
|
33
33
|
const DEV_PORT = 3001; // 开发环境默认端口
|
|
34
34
|
|
|
@@ -52,7 +52,8 @@ const DATA_PATHS = [
|
|
|
52
52
|
'data',
|
|
53
53
|
'logs',
|
|
54
54
|
'sessions',
|
|
55
|
-
'workspace'
|
|
55
|
+
'workspace',
|
|
56
|
+
'plugins'
|
|
56
57
|
];
|
|
57
58
|
|
|
58
59
|
function ensureAppHome() {
|
|
@@ -424,6 +425,11 @@ async function exportData() {
|
|
|
424
425
|
ensureDefaultDirs();
|
|
425
426
|
console.log('📦 Starting data export...');
|
|
426
427
|
|
|
428
|
+
// Generate filename with timestamp
|
|
429
|
+
const now = new Date();
|
|
430
|
+
const timestamp = now.toISOString().replace(/[-:T.]/g, '').slice(0, 14); // YYYYMMDDHHmmss
|
|
431
|
+
const exportFilename = `${EXPORT_FILENAME_PREFIX}-${timestamp}.tar.gz`;
|
|
432
|
+
|
|
427
433
|
const filesToArchive = [];
|
|
428
434
|
|
|
429
435
|
for (const p of DATA_PATHS) {
|
|
@@ -438,16 +444,19 @@ async function exportData() {
|
|
|
438
444
|
return;
|
|
439
445
|
}
|
|
440
446
|
|
|
447
|
+
const exportPath = path.join(APP_HOME, exportFilename);
|
|
448
|
+
|
|
441
449
|
try {
|
|
442
450
|
await tar.c(
|
|
443
451
|
{
|
|
444
452
|
gzip: true,
|
|
445
|
-
file:
|
|
453
|
+
file: exportPath,
|
|
446
454
|
cwd: APP_HOME
|
|
447
455
|
},
|
|
448
456
|
filesToArchive
|
|
449
457
|
);
|
|
450
|
-
console.log(`✅ Export successful
|
|
458
|
+
console.log(`✅ Export successful!`);
|
|
459
|
+
console.log(` Backup file: ${exportPath}`);
|
|
451
460
|
console.log(` Copy this file to your new machine to import.`);
|
|
452
461
|
} catch (err) {
|
|
453
462
|
console.error('❌ Export failed:', err);
|
|
@@ -456,15 +465,49 @@ async function exportData() {
|
|
|
456
465
|
|
|
457
466
|
async function importData() {
|
|
458
467
|
ensureAppHome();
|
|
459
|
-
|
|
468
|
+
|
|
469
|
+
// Find backup file
|
|
470
|
+
let backupFile = getFlagValue('--file');
|
|
471
|
+
|
|
472
|
+
if (!backupFile) {
|
|
473
|
+
// Try to find the latest backup file in APP_HOME
|
|
474
|
+
try {
|
|
475
|
+
const files = fs.readdirSync(APP_HOME)
|
|
476
|
+
.filter(f => f.startsWith(EXPORT_FILENAME_PREFIX) && f.endsWith('.tar.gz'))
|
|
477
|
+
.sort()
|
|
478
|
+
.reverse();
|
|
479
|
+
|
|
480
|
+
if (files.length > 0) {
|
|
481
|
+
backupFile = path.join(APP_HOME, files[0]);
|
|
482
|
+
console.log(`[CLI] No file specified, using latest found: ${files[0]}`);
|
|
483
|
+
} else {
|
|
484
|
+
// Fallback to old filename for compatibility
|
|
485
|
+
const oldFile = path.join(APP_HOME, 'xiaozuoAssistant-backup.tar.gz');
|
|
486
|
+
if (fs.existsSync(oldFile)) {
|
|
487
|
+
backupFile = oldFile;
|
|
488
|
+
console.log(`[CLI] Using legacy backup file: xiaozuoAssistant-backup.tar.gz`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
} catch (e) {
|
|
492
|
+
// ignore
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (!backupFile) {
|
|
497
|
+
console.error(`❌ No backup file found or specified.`);
|
|
498
|
+
console.log(` Use --file <path> to specify a backup file.`);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Resolve absolute path
|
|
503
|
+
const backupPath = path.resolve(process.cwd(), backupFile);
|
|
460
504
|
|
|
461
505
|
if (!fs.existsSync(backupPath)) {
|
|
462
506
|
console.error(`❌ Backup file not found: ${backupPath}`);
|
|
463
|
-
console.log(` Please ensure '${EXPORT_FILENAME}' is in ${APP_HOME}`);
|
|
464
507
|
return;
|
|
465
508
|
}
|
|
466
509
|
|
|
467
|
-
console.log(
|
|
510
|
+
console.log(`📦 Starting data import from: ${backupPath}`);
|
|
468
511
|
console.log('⚠️ Warning: This will overwrite existing data files (config.json, memories, etc.)');
|
|
469
512
|
|
|
470
513
|
// Simple prompt implementation for Node.js
|
|
@@ -473,6 +516,13 @@ async function importData() {
|
|
|
473
516
|
const answer = data.toString().trim().toLowerCase();
|
|
474
517
|
if (answer === 'y' || answer === 'yes') {
|
|
475
518
|
try {
|
|
519
|
+
// Stop server if running before import
|
|
520
|
+
const pidFile = getPidFilePath();
|
|
521
|
+
if (fs.existsSync(pidFile)) {
|
|
522
|
+
console.log('[CLI] Stopping server before import...');
|
|
523
|
+
await stopServer();
|
|
524
|
+
}
|
|
525
|
+
|
|
476
526
|
await tar.x({
|
|
477
527
|
file: backupPath,
|
|
478
528
|
cwd: APP_HOME
|
|
@@ -500,6 +550,12 @@ async function importData() {
|
|
|
500
550
|
}
|
|
501
551
|
}
|
|
502
552
|
|
|
553
|
+
// Ensure port is set to production port if it was dev port
|
|
554
|
+
if (config.server && config.server.port === DEV_PORT) {
|
|
555
|
+
config.server.port = PRODUCTION_PORT;
|
|
556
|
+
console.log(`[CLI] Updated port from ${DEV_PORT} to ${PRODUCTION_PORT}`);
|
|
557
|
+
}
|
|
558
|
+
|
|
503
559
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
504
560
|
console.log(`✅ Auto-configured workspace path to: ${APP_HOME}`);
|
|
505
561
|
} catch (e) {
|
package/package.json
CHANGED