image-convert-cli 1.1.2 → 1.1.3
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/index.ts +2 -1
- package/dist/index.js +51 -3
- package/package.json +1 -1
- package/src/cli.ts +59 -1
package/bin/index.ts
CHANGED
|
@@ -8,7 +8,8 @@ const options: ConvertOptions = {};
|
|
|
8
8
|
|
|
9
9
|
// Check for update command (positional argument)
|
|
10
10
|
if (args[0] === "update") {
|
|
11
|
-
|
|
11
|
+
const autoUpdate = args.includes("--yes") || args.includes("-y");
|
|
12
|
+
await handleUpdate(undefined, undefined, autoUpdate);
|
|
12
13
|
process.exit(0);
|
|
13
14
|
}
|
|
14
15
|
|
package/dist/index.js
CHANGED
|
@@ -6571,6 +6571,9 @@ var require_lib2 = __commonJS((exports, module) => {
|
|
|
6571
6571
|
module.exports = Sharp;
|
|
6572
6572
|
});
|
|
6573
6573
|
|
|
6574
|
+
// src/cli.ts
|
|
6575
|
+
import { spawn } from "child_process";
|
|
6576
|
+
|
|
6574
6577
|
// src/prompts.ts
|
|
6575
6578
|
import * as readline3 from "readline";
|
|
6576
6579
|
import * as fs3 from "fs";
|
|
@@ -8635,7 +8638,42 @@ Conversion settings:`);
|
|
|
8635
8638
|
|
|
8636
8639
|
// src/cli.ts
|
|
8637
8640
|
var NPM_REGISTRY_URL = "https://registry.npmjs.org/image-convert-cli/latest";
|
|
8638
|
-
async function
|
|
8641
|
+
async function executeUpdate() {
|
|
8642
|
+
return new Promise((resolve) => {
|
|
8643
|
+
console.log("Updating image-convert-cli...");
|
|
8644
|
+
const child = spawn("bun", ["add", "-g", "image-convert-cli"], {
|
|
8645
|
+
stdio: ["inherit", "pipe", "pipe"]
|
|
8646
|
+
});
|
|
8647
|
+
child.stdout?.on("data", (data) => {
|
|
8648
|
+
process.stdout.write(data);
|
|
8649
|
+
});
|
|
8650
|
+
child.stderr?.on("data", (data) => {
|
|
8651
|
+
process.stderr.write(data);
|
|
8652
|
+
});
|
|
8653
|
+
child.on("close", (code) => {
|
|
8654
|
+
if (code === 0) {
|
|
8655
|
+
console.log("Update completed successfully.");
|
|
8656
|
+
} else {
|
|
8657
|
+
console.error(`Update failed with exit code: ${code}`);
|
|
8658
|
+
}
|
|
8659
|
+
resolve();
|
|
8660
|
+
});
|
|
8661
|
+
child.on("error", (error) => {
|
|
8662
|
+
console.error(`Update failed: ${error.message}`);
|
|
8663
|
+
resolve();
|
|
8664
|
+
});
|
|
8665
|
+
});
|
|
8666
|
+
}
|
|
8667
|
+
async function promptForUpdate(latestVersion, promptService) {
|
|
8668
|
+
const prompts = promptService || new InteractivePromptService;
|
|
8669
|
+
return prompts.promptConfirm({
|
|
8670
|
+
sourcePath: "",
|
|
8671
|
+
targetFormat: "webp",
|
|
8672
|
+
destinationPath: "",
|
|
8673
|
+
compress: false
|
|
8674
|
+
});
|
|
8675
|
+
}
|
|
8676
|
+
async function handleUpdate(fetchVersion, currentVersion, autoUpdate, promptService) {
|
|
8639
8677
|
const fetcher = fetchVersion || (async () => {
|
|
8640
8678
|
const response = await fetch(NPM_REGISTRY_URL);
|
|
8641
8679
|
if (!response.ok) {
|
|
@@ -8651,7 +8689,16 @@ async function handleUpdate(fetchVersion, currentVersion) {
|
|
|
8651
8689
|
console.log(`You are running the latest version: ${version}`);
|
|
8652
8690
|
} else {
|
|
8653
8691
|
console.log(`Update available: ${version} -> ${latestVersion}`);
|
|
8654
|
-
|
|
8692
|
+
if (autoUpdate) {
|
|
8693
|
+
await executeUpdate();
|
|
8694
|
+
} else {
|
|
8695
|
+
const shouldUpdate = await promptForUpdate(latestVersion, promptService);
|
|
8696
|
+
if (shouldUpdate) {
|
|
8697
|
+
await executeUpdate();
|
|
8698
|
+
} else {
|
|
8699
|
+
console.log("Update cancelled.");
|
|
8700
|
+
}
|
|
8701
|
+
}
|
|
8655
8702
|
}
|
|
8656
8703
|
} catch (error) {
|
|
8657
8704
|
console.error(`Error checking for updates: ${error.message}`);
|
|
@@ -8729,7 +8776,8 @@ async function runBatchMode(sourceDir, targetFormat, options, prompts) {
|
|
|
8729
8776
|
var args = process.argv.slice(2);
|
|
8730
8777
|
var options = {};
|
|
8731
8778
|
if (args[0] === "update") {
|
|
8732
|
-
|
|
8779
|
+
const autoUpdate = args.includes("--yes") || args.includes("-y");
|
|
8780
|
+
await handleUpdate(undefined, undefined, autoUpdate);
|
|
8733
8781
|
process.exit(0);
|
|
8734
8782
|
}
|
|
8735
8783
|
if (args[0] === "version") {
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
2
3
|
import type { ConvertOptions } from "./types";
|
|
3
4
|
import { IPromptService, InteractivePromptService } from "./prompts";
|
|
4
5
|
import { convertImage, displayConversionResult, convertBatch, displayBatchResult } from "./converter";
|
|
@@ -7,9 +8,56 @@ import type { BatchConversionSettings } from "./types";
|
|
|
7
8
|
|
|
8
9
|
const NPM_REGISTRY_URL = "https://registry.npmjs.org/image-convert-cli/latest";
|
|
9
10
|
|
|
11
|
+
export async function executeUpdate(): Promise<void> {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
console.log("Updating image-convert-cli...");
|
|
14
|
+
|
|
15
|
+
const child = spawn("bun", ["add", "-g", "image-convert-cli"], {
|
|
16
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
child.stdout?.on("data", (data) => {
|
|
20
|
+
process.stdout.write(data);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
child.stderr?.on("data", (data) => {
|
|
24
|
+
process.stderr.write(data);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
child.on("close", (code) => {
|
|
28
|
+
if (code === 0) {
|
|
29
|
+
console.log("Update completed successfully.");
|
|
30
|
+
} else {
|
|
31
|
+
console.error(`Update failed with exit code: ${code}`);
|
|
32
|
+
}
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
child.on("error", (error) => {
|
|
37
|
+
console.error(`Update failed: ${error.message}`);
|
|
38
|
+
resolve();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function promptForUpdate(
|
|
44
|
+
latestVersion: string,
|
|
45
|
+
promptService?: IPromptService,
|
|
46
|
+
): Promise<boolean> {
|
|
47
|
+
const prompts = promptService || new InteractivePromptService();
|
|
48
|
+
return prompts.promptConfirm({
|
|
49
|
+
sourcePath: "",
|
|
50
|
+
targetFormat: "webp",
|
|
51
|
+
destinationPath: "",
|
|
52
|
+
compress: false,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
10
56
|
export async function handleUpdate(
|
|
11
57
|
fetchVersion?: () => Promise<string>,
|
|
12
58
|
currentVersion?: string,
|
|
59
|
+
autoUpdate?: boolean,
|
|
60
|
+
promptService?: IPromptService,
|
|
13
61
|
): Promise<void> {
|
|
14
62
|
const fetcher = fetchVersion || (async () => {
|
|
15
63
|
const response = await fetch(NPM_REGISTRY_URL);
|
|
@@ -29,7 +77,17 @@ export async function handleUpdate(
|
|
|
29
77
|
console.log(`You are running the latest version: ${version}`);
|
|
30
78
|
} else {
|
|
31
79
|
console.log(`Update available: ${version} -> ${latestVersion}`);
|
|
32
|
-
|
|
80
|
+
|
|
81
|
+
if (autoUpdate) {
|
|
82
|
+
await executeUpdate();
|
|
83
|
+
} else {
|
|
84
|
+
const shouldUpdate = await promptForUpdate(latestVersion, promptService);
|
|
85
|
+
if (shouldUpdate) {
|
|
86
|
+
await executeUpdate();
|
|
87
|
+
} else {
|
|
88
|
+
console.log("Update cancelled.");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
33
91
|
}
|
|
34
92
|
} catch (error) {
|
|
35
93
|
console.error(`Error checking for updates: ${(error as Error).message}`);
|