redate-cli 0.2.1 → 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.
- package/package.json +1 -1
- package/src/redate.js +82 -1
package/package.json
CHANGED
package/src/redate.js
CHANGED
|
@@ -3,6 +3,9 @@ import { Command } from "commander";
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import exifr from 'exifr';
|
|
6
|
+
import https from "https";
|
|
7
|
+
import { execSync } from "child_process";
|
|
8
|
+
import readline from "readline";
|
|
6
9
|
import { getConfig, setConfig, TOKENS, DEFAULT_CONFIG } from "./config.js";
|
|
7
10
|
|
|
8
11
|
|
|
@@ -11,7 +14,7 @@ const program = new Command();
|
|
|
11
14
|
program
|
|
12
15
|
.name("redate")
|
|
13
16
|
.description("Rename images based on EXIF dates")
|
|
14
|
-
.version("0.2.
|
|
17
|
+
.version("0.2.2");
|
|
15
18
|
|
|
16
19
|
program
|
|
17
20
|
.command("process <paths...>")
|
|
@@ -64,9 +67,49 @@ configCommand
|
|
|
64
67
|
setConfig(DEFAULT_CONFIG);
|
|
65
68
|
console.log("Config reset to defaults");
|
|
66
69
|
});
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
program
|
|
73
|
+
.command("update")
|
|
74
|
+
.description("Check for newer version and update globally")
|
|
75
|
+
.action(async () => {
|
|
76
|
+
try {
|
|
77
|
+
const currentVersion = program.version();
|
|
78
|
+
|
|
79
|
+
const latestVersion = await getLatestVersionFromNpm("redate-cli");
|
|
80
|
+
|
|
81
|
+
if (!latestVersion) {
|
|
82
|
+
console.error("Could not check latest version.");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (latestVersion === currentVersion) {
|
|
87
|
+
console.log(`You are already using the latest version (${currentVersion}).`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`New version available: ${latestVersion}`);
|
|
92
|
+
console.log(`Current version: ${currentVersion}`);
|
|
93
|
+
|
|
94
|
+
const shouldUpdate = await askYesNo("Update globally now? (y/n): ");
|
|
95
|
+
|
|
96
|
+
if (!shouldUpdate) {
|
|
97
|
+
console.log("Update cancelled.");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
console.log("Updating...");
|
|
102
|
+
execSync("npm install -g redate", { stdio: "inherit" });
|
|
103
|
+
|
|
104
|
+
console.log("Update completed.");
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error("Update failed:", err.message);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
67
109
|
program.parse(process.argv);
|
|
68
110
|
|
|
69
111
|
|
|
112
|
+
|
|
70
113
|
const fileHandlers = {
|
|
71
114
|
rename: (src, dest) => {
|
|
72
115
|
fs.renameSync(src, dest);
|
|
@@ -165,4 +208,42 @@ async function getDateFromFile(filePath) {
|
|
|
165
208
|
const offsetMs = sign * (h * 60 + m) * 60_000;
|
|
166
209
|
|
|
167
210
|
return new Date(date.getTime() + offsetMs);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
function getLatestVersionFromNpm(packageName) {
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
https
|
|
217
|
+
.get(`https://registry.npmjs.org/${packageName}/latest`, (res) => {
|
|
218
|
+
let data = "";
|
|
219
|
+
|
|
220
|
+
res.on("data", (chunk) => {
|
|
221
|
+
data += chunk;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
res.on("end", () => {
|
|
225
|
+
try {
|
|
226
|
+
const json = JSON.parse(data);
|
|
227
|
+
resolve(json.version);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
reject(e);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
})
|
|
233
|
+
.on("error", reject);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function askYesNo(question) {
|
|
238
|
+
return new Promise((resolve) => {
|
|
239
|
+
const rl = readline.createInterface({
|
|
240
|
+
input: process.stdin,
|
|
241
|
+
output: process.stdout,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
rl.question(question, (answer) => {
|
|
245
|
+
rl.close();
|
|
246
|
+
resolve(answer.trim().toLowerCase() === "y");
|
|
247
|
+
});
|
|
248
|
+
});
|
|
168
249
|
}
|