backupman 0.1.4 → 0.2.0

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 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
1
4
  const fs = require("fs");
2
5
  const path = require("path");
3
6
  const readline = require("readline");
@@ -19,11 +22,11 @@ class BackupMan {
19
22
  try {
20
23
  const data = await fs.promises.readFile(this.indexFile, "utf8");
21
24
  const parsed = JSON.parse(data);
22
- if (!parsed.snapshots || typeof parsed.lastId !== "number") {
25
+ if (!Array.isArray(parsed.snapshots) || typeof parsed.lastId !== "number") {
23
26
  throw new Error("Corrupted index");
24
27
  }
25
28
  return parsed;
26
- } catch (err) {
29
+ } catch (_err) {
27
30
  return { lastId: 0, snapshots: [] };
28
31
  }
29
32
  }
@@ -99,7 +102,7 @@ class BackupMan {
99
102
  formatSnapshot(snapshot) {
100
103
  const ts = snapshot.createdAt || "";
101
104
  const msg = snapshot.message || "";
102
- return `[#${snapshot.id}] [${ts}] ${msg}`;
105
+ return `#${snapshot.id} [${ts}] ${msg}`;
103
106
  }
104
107
 
105
108
  async chooseSnapshot(index) {
@@ -109,7 +112,6 @@ class BackupMan {
109
112
  }
110
113
 
111
114
  const list = [...index.snapshots].sort((a, b) => b.id - a.id);
112
-
113
115
  console.log("");
114
116
  console.log("Available snapshots (newest first):");
115
117
  list.forEach(s => {
@@ -118,18 +120,14 @@ class BackupMan {
118
120
  console.log("");
119
121
 
120
122
  while (true) {
121
- const answer = (await this.prompt("Enter snapshot id to restore (e.g. 2, empty = cancel): ")).trim();
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) {
129
- return found;
130
- }
123
+ 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;
131
129
  }
132
- console.log("Invalid id. Please enter an existing snapshot id or press Enter to cancel.");
130
+ console.log("Invalid id. Please type an existing snapshot id or press Enter to cancel.");
133
131
  }
134
132
  }
135
133
 
@@ -143,8 +141,8 @@ class BackupMan {
143
141
  }
144
142
 
145
143
  console.log("");
146
- console.log(`You chose snapshot ${this.formatSnapshot(snapshot)}`);
147
- const confirm = (await this.prompt("Create an auto-backup of current state and overwrite files? (y/N): ")).trim().toLowerCase();
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();
148
146
  if (confirm !== "y" && confirm !== "yes") {
149
147
  console.log("Restore aborted.");
150
148
  return;
@@ -165,15 +163,16 @@ class BackupMan {
165
163
  }
166
164
 
167
165
  function printUsage() {
168
- console.log("backupman - ultra-simple local snapshot versioning");
166
+ console.log("backupman - ultra-simple local snapshot tool");
169
167
  console.log("");
170
168
  console.log("Usage:");
171
169
  console.log(" backupman save \"message\" Save current directory as a snapshot");
172
170
  console.log(" backupman restore Restore from a previous snapshot");
173
171
  console.log("");
174
172
  console.log("Notes:");
173
+ console.log(" - Run this inside the folder you want to protect (e.g. your project root or src)");
175
174
  console.log(" - Snapshots are stored in .backupman/snapshots");
176
- console.log(" - .backupman, node_modules, .git are ignored");
175
+ console.log(" - .backupman, node_modules, .git are ignored when copying");
177
176
  }
178
177
 
179
178
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backupman",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Ultra-simple local snapshot versioning tool for chaotic devs and mischievous AIs.",
5
5
  "bin": {
6
6
  "backupman": "index.js"