backupman 0.1.0 → 0.1.2
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/index.js +17 -10
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const readline = require("readline");
|
|
@@ -100,7 +100,7 @@ class BackupMan {
|
|
|
100
100
|
formatSnapshot(snapshot) {
|
|
101
101
|
const ts = snapshot.createdAt || "";
|
|
102
102
|
const msg = snapshot.message || "";
|
|
103
|
-
return
|
|
103
|
+
return `[#${snapshot.id}] [${ts}] ${msg}`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async chooseSnapshot(index) {
|
|
@@ -110,23 +110,27 @@ class BackupMan {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
const list = [...index.snapshots].sort((a, b) => b.id - a.id);
|
|
113
|
+
|
|
113
114
|
console.log("");
|
|
114
115
|
console.log("Available snapshots (newest first):");
|
|
115
|
-
list.forEach(
|
|
116
|
-
console.log(
|
|
116
|
+
list.forEach(s => {
|
|
117
|
+
console.log(" " + this.formatSnapshot(s));
|
|
117
118
|
});
|
|
118
119
|
console.log("");
|
|
119
120
|
|
|
120
121
|
while (true) {
|
|
121
|
-
const answer = (await this.prompt("
|
|
122
|
+
const answer = (await this.prompt("Enter snapshot id to restore (e.g. 2, empty = cancel): ")).trim();
|
|
122
123
|
if (!answer) {
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
125
126
|
const n = Number.parseInt(answer, 10);
|
|
126
|
-
if (!Number.isNaN(n)
|
|
127
|
-
|
|
127
|
+
if (!Number.isNaN(n)) {
|
|
128
|
+
const found = list.find(s => s.id === n);
|
|
129
|
+
if (found) {
|
|
130
|
+
return found;
|
|
131
|
+
}
|
|
128
132
|
}
|
|
129
|
-
console.log("Invalid
|
|
133
|
+
console.log("Invalid id. Please enter an existing snapshot id or press Enter to cancel.");
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
|
|
@@ -140,13 +144,16 @@ class BackupMan {
|
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
console.log("");
|
|
143
|
-
console.log(`You chose snapshot
|
|
144
|
-
const confirm = (await this.prompt("
|
|
147
|
+
console.log(`You chose snapshot ${this.formatSnapshot(snapshot)}`);
|
|
148
|
+
const confirm = (await this.prompt("Create an auto-backup of current state and overwrite files? (y/N): ")).trim().toLowerCase();
|
|
145
149
|
if (confirm !== "y" && confirm !== "yes") {
|
|
146
150
|
console.log("Restore aborted.");
|
|
147
151
|
return;
|
|
148
152
|
}
|
|
149
153
|
|
|
154
|
+
console.log("Creating auto-backup of current state...");
|
|
155
|
+
await this.createSnapshot(`[auto] before restore from #${snapshot.id}`);
|
|
156
|
+
|
|
150
157
|
console.log("Clearing current directory (except .backupman)...");
|
|
151
158
|
await this.deleteEverythingExceptBackupDir();
|
|
152
159
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "backupman",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Ultra-simple local snapshot versioning tool for chaotic devs and mischievous AIs.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"backupman": "index.js"
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {}
|
|
22
|
-
}
|
|
22
|
+
}
|