image-convert-cli 1.1.2 → 1.1.4

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 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
- await handleUpdate();
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";
@@ -8632,10 +8635,72 @@ Conversion settings:`);
8632
8635
  });
8633
8636
  }
8634
8637
  }
8638
+ // package.json
8639
+ var package_default = {
8640
+ name: "image-convert-cli",
8641
+ version: "1.1.4",
8642
+ type: "module",
8643
+ bin: {
8644
+ imgc: "./dist/index.js"
8645
+ },
8646
+ scripts: {
8647
+ start: "bun bin/index.ts",
8648
+ test: "bun test",
8649
+ prepare: "husky install",
8650
+ build: "bun build ./bin/index.ts --outdir ./dist --target bun",
8651
+ publish: "bun run build && bun publish --access public --ignore-scripts"
8652
+ },
8653
+ publishConfig: {
8654
+ access: "public"
8655
+ },
8656
+ dependencies: {
8657
+ "@inquirer/prompts": "^8.2.0",
8658
+ sharp: "^0.34.5"
8659
+ },
8660
+ devDependencies: {
8661
+ "@types/bun": "^1.3.8",
8662
+ husky: "^9.1.7"
8663
+ }
8664
+ };
8635
8665
 
8636
8666
  // src/cli.ts
8637
8667
  var NPM_REGISTRY_URL = "https://registry.npmjs.org/image-convert-cli/latest";
8638
- async function handleUpdate(fetchVersion, currentVersion) {
8668
+ async function executeUpdate() {
8669
+ return new Promise((resolve) => {
8670
+ console.log("Updating image-convert-cli...");
8671
+ const child = spawn("bun", ["add", "-g", "image-convert-cli"], {
8672
+ stdio: ["inherit", "pipe", "pipe"]
8673
+ });
8674
+ child.stdout?.on("data", (data) => {
8675
+ process.stdout.write(data);
8676
+ });
8677
+ child.stderr?.on("data", (data) => {
8678
+ process.stderr.write(data);
8679
+ });
8680
+ child.on("close", (code) => {
8681
+ if (code === 0) {
8682
+ console.log("Update completed successfully.");
8683
+ } else {
8684
+ console.error(`Update failed with exit code: ${code}`);
8685
+ }
8686
+ resolve();
8687
+ });
8688
+ child.on("error", (error) => {
8689
+ console.error(`Update failed: ${error.message}`);
8690
+ resolve();
8691
+ });
8692
+ });
8693
+ }
8694
+ async function promptForUpdate(latestVersion, promptService) {
8695
+ const prompts = promptService || new InteractivePromptService;
8696
+ return prompts.promptConfirm({
8697
+ sourcePath: "",
8698
+ targetFormat: "webp",
8699
+ destinationPath: "",
8700
+ compress: false
8701
+ });
8702
+ }
8703
+ async function handleUpdate(fetchVersion, currentVersion, autoUpdate, promptService) {
8639
8704
  const fetcher = fetchVersion || (async () => {
8640
8705
  const response = await fetch(NPM_REGISTRY_URL);
8641
8706
  if (!response.ok) {
@@ -8644,14 +8709,23 @@ async function handleUpdate(fetchVersion, currentVersion) {
8644
8709
  const data = await response.json();
8645
8710
  return data.version;
8646
8711
  });
8647
- const version = currentVersion || process.env.npm_package_version || "1.1.0";
8712
+ const version = currentVersion || process.env.npm_package_version || package_default.version;
8648
8713
  try {
8649
8714
  const latestVersion = await fetcher();
8650
8715
  if (latestVersion === version) {
8651
8716
  console.log(`You are running the latest version: ${version}`);
8652
8717
  } else {
8653
8718
  console.log(`Update available: ${version} -> ${latestVersion}`);
8654
- console.log("Run: bun update to upgrade");
8719
+ if (autoUpdate) {
8720
+ await executeUpdate();
8721
+ } else {
8722
+ const shouldUpdate = await promptForUpdate(latestVersion, promptService);
8723
+ if (shouldUpdate) {
8724
+ await executeUpdate();
8725
+ } else {
8726
+ console.log("Update cancelled.");
8727
+ }
8728
+ }
8655
8729
  }
8656
8730
  } catch (error) {
8657
8731
  console.error(`Error checking for updates: ${error.message}`);
@@ -8664,7 +8738,7 @@ async function runCli(options, promptService) {
8664
8738
  return;
8665
8739
  }
8666
8740
  if (options.version) {
8667
- const version = process.env.npm_package_version || "1.1.0";
8741
+ const version = process.env.npm_package_version || package_default.version;
8668
8742
  console.log(`image-convert-cli v${version}`);
8669
8743
  return;
8670
8744
  }
@@ -8729,7 +8803,8 @@ async function runBatchMode(sourceDir, targetFormat, options, prompts) {
8729
8803
  var args = process.argv.slice(2);
8730
8804
  var options = {};
8731
8805
  if (args[0] === "update") {
8732
- await handleUpdate();
8806
+ const autoUpdate = args.includes("--yes") || args.includes("-y");
8807
+ await handleUpdate(undefined, undefined, autoUpdate);
8733
8808
  process.exit(0);
8734
8809
  }
8735
8810
  if (args[0] === "version") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-convert-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "imgc": "./dist/index.js"
package/src/cli.ts CHANGED
@@ -1,15 +1,64 @@
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";
5
6
  import { getDefaultDestinationPath, isDirectory, getImageFilesFromDirectory } from "./utils/path";
6
7
  import type { BatchConversionSettings } from "./types";
8
+ import packageJson from "../package.json" with { type: "json" };
7
9
 
8
10
  const NPM_REGISTRY_URL = "https://registry.npmjs.org/image-convert-cli/latest";
9
11
 
12
+ export async function executeUpdate(): Promise<void> {
13
+ return new Promise((resolve) => {
14
+ console.log("Updating image-convert-cli...");
15
+
16
+ const child = spawn("bun", ["add", "-g", "image-convert-cli"], {
17
+ stdio: ["inherit", "pipe", "pipe"],
18
+ });
19
+
20
+ child.stdout?.on("data", (data) => {
21
+ process.stdout.write(data);
22
+ });
23
+
24
+ child.stderr?.on("data", (data) => {
25
+ process.stderr.write(data);
26
+ });
27
+
28
+ child.on("close", (code) => {
29
+ if (code === 0) {
30
+ console.log("Update completed successfully.");
31
+ } else {
32
+ console.error(`Update failed with exit code: ${code}`);
33
+ }
34
+ resolve();
35
+ });
36
+
37
+ child.on("error", (error) => {
38
+ console.error(`Update failed: ${error.message}`);
39
+ resolve();
40
+ });
41
+ });
42
+ }
43
+
44
+ export async function promptForUpdate(
45
+ latestVersion: string,
46
+ promptService?: IPromptService,
47
+ ): Promise<boolean> {
48
+ const prompts = promptService || new InteractivePromptService();
49
+ return prompts.promptConfirm({
50
+ sourcePath: "",
51
+ targetFormat: "webp",
52
+ destinationPath: "",
53
+ compress: false,
54
+ });
55
+ }
56
+
10
57
  export async function handleUpdate(
11
58
  fetchVersion?: () => Promise<string>,
12
59
  currentVersion?: string,
60
+ autoUpdate?: boolean,
61
+ promptService?: IPromptService,
13
62
  ): Promise<void> {
14
63
  const fetcher = fetchVersion || (async () => {
15
64
  const response = await fetch(NPM_REGISTRY_URL);
@@ -20,7 +69,7 @@ export async function handleUpdate(
20
69
  return data.version;
21
70
  });
22
71
 
23
- const version = currentVersion || process.env.npm_package_version || "1.1.0";
72
+ const version = currentVersion || process.env.npm_package_version || packageJson.version;
24
73
 
25
74
  try {
26
75
  const latestVersion = await fetcher();
@@ -29,7 +78,17 @@ export async function handleUpdate(
29
78
  console.log(`You are running the latest version: ${version}`);
30
79
  } else {
31
80
  console.log(`Update available: ${version} -> ${latestVersion}`);
32
- console.log("Run: bun update to upgrade");
81
+
82
+ if (autoUpdate) {
83
+ await executeUpdate();
84
+ } else {
85
+ const shouldUpdate = await promptForUpdate(latestVersion, promptService);
86
+ if (shouldUpdate) {
87
+ await executeUpdate();
88
+ } else {
89
+ console.log("Update cancelled.");
90
+ }
91
+ }
33
92
  }
34
93
  } catch (error) {
35
94
  console.error(`Error checking for updates: ${(error as Error).message}`);
@@ -48,7 +107,7 @@ export async function runCli(
48
107
  }
49
108
 
50
109
  if (options.version) {
51
- const version = process.env.npm_package_version || "1.1.0";
110
+ const version = process.env.npm_package_version || packageJson.version;
52
111
  console.log(`image-convert-cli v${version}`);
53
112
  return;
54
113
  }