image-convert-cli 1.0.0 → 1.1.1

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/README.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
+ ## Demo
8
+
9
+ <video src="assets/demo.mp4" width="100%" autoplay loop muted playsinline></video>
10
+
7
11
  ## Quick Start
8
12
 
9
13
  ```bash
package/bin/index.ts CHANGED
@@ -1,23 +1,36 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
- import { runCli } from "../src/cli";
3
+ import { runCli, handleUpdate } from "../src/cli";
4
4
  import type { ConvertOptions } from "../src/types";
5
5
 
6
6
  const args = process.argv.slice(2);
7
7
  const options: ConvertOptions = {};
8
8
 
9
+ // Check for update command (positional argument)
10
+ if (args[0] === "update") {
11
+ await handleUpdate();
12
+ process.exit(0);
13
+ }
14
+
15
+ // Check for version command (positional argument)
16
+ if (args[0] === "version") {
17
+ options.version = true;
18
+ }
19
+
9
20
  // Parse arguments
10
21
  for (let i = 0; i < args.length; i++) {
11
22
  const arg = args[i];
12
23
  if (arg === "--help" || arg === "-h") {
13
24
  options.help = true;
25
+ } else if (arg === "--version" || arg === "-v") {
26
+ options.version = true;
14
27
  } else if (arg === "--yes" || arg === "-y") {
15
28
  options.yes = true;
16
29
  } else if (arg === "--source" || arg === "-s") {
17
30
  options.source = args[++i];
18
31
  } else if (arg === "--format" || arg === "-f") {
19
- const format = args[++i] as "webp" | "jpeg" | "jpg" | undefined;
20
- if (format && ["webp", "jpeg", "jpg"].includes(format)) {
32
+ const format = args[++i] as "webp" | "jpeg" | "jpg" | "png" | undefined;
33
+ if (format && ["webp", "jpeg", "jpg", "png"].includes(format)) {
21
34
  options.format = format;
22
35
  }
23
36
  } else if (arg === "--dest" || arg === "-d") {
package/dist/index.js CHANGED
@@ -8309,6 +8309,10 @@ async function convertImage(sourcePath, destinationPath, format, compress) {
8309
8309
  sharpFormat = "jpeg";
8310
8310
  options = compress ? { quality: 100, mozjpeg: true } : { quality: 100 };
8311
8311
  break;
8312
+ case "png":
8313
+ sharpFormat = "png";
8314
+ options = compress ? { compressionLevel: 9 } : { compressionLevel: 6 };
8315
+ break;
8312
8316
  default:
8313
8317
  throw new Error(`Unsupported format: ${format}`);
8314
8318
  }
@@ -8425,7 +8429,8 @@ class InteractivePromptService {
8425
8429
  choices: [
8426
8430
  { value: "webp", description: "WebP format (recommended for web)" },
8427
8431
  { value: "jpeg", description: "JPEG format" },
8428
- { value: "jpg", description: "JPG format" }
8432
+ { value: "jpg", description: "JPG format" },
8433
+ { value: "png", description: "PNG format (lossless)" }
8429
8434
  ]
8430
8435
  });
8431
8436
  }
@@ -8448,20 +8453,29 @@ Usage:
8448
8453
  imgc [options]
8449
8454
  imgc --source <path> --format <format> [options]
8450
8455
  imgc -y --source <path> --format <format>
8456
+ imgc update # Check for updates
8457
+ imgc version # Show version
8451
8458
 
8452
8459
  Options:
8453
8460
  --help, -h Show this help message
8461
+ --version, -v Show version number
8454
8462
  --yes, -y Non-interactive mode (use defaults for optional prompts)
8455
8463
  --source, -s Source file path (required with -y)
8456
- --format, -f Target format: webp, jpeg, or jpg (required with -y)
8464
+ --format, -f Target format: webp, jpeg, jpg, or png (required with -y)
8457
8465
  --dest, -d Destination path (optional, auto-generated if not provided)
8458
- --compress, -c Enable compression (optional, default: false)
8466
+ --compress, -c Enable compression (optional, default: false)
8467
+
8468
+ Commands:
8469
+ update Check for the latest version on npm
8470
+ version Show version number
8459
8471
 
8460
8472
  Examples:
8461
8473
  imgc # Interactive mode
8462
8474
  imgc --help # Show help
8475
+ imgc --version # Show version
8463
8476
  imgc -y --source photo.png --format webp
8464
8477
  imgc -y --source photo.jpg --format jpeg --compress
8478
+ imgc update # Check for updates
8465
8479
  `);
