image-convert-cli 1.0.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.
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # image-convert-cli
2
+
3
+ > A fast, interactive CLI tool for converting images between WebP, JPEG, and JPG formats
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ # Install (any package manager)
11
+ npm install -g image-convert-cli # or pnpm/yarn/bun
12
+
13
+ # Run
14
+ imgc --source photo.png --format webp
15
+ ```
16
+
17
+ Or run directly without installing:
18
+
19
+ ```bash
20
+ bun bin/index.ts --source photo.png --format webp --dest photo.webp
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ ### Install via npm/pnpm/yarn/bun
26
+
27
+ ```bash
28
+ # npm
29
+ npm install -g image-convert-cli
30
+
31
+ # pnpm
32
+ pnpm add -g image-convert-cli
33
+
34
+ # yarn
35
+ yarn global add image-convert-cli
36
+
37
+ # bun
38
+ bun install -g image-convert-cli
39
+ ```
40
+
41
+ ### From Source
42
+
43
+ ```bash
44
+ git clone <repo-url>
45
+ cd image-convert-cli
46
+ npm install # or pnpm/yarn/bun install
47
+ npm link # or equivalent for your package manager
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ### Interactive Mode
53
+
54
+ Just run without arguments:
55
+
56
+ ```bash
57
+ imgc
58
+ ```
59
+
60
+ ### Non-Interactive Mode
61
+
62
+ Pass all options via flags:
63
+
64
+ ```bash
65
+ imgc -s photo.png -f webp -d photo.webp -c
66
+ ```
67
+
68
+ ### Options
69
+
70
+ | Flag | Short | Description |
71
+ |------|-------|-------------|
72
+ | `--help` | `-h` | Show help message |
73
+ | `--source <path>` | `-s` | Source image file path |
74
+ | `--format <format>` | `-f` | Target format: webp, jpeg, or jpg |
75
+ | `--dest <path>` | `-d` | Output file path |
76
+ | `--compress` | `-c` | Enable compression |
77
+ | `--yes` | `-y` | Skip all confirmations (use defaults) |
78
+
79
+ ## Examples
80
+
81
+ ### Convert PNG to WebP
82
+
83
+ ```bash
84
+ imgc -s input.png -f webp -d output.webp
85
+ ```
86
+
87
+ ### Quick lossless conversion
88
+
89
+ ```bash
90
+ imgc -s image.png -f webp
91
+ ```
92
+
93
+ ### Convert with compression
94
+
95
+ ```bash
96
+ imgc -s photo.jpg -f webp -c
97
+ ```
98
+
99
+ ## Quality Settings
100
+
101
+ - **Default**: 100% quality, lossless
102
+ - **With --compress**: Format-specific optimization (WebP lossless, mozjpeg for JPEG/JPG)
103
+
104
+ | Format | Options |
105
+ |--------|---------|
106
+ | WebP | 100% quality + lossless encoding |
107
+ | JPEG | 100% quality + mozjpeg optimization |
108
+ | JPG | 100% quality + mozjpeg optimization |
109
+
110
+ ---
111
+
112
+ # Development
113
+
114
+ > For contributors who want to extend or contribute to the project
115
+
116
+ ## Prerequisites
117
+
118
+ - [Bun](https://bun.sh/) v1.3 or later (or Node.js v18+ for alternative runtimes)
119
+ - Any Node.js compatible package manager (npm, pnpm, yarn, bun)
120
+
121
+ ## Getting Started
122
+
123
+ ```bash
124
+ git clone <repo>
125
+ cd image-convert-cli
126
+ bun install
127
+ bun test # Run tests
128
+ bun start # Run CLI interactively
129
+ ```
130
+
131
+ ## Project Structure
132
+
133
+ ```
134
+ bin/index.ts # CLI entry point, argument parsing
135
+ src/
136
+ ├── cli.ts # Core CLI orchestration
137
+ ├── converter.ts # Image conversion using Sharp
138
+ ├── prompts.ts # Interactive prompt services
139
+ ├── types.ts # TypeScript type definitions
140
+ └── utils/
141
+ ├── path.ts # Path utilities
142
+ └── format.ts # Formatting utilities
143
+ tests/ # Unit tests
144
+ ```
145
+
146
+ ## Available Commands
147
+
148
+ | Command | Description |
149
+ |---------|-------------|
150
+ | `bun start` | Run CLI in interactive mode |
151
+ | `bun test` | Run all unit tests |
152
+ | `bun bin/index.ts --help` | Show CLI help |
153
+
154
+ ## Key Concepts
155
+
156
+ ### Dependency Injection
157
+
158
+ The CLI accepts a `promptService` parameter for testability:
159
+
160
+ ```typescript
161
+ import { runCli } from "./cli";
162
+ await runCli(options, mockPromptService);
163
+ ```
164
+
165
+ ### Result Objects
166
+
167
+ Conversions return structured `ConversionResult` objects instead of throwing:
168
+
169
+ ```typescript
170
+ interface ConversionResult {
171
+ success: boolean;
172
+ inputPath: string;
173
+ outputPath: string;
174
+ originalSize: number;
175
+ convertedSize: number;
176
+ format: string;
177
+ error?: string;
178
+ }
179
+ ```
180
+
181
+ See `CLAUDE.md` for detailed development workflow including TDD practices.
182
+
183
+ ## Contributing
184
+
185
+ 1. Fork the repository
186
+ 2. Create a feature branch
187
+ 3. Make changes with tests
188
+ 4. Ensure all tests pass (`bun test`)
189
+ 5. Submit a Pull Request
190
+
191
+ ## Tech Stack
192
+
193
+ - **Runtime**: Bun v1.3+
194
+ - **Image Processing**: Sharp v0.34+
195
+ - **CLI Prompts**: @inquirer/prompts v8.2+
196
+ - **Testing**: bun:test
197
+
198
+ ## License
199
+
200
+ MIT License - see [LICENSE](LICENSE) file
201
+
202
+ ## Acknowledgments
203
+
204
+ - [Sharp](https://sharp.pixelplumbing.com/) - High-performance image processing
205
+ - [Bun](https://bun.sh/) - Fast JavaScript runtime
206
+ - [@inquirer/prompts](https://github.com/SBoudrias/Inquirer.js) - Interactive CLI prompts
package/bin/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { runCli } from "../src/cli";
4
+ import type { ConvertOptions } from "../src/types";
5
+
6
+ const args = process.argv.slice(2);
7
+ const options: ConvertOptions = {};
8
+
9
+ // Parse arguments
10
+ for (let i = 0; i < args.length; i++) {
11
+ const arg = args[i];
12
+ if (arg === "--help" || arg === "-h") {
13
+ options.help = true;
14
+ } else if (arg === "--yes" || arg === "-y") {
15
+ options.yes = true;
16
+ } else if (arg === "--source" || arg === "-s") {
17
+ options.source = args[++i];
18
+ } else if (arg === "--format" || arg === "-f") {
19
+ const format = args[++i] as "webp" | "jpeg" | "jpg" | undefined;
20
+ if (format && ["webp", "jpeg", "jpg"].includes(format)) {
21
+ options.format = format;
22
+ }
23
+ } else if (arg === "--dest" || arg === "-d") {
24
+ options.destination = args[++i];
25
+ } else if (arg === "--compress" || arg === "-c") {
26
+ options.compress = true;
27
+ }
28
+ }
29
+
30
+ runCli(options);