olly-molly 0.1.12 → 0.1.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/bin/cli.js +39 -12
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -59,25 +59,52 @@ function getLocalVersion() {
|
|
|
59
59
|
} catch { return null; }
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const CUSTOM_PROFILES_DIR = path.join(APP_DIR, 'custom-profiles');
|
|
63
|
+
|
|
64
|
+
function backupUserData() {
|
|
65
|
+
const backupDir = path.join(os.tmpdir(), 'olly-molly-backup');
|
|
66
|
+
fs.mkdirSync(backupDir, { recursive: true });
|
|
67
|
+
|
|
68
|
+
// Backup database
|
|
64
69
|
if (fs.existsSync(DB_DIR)) {
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const dbBackupDir = path.join(backupDir, 'db');
|
|
71
|
+
fs.cpSync(DB_DIR, dbBackupDir, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Backup custom profile images
|
|
75
|
+
if (fs.existsSync(CUSTOM_PROFILES_DIR)) {
|
|
76
|
+
const profilesBackupDir = path.join(backupDir, 'custom-profiles');
|
|
77
|
+
fs.cpSync(CUSTOM_PROFILES_DIR, profilesBackupDir, { recursive: true });
|
|
67
78
|
}
|
|
68
|
-
|
|
79
|
+
|
|
80
|
+
return backupDir;
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
function
|
|
72
|
-
if (backupDir
|
|
83
|
+
function restoreUserData(backupDir) {
|
|
84
|
+
if (!backupDir || !fs.existsSync(backupDir)) return;
|
|
85
|
+
|
|
86
|
+
// Restore database
|
|
87
|
+
const dbBackupDir = path.join(backupDir, 'db');
|
|
88
|
+
if (fs.existsSync(dbBackupDir)) {
|
|
73
89
|
fs.mkdirSync(DB_DIR, { recursive: true });
|
|
74
|
-
for (const file of fs.readdirSync(
|
|
90
|
+
for (const file of fs.readdirSync(dbBackupDir)) {
|
|
75
91
|
if (file.includes('.sqlite')) {
|
|
76
|
-
fs.copyFileSync(path.join(
|
|
92
|
+
fs.copyFileSync(path.join(dbBackupDir, file), path.join(DB_DIR, file));
|
|
77
93
|
}
|
|
78
94
|
}
|
|
79
|
-
fs.rmSync(backupDir, { recursive: true, force: true });
|
|
80
95
|
}
|
|
96
|
+
|
|
97
|
+
// Restore custom profile images
|
|
98
|
+
const profilesBackupDir = path.join(backupDir, 'custom-profiles');
|
|
99
|
+
if (fs.existsSync(profilesBackupDir)) {
|
|
100
|
+
fs.mkdirSync(CUSTOM_PROFILES_DIR, { recursive: true });
|
|
101
|
+
for (const file of fs.readdirSync(profilesBackupDir)) {
|
|
102
|
+
fs.copyFileSync(path.join(profilesBackupDir, file), path.join(CUSTOM_PROFILES_DIR, file));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Clean up backup
|
|
107
|
+
fs.rmSync(backupDir, { recursive: true, force: true });
|
|
81
108
|
}
|
|
82
109
|
|
|
83
110
|
async function main() {
|
|
@@ -90,12 +117,12 @@ async function main() {
|
|
|
90
117
|
// Update if npm version is newer
|
|
91
118
|
if (localVersion && npmVersion && localVersion !== npmVersion) {
|
|
92
119
|
console.log(`🔄 Updating ${localVersion} → ${npmVersion}\n`);
|
|
93
|
-
const
|
|
120
|
+
const userDataBackup = backupUserData();
|
|
94
121
|
fs.rmSync(APP_DIR, { recursive: true, force: true });
|
|
95
122
|
console.log('📥 Downloading...');
|
|
96
123
|
await download(TARBALL_URL, APP_DIR);
|
|
97
124
|
console.log('✅ Downloaded\n');
|
|
98
|
-
|
|
125
|
+
restoreUserData(userDataBackup);
|
|
99
126
|
needsInstall = true;
|
|
100
127
|
needsBuild = true;
|
|
101
128
|
}
|