backupman 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/index.js +18 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
-
4
2
  const fs = require("fs");
5
3
  const path = require("path");
6
4
  const readline = require("readline");
@@ -22,11 +20,11 @@ class BackupMan {
22
20
  try {
23
21
  const data = await fs.promises.readFile(this.indexFile, "utf8");
24
22
  const parsed = JSON.parse(data);
25
- if (!Array.isArray(parsed.snapshots) || typeof parsed.lastId !== "number") {
23
+ if (!parsed.snapshots || typeof parsed.lastId !== "number") {
26
24
  throw new Error("Corrupted index");
27
25
  }
28
26
  return parsed;
29
- } catch (_err) {
27
+ } catch (err) {
30
28
  return { lastId: 0, snapshots: [] };
31
29
  }
32
30
  }
@@ -121,11 +119,13 @@ class BackupMan {
121
119
 
122
120
  while (true) {
123
121
  const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
124
- if (!answer) return null;
125
- const id = Number.parseInt(answer, 10);
126
- if (!Number.isNaN(id)) {
127
- const snap = list.find(s => s.id === id);
128
- if (snap) return snap;
122
+ if (!answer) {
123
+ return null;
124
+ }
125
+ const n = Number.parseInt(answer, 10);
126
+ if (!Number.isNaN(n)) {
127
+ const found = list.find(s => s.id === n);
128
+ if (found) return found;
129
129
  }
130
130
  console.log("Invalid id. Please type an existing snapshot id or press Enter to cancel.");
131
131
  }
@@ -141,38 +141,30 @@ class BackupMan {
141
141
  }
142
142
 
143
143
  console.log("");
144
- console.log(`You chose snapshot: ${this.formatSnapshot(snapshot)}`);
145
- const confirm = (await this.prompt("Auto-backup current state and overwrite files? (y/N): ")).trim().toLowerCase();
144
+ console.log("You chose: " + this.formatSnapshot(snapshot));
145
+ const confirm = (await this.prompt("Overwrite current files with this snapshot? [y/n]: ")).trim().toLowerCase();
146
146
  if (confirm !== "y" && confirm !== "yes") {
147
147
  console.log("Restore aborted.");
148
148
  return;
149
149
  }
150
150
 
151
- console.log("Creating auto-backup of current state...");
152
- await this.createSnapshot(`[auto] before restore from #${snapshot.id}`);
153
-
154
- console.log("Clearing current directory (except .backupman)...");
151
+ console.log("Clearing current directory...");
155
152
  await this.deleteEverythingExceptBackupDir();
156
153
 
157
154
  console.log("Restoring snapshot files...");
158
155
  const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
159
156
  await this.copyDir(srcSnapshotDir, this.rootDir);
160
157
 
161
- console.log(`Done. Restored snapshot #${snapshot.id}.`);
158
+ console.log("Done. Restored snapshot #" + snapshot.id + ".");
162
159
  }
163
160
  }
164
161
 
165
162
  function printUsage() {
166
163
  console.log("backupman - ultra-simple local snapshot tool");
167
164
  console.log("");
168
- console.log("Usage:");
169
- console.log(" backupman save \"message\" Save current directory as a snapshot");
170
- console.log(" backupman restore Restore from a previous snapshot");
171
- console.log("");
172
- console.log("Notes:");
173
- console.log(" - Run this inside the folder you want to protect (e.g. your project root or src)");
174
- console.log(" - Snapshots are stored in .backupman/snapshots");
175
- console.log(" - .backupman, node_modules, .git are ignored when copying");
165
+ console.log("Commands:");
166
+ console.log(" backupman save \"message\"");
167
+ console.log(" backupman restore");
176
168
  }
177
169
 
178
170
  async function main() {
@@ -195,7 +187,7 @@ async function main() {
195
187
  }
196
188
  }
197
189
  const id = await manager.createSnapshot(message.trim());
198
- console.log(`Saved snapshot #${id}.`);
190
+ console.log("Saved snapshot #" + id + ".");
199
191
  return;
200
192
  }
201
193
 
@@ -204,7 +196,7 @@ async function main() {
204
196
  return;
205
197
  }
206
198
 
207
- console.error(`Unknown command: ${command}`);
199
+ console.error("Unknown command: " + command);
208
200
  printUsage();
209
201
  process.exit(1);
210
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backupman",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Ultra-simple local snapshot versioning tool for chaotic devs and mischievous AIs.",
5
5
  "bin": {
6
6
  "backupman": "index.js"