8466
8480
  }
8467
8481
  showSettings(settings) {
@@ -8493,12 +8507,40 @@ function getDefaultDestinationPath(sourcePath, format) {
8493
8507
  }
8494
8508
 
8495
8509
  // src/cli.ts
8510
+ var NPM_REGISTRY_URL = "https://registry.npmjs.org/image-convert-cli/latest";
8511
+ async function handleUpdate(fetchVersion, currentVersion) {
8512
+ const fetcher = fetchVersion || (async () => {
8513
+ const response = await fetch(NPM_REGISTRY_URL);
8514
+ if (!response.ok) {
8515
+ throw new Error(`Failed to fetch version: ${response.statusText}`);
8516
+ }
8517
+ const data = await response.json();
8518
+ return data.version;
8519
+ });
8520
+ const version = currentVersion || process.env.npm_package_version || "1.1.0";
8521
+ try {
8522
+ const latestVersion = await fetcher();
8523
+ if (latestVersion === version) {
8524
+ console.log(`You are running the latest version: ${version}`);
8525
+ } else {
8526
+ console.log(`Update available: ${version} -> ${latestVersion}`);
8527
+ console.log("Run: bun update to upgrade");
8528
+ }
8529
+ } catch (error) {
8530
+ console.error(`Error checking for updates: ${error.message}`);
8531
+ }
8532
+ }
8496
8533
  async function runCli(options, promptService) {
8497
8534
  const prompts = promptService || new InteractivePromptService;
8498
8535
  if (options.help) {
8499
8536
  prompts.showHelp();
8500
8537
  return;
8501
8538
  }
8539
+ if (options.version) {
8540
+ const version = process.env.npm_package_version || "1.1.0";
8541
+ console.log(`image-convert-cli v${version}`);
8542
+ return;
8543
+ }
8502
8544
  if (options.yes && (!options.source || !options.format)) {
8503
8545
  console.error("Error: -y mode requires --source and --format arguments");
8504
8546
  prompts.showHelp();
@@ -8532,17 +8574,26 @@ async function runCli(options, promptService) {
8532
8574
  // bin/index.ts
8533
8575
  var args = process.argv.slice(2);
8534
8576
  var options = {};
8577
+ if (args[0] === "update") {
8578
+ await handleUpdate();
8579
+ process.exit(0);
8580
+ }
8581
+ if (args[0] === "version") {
8582
+ options.version = true;
8583
+ }
8535
8584
  for (let i = 0;i < args.length; i++) {
8536
8585
  const arg = args[i];
8537
8586
  if (arg === "--help" || arg === "-h") {
8538
8587
  options.help = true;
8588
+ } else if (arg === "--version" || arg === "-v") {
8589
+ options.version = true;
8539
8590
  } else if (arg === "--yes" || arg === "-y") {
8540
8591
  options.yes = true;
8541
8592
  } else if (arg === "--source" || arg === "-s") {
8542
8593
  options.source = args[++i];
8543
8594
  } else if (arg === "--format" || arg === "-f") {
8544
8595
  const format = args[++i];
8545
- if (format && ["webp", "jpeg", "jpg"].includes(format)) {
8596
+ if (format && ["webp", "jpeg", "jpg", "png"].includes(format)) {
8546
8597
  options.format = format;
8547
8598
  }
8548
8599
  } else if (arg === "--dest" || arg === "-d") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-convert-cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "imgc": "./dist/index.js"
package/src/cli.ts CHANGED
@@ -3,6 +3,37 @@ import { IPromptService, InteractivePromptService } from "./prompts";
3
3
  import { convertImage, displayConversionResult } from "./converter";
4
4
  import { getDefaultDestinationPath } from "./utils/path";
5
5
 
6
+ const NPM_REGISTRY_URL = "https://registry.npmjs.org/image-convert-cli/latest";
7
+
8
+ export async function handleUpdate(
9
+ fetchVersion?: () => Promise<string>,
10
+ currentVersion?: string,
11
+ ): Promise<void> {
12
+ const fetcher = fetchVersion || (async () => {
13
+ const response = await fetch(NPM_REGISTRY_URL);
14
+ if (!response.ok) {
15
+ throw new Error(`Failed to fetch version: ${response.statusText}`);
16
+ }
17
+ const data = await response.json() as { version: string };
18
+ return data.version;
19
+ });
20
+
21
+ const version = currentVersion || process.env.npm_package_version || "1.1.0";
22
+
23
+ try {
24
+ const latestVersion = await fetcher();
25
+
26
+ if (latestVersion === version) {
27
+ console.log(`You are running the latest version: ${version}`);
28
+ } else {
29
+ console.log(`Update available: ${version} -> ${latestVersion}`);
30
+ console.log("Run: bun update to upgrade");
31
+ }
32
+ } catch (error) {
33
+ console.error(`Error checking for updates: ${(error as Error).message}`);
34
+ }
35
+ }
36
+
6
37
  export async function runCli(
7
38
  options: ConvertOptions,
8
39
  promptService?: IPromptService,
@@ -14,6 +45,12 @@ export async function runCli(
14
45
  return;
15
46
  }
16
47
 
48
+ if (options.version) {
49
+ const version = process.env.npm_package_version || "1.1.0";
50
+ console.log(`image-convert-cli v${version}`);
51
+ return;
52
+ }
53
+
17
54
  if (options.yes && (!options.source || !options.format)) {
18
55
  console.error("Error: -y mode requires --source and --format arguments");
19
56
  prompts.showHelp();
package/src/converter.ts CHANGED
@@ -16,7 +16,7 @@ export async function convertImage(
16
16
 
17
17
  // Determine output format for Sharp
18
18
  let sharpFormat: keyof sharp.FormatEnum;
19
- let options: sharp.JpegOptions | sharp.WebpOptions | sharp.OutputInfo;
19
+ let options: sharp.JpegOptions | sharp.WebpOptions | sharp.PngOptions | sharp.OutputInfo;
20
20
 
21
21
  switch (format) {
22
22
  case "webp":
@@ -30,6 +30,12 @@ export async function convertImage(
30
30
  sharpFormat = "jpeg";
31
31
  options = compress ? { quality: 100, mozjpeg: true } : { quality: 100 };
32
32
  break;
33
+ case "png":
34
+ sharpFormat = "png";
35
+ options = compress
36
+ ? { compressionLevel: 9 }
37
+ : { compressionLevel: 6 };
38
+ break;
33
39
  default:
34
40
  throw new Error(`Unsupported format: ${format}`);
35
41
  }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ export * from "./types";
2
2
  export * from "./utils/path";
3
3
  export * from "./utils/format";
4
4
  export { convertImage, displayConversionResult } from "./converter";
5
- export { runCli } from "./cli";
5
+ export { runCli, handleUpdate } from "./cli";
6
6
  export {
7
7
  type IPromptService,
8
8
  InteractivePromptService,
package/src/prompts.ts CHANGED
@@ -125,6 +125,7 @@ export class InteractivePromptService implements IPromptService {
125
125
  { value: "webp", description: "WebP format (recommended for web)" },
126
126
  { value: "jpeg", description: "JPEG format" },
127
127
  { value: "jpg", description: "JPG format" },
128
+ { value: "png", description: "PNG format (lossless)" },
128
129
  ],
129
130
  });
130
131
  }
@@ -150,20 +151,29 @@ Usage:
150
151
  imgc [options]
151
152
  imgc --source <path> --format <format> [options]
152
153
  imgc -y --source <path> --format <format>
154
+ imgc update # Check for updates
155
+ imgc version # Show version
153
156
 
154
157
  Options:
155
158
  --help, -h Show this help message
159
+ --version, -v Show version number
156
160
  --yes, -y Non-interactive mode (use defaults for optional prompts)
157
161
  --source, -s Source file path (required with -y)
158
- --format, -f Target format: webp, jpeg, or jpg (required with -y)
162
+ --format, -f Target format: webp, jpeg, jpg, or png (required with -y)
159
163
  --dest, -d Destination path (optional, auto-generated if not provided)
160
- --compress, -c Enable compression (optional, default: false)
164
+ --compress, -c Enable compression (optional, default: false)
165
+
166
+ Commands:
167
+ update Check for the latest version on npm
168
+ version Show version number
161
169
 
162
170
  Examples:
163
171
  imgc # Interactive mode
164
172
  imgc --help # Show help
173
+ imgc --version # Show version
165
174
  imgc -y --source photo.png --format webp
166
175
  imgc -y --source photo.jpg --format jpeg --compress
176
+ imgc update # Check for updates
167
177
  `);
168
178
  }
169
179
 
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
- export type SupportedFormat = "webp" | "jpeg" | "jpg";
1
+ export type SupportedFormat = "webp" | "jpeg" | "jpg" | "png";
2
2
 
3
3
  export type ConvertOptions = {
4
4
  help?: boolean;
5
+ version?: boolean;
5
6
  yes?: boolean;
6
7
  source?: string;
7
8
  format?: SupportedFormat;