one-image-optimizer 1.0.0 → 1.0.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/CHEAT_SHEET.md ADDED
@@ -0,0 +1,111 @@
1
+ # ⚔ one-image-optimizer - Quick Cheat Sheet
2
+
3
+ ## šŸ“¦ Installation (3 Steps)
4
+
5
+ ```bash
6
+ # 1. Install
7
+ npm install one-image-optimizer
8
+
9
+ # 2. Edit config file (auto-created)
10
+ # Open: one-image-optimizer.config.js
11
+ # Change: ROOT_FOLDER: './your/images/folder'
12
+
13
+ # 3. Run
14
+ npx one-image-optimizer
15
+ ```
16
+
17
+ ---
18
+
19
+ ## šŸŽÆ Commands
20
+
21
+ ```bash
22
+ # Full optimization (compress + rename + webp)
23
+ npx one-image-optimizer
24
+
25
+ # Compress images only
26
+ npx oio-compress
27
+
28
+ # Convert to WebP only
29
+ npx oio-webp
30
+
31
+ # Rename images only
32
+ npx oio-rename
33
+
34
+ # Empty folders (āš ļø destructive!)
35
+ npx oio-empty
36
+ ```
37
+
38
+ ---
39
+
40
+ ## āš™ļø Config File
41
+
42
+ ```javascript
43
+ // one-image-optimizer.config.js
44
+ module.exports = {
45
+ ROOT_FOLDER: './assets/images', // šŸ‘ˆ Change this!
46
+ COMPRESS_THRESHOLD_MB: 1,
47
+ MAX_WIDTH: 1920,
48
+ MAX_HEIGHT: 1080,
49
+ WEBP_QUALITY: 80,
50
+ JPEG_QUALITY: 75
51
+ };
52
+ ```
53
+
54
+ ---
55
+
56
+ ## šŸŒ Global Install (Optional)
57
+
58
+ ```bash
59
+ # Install globally
60
+ npm install -g one-image-optimizer
61
+
62
+ # Use without npx
63
+ one-image-optimizer
64
+ oio-compress
65
+ oio-webp
66
+ ```
67
+
68
+ ---
69
+
70
+ ## šŸ’” Common Paths
71
+
72
+ ```javascript
73
+ ROOT_FOLDER: './assets/images' // React/Vue
74
+ ROOT_FOLDER: './public/images' // Next.js
75
+ ROOT_FOLDER: './src/assets' // Angular
76
+ ROOT_FOLDER: './static/images' // Gatsby
77
+ ROOT_FOLDER: './content/images' // Hugo/Jekyll
78
+ ```
79
+
80
+ ---
81
+
82
+ ## šŸ”§ Troubleshooting
83
+
84
+ ```bash
85
+ # Config not found?
86
+ npm install one-image-optimizer
87
+
88
+ # Commands not working?
89
+ npm install one-image-optimizer@latest
90
+
91
+ # Update package
92
+ npm update one-image-optimizer
93
+ ```
94
+
95
+ ---
96
+
97
+ ## šŸ“Š What It Does
98
+
99
+ | Command | Action |
100
+ |---------|--------|
101
+ | `one-image-optimizer` | Compress → Rename → WebP |
102
+ | `oio-compress` | Compress images > 1MB |
103
+ | `oio-webp` | Convert to WebP format |
104
+ | `oio-rename` | Rename based on folder |
105
+ | `oio-empty` | Delete all files (āš ļø) |
106
+
107
+ ---
108
+
109
+ **That's all you need to know!** šŸš€
110
+
111
+ For detailed docs, see: `HOW_TO_USE.md` or `README.md`
File without changes
File without changes
package/HOW_TO_USE.md ADDED
@@ -0,0 +1,377 @@
1
+ # šŸ“– How to Install and Use one-image-optimizer
2
+
3
+ ## šŸš€ Simple Installation & Usage Guide
4
+
5
+ ### Step 1: Install the Package
6
+
7
+ In your project directory, run:
8
+
9
+ ```bash
10
+ npm install one-image-optimizer
11
+ ```
12
+
13
+ **That's it!** The package will:
14
+ - āœ… Install automatically
15
+ - āœ… Create a config file: `one-image-optimizer.config.js`
16
+
17
+ ---
18
+
19
+ ### Step 2: Configure Your Image Folder
20
+
21
+ Open the auto-created config file and set your images folder:
22
+
23
+ ```javascript
24
+ // one-image-optimizer.config.js
25
+ module.exports = {
26
+ ROOT_FOLDER: './assets/images', // šŸ‘ˆ CHANGE THIS to your images folder
27
+ COMPRESS_THRESHOLD_MB: 1,
28
+ MAX_WIDTH: 1920,
29
+ MAX_HEIGHT: 1080,
30
+ WEBP_QUALITY: 80,
31
+ JPEG_QUALITY: 75,
32
+ IMAGE_EXTENSIONS: ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp', '.tiff']
33
+ };
34
+ ```
35
+
36
+ **Example paths:**
37
+ - `'./assets/images'` - If your images are in `assets/images` folder
38
+ - `'./public/images'` - If your images are in `public/images` folder
39
+ - `'./src/assets'` - If your images are in `src/assets` folder
40
+
41
+ ---
42
+
43
+ ### Step 3: Run the Commands
44
+
45
+ #### Option A: Full Optimization (Recommended)
46
+
47
+ Run all optimization steps at once:
48
+
49
+ ```bash
50
+ npx one-image-optimizer
51
+ ```
52
+
53
+ This will:
54
+ 1. āœ… Compress all images larger than 1MB
55
+ 2. āœ… Rename images based on their folder names
56
+ 3. āœ… Convert all images to WebP format
57
+
58
+ You'll be asked to confirm before it starts.
59
+
60
+ #### Option B: Individual Commands
61
+
62
+ Run specific tasks:
63
+
64
+ ```bash
65
+ # Compress images only
66
+ npx oio-compress
67
+
68
+ # Convert to WebP only
69
+ npx oio-webp
70
+
71
+ # Rename images only
72
+ npx oio-rename
73
+
74
+ # Empty folders (āš ļø CAREFUL - this deletes files!)
75
+ npx oio-empty
76
+ ```
77
+
78
+ ---
79
+
80
+ ## šŸ“‹ Complete Example
81
+
82
+ Let's say you have a React project with images in `public/images`:
83
+
84
+ ```bash
85
+ # 1. Navigate to your project
86
+ cd my-react-app
87
+
88
+ # 2. Install the package
89
+ npm install one-image-optimizer
90
+
91
+ # 3. Edit the config file
92
+ # Open: one-image-optimizer.config.js
93
+ # Change: ROOT_FOLDER: './public/images'
94
+
95
+ # 4. Run optimization
96
+ npx one-image-optimizer
97
+
98
+ # 5. Done! Your images are optimized āœ…
99
+ ```
100
+
101
+ ---
102
+
103
+ ## šŸŽÆ Real-World Usage Examples
104
+
105
+ ### Example 1: E-commerce Website
106
+
107
+ ```bash
108
+ # Your project structure:
109
+ my-shop/
110
+ ā”œā”€ā”€ public/
111
+ │ └── products/
112
+ │ ā”œā”€ā”€ shoes/
113
+ │ ā”œā”€ā”€ shirts/
114
+ │ └── accessories/
115
+
116
+ # Install
117
+ npm install one-image-optimizer
118
+
119
+ # Configure
120
+ # Set ROOT_FOLDER: './public/products'
121
+
122
+ # Run
123
+ npx one-image-optimizer
124
+ ```
125
+
126
+ ### Example 2: Portfolio Website
127
+
128
+ ```bash
129
+ # Your project structure:
130
+ portfolio/
131
+ ā”œā”€ā”€ src/
132
+ │ └── assets/
133
+ │ └── gallery/
134
+
135
+ # Install
136
+ npm install one-image-optimizer
137
+
138
+ # Configure
139
+ # Set ROOT_FOLDER: './src/assets/gallery'
140
+
141
+ # Run
142
+ npx oio-compress # Just compress, don't convert to WebP
143
+ ```
144
+
145
+ ### Example 3: Blog with Multiple Image Folders
146
+
147
+ ```bash
148
+ # Your project structure:
149
+ blog/
150
+ ā”œā”€ā”€ content/
151
+ │ ā”œā”€ā”€ posts/
152
+ │ │ └── images/
153
+ │ └── authors/
154
+ │ └── photos/
155
+
156
+ # Install once
157
+ npm install one-image-optimizer
158
+
159
+ # Optimize posts images
160
+ # Edit config: ROOT_FOLDER: './content/posts/images'
161
+ npx one-image-optimizer
162
+
163
+ # Then optimize author photos
164
+ # Edit config: ROOT_FOLDER: './content/authors/photos'
165
+ npx one-image-optimizer
166
+ ```
167
+
168
+ ---
169
+
170
+ ## šŸ”„ Workflow Tips
171
+
172
+ ### Daily Workflow
173
+
174
+ ```bash
175
+ # Add new images to your folder
176
+ # Then run:
177
+ npx oio-compress # Quick compression
178
+
179
+ # Or for full optimization:
180
+ npx one-image-optimizer
181
+ ```
182
+
183
+ ### Before Deployment
184
+
185
+ ```bash
186
+ # Optimize all images before deploying:
187
+ npx one-image-optimizer
188
+
189
+ # Then build and deploy:
190
+ npm run build
191
+ npm run deploy
192
+ ```
193
+
194
+ ### Batch Processing
195
+
196
+ ```bash
197
+ # Process different folders one by one:
198
+ npx oio-compress # Compress first
199
+ npx oio-rename # Then rename
200
+ npx oio-webp # Finally convert to WebP
201
+ ```
202
+
203
+ ---
204
+
205
+ ## šŸŒ Global Installation (Optional)
206
+
207
+ If you use this tool frequently across multiple projects:
208
+
209
+ ```bash
210
+ # Install globally
211
+ npm install -g one-image-optimizer
212
+
213
+ # Now use shorter commands (no npx needed):
214
+ one-image-optimizer
215
+ oio-compress
216
+ oio-webp
217
+ oio-rename
218
+ ```
219
+
220
+ **Benefits:**
221
+ - āœ… Shorter commands
222
+ - āœ… Available in any directory
223
+ - āœ… No need to type `npx` every time
224
+
225
+ ---
226
+
227
+ ## āš™ļø Configuration Options Explained
228
+
229
+ ```javascript
230
+ module.exports = {
231
+ // Main folder containing your images
232
+ ROOT_FOLDER: './assets/images',
233
+
234
+ // Compress images larger than this size (in MB)
235
+ COMPRESS_THRESHOLD_MB: 1,
236
+
237
+ // Maximum width for compressed images (pixels)
238
+ MAX_WIDTH: 1920,
239
+
240
+ // Maximum height for compressed images (pixels)
241
+ MAX_HEIGHT: 1080,
242
+
243
+ // WebP quality (0-100, higher = better quality, larger file)
244
+ WEBP_QUALITY: 80,
245
+
246
+ // JPEG quality (0-100, higher = better quality, larger file)
247
+ JPEG_QUALITY: 75,
248
+
249
+ // Supported image formats
250
+ IMAGE_EXTENSIONS: ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp', '.tiff']
251
+ };
252
+ ```
253
+
254
+ ### Customization Examples:
255
+
256
+ **High Quality (Larger Files):**
257
+ ```javascript
258
+ WEBP_QUALITY: 90,
259
+ JPEG_QUALITY: 85,
260
+ ```
261
+
262
+ **Maximum Compression (Smaller Files):**
263
+ ```javascript
264
+ WEBP_QUALITY: 60,
265
+ JPEG_QUALITY: 60,
266
+ ```
267
+
268
+ **4K Images:**
269
+ ```javascript
270
+ MAX_WIDTH: 3840,
271
+ MAX_HEIGHT: 2160,
272
+ ```
273
+
274
+ **Mobile-Optimized:**
275
+ ```javascript
276
+ MAX_WIDTH: 1080,
277
+ MAX_HEIGHT: 1920,
278
+ ```
279
+
280
+ ---
281
+
282
+ ## šŸ› ļø Troubleshooting
283
+
284
+ ### Issue: "Config file not found"
285
+
286
+ **Solution:**
287
+ ```bash
288
+ # Reinstall to recreate config
289
+ npm install one-image-optimizer
290
+ ```
291
+
292
+ ### Issue: "Path does not exist"
293
+
294
+ **Solution:**
295
+ - Check that `ROOT_FOLDER` in config points to a valid directory
296
+ - Use relative paths from your project root
297
+ - Example: `./assets/images` NOT `assets/images`
298
+
299
+ ### Issue: "Commands not working"
300
+
301
+ **Solution:**
302
+ ```bash
303
+ # Update to latest version
304
+ npm install one-image-optimizer@latest
305
+
306
+ # Or reinstall
307
+ npm uninstall one-image-optimizer
308
+ npm install one-image-optimizer
309
+ ```
310
+
311
+ ### Issue: "Permission errors on Windows"
312
+
313
+ **Solution:**
314
+ - Close any programs viewing the images
315
+ - Run terminal as administrator (if needed)
316
+ - The tool has built-in Windows file lock handling
317
+
318
+ ---
319
+
320
+ ## šŸ“Š What Each Command Does
321
+
322
+ ### `npx one-image-optimizer`
323
+ - Runs ALL optimization steps in sequence
324
+ - Asks for confirmation before starting
325
+ - Best for: First-time optimization, complete cleanup
326
+
327
+ ### `npx oio-compress`
328
+ - Only compresses images larger than threshold
329
+ - Resizes if needed
330
+ - Best for: Regular maintenance, new image batches
331
+
332
+ ### `npx oio-webp`
333
+ - Converts all images to WebP format
334
+ - Deletes original files after conversion
335
+ - Best for: Web performance optimization
336
+
337
+ ### `npx oio-rename`
338
+ - Renames images based on folder names
339
+ - Format: `{foldername}image1.jpg`, `{foldername}image2.jpg`
340
+ - Best for: Organizing images, SEO-friendly names
341
+
342
+ ### `npx oio-empty`
343
+ - āš ļø **DESTRUCTIVE!** Deletes all files in folders
344
+ - Keeps folder structure
345
+ - Best for: Cleaning up before fresh import
346
+
347
+ ---
348
+
349
+ ## āœ… Quick Reference
350
+
351
+ | Task | Command |
352
+ |------|---------|
353
+ | Install | `npm install one-image-optimizer` |
354
+ | Full optimization | `npx one-image-optimizer` |
355
+ | Compress only | `npx oio-compress` |
356
+ | WebP only | `npx oio-webp` |
357
+ | Rename only | `npx oio-rename` |
358
+ | Empty folders | `npx oio-empty` |
359
+ | Global install | `npm install -g one-image-optimizer` |
360
+ | Update | `npm install one-image-optimizer@latest` |
361
+
362
+ ---
363
+
364
+ ## šŸŽ‰ You're Ready!
365
+
366
+ **3 Simple Steps:**
367
+ 1. `npm install one-image-optimizer`
368
+ 2. Edit `one-image-optimizer.config.js` (set your folder)
369
+ 3. Run `npx one-image-optimizer`
370
+
371
+ **That's it!** Your images are optimized! šŸš€
372
+
373
+ ---
374
+
375
+ **Need more help?** Check out:
376
+ - `README.md` - Full documentation
377
+ - `QUICK_START.md` - Quick reference guide
@@ -0,0 +1,261 @@
1
+ # šŸ“‹ Publishing Checklist - one-image-optimizer v1.0.1
2
+
3
+ ## āœ… Pre-Publishing Checklist
4
+
5
+ ### 1. Verify Package Structure
6
+ - [x] `bin/` directory created with all CLI files
7
+ - [x] All bin files have `#!/usr/bin/env node` shebang
8
+ - [x] `package.json` updated with correct `bin` field
9
+ - [x] Version bumped to `1.0.1`
10
+ - [x] README.md updated with new usage instructions
11
+
12
+ ### 2. Test Locally
13
+
14
+ ```bash
15
+ # Link the package locally
16
+ npm link
17
+
18
+ # Verify commands are available
19
+ Get-Command one-image-optimizer
20
+ Get-Command oio-compress
21
+ Get-Command oio-webp
22
+ Get-Command oio-rename
23
+ Get-Command oio-empty
24
+ ```
25
+
26
+ **Status:** āœ… All commands are available globally!
27
+
28
+ ### 3. Test in a Separate Project
29
+
30
+ ```bash
31
+ # Create a test directory
32
+ mkdir test-project
33
+ cd test-project
34
+ npm init -y
35
+
36
+ # Link your package
37
+ npm link one-image-optimizer
38
+
39
+ # Create a test config
40
+ # (Edit one-image-optimizer.config.js)
41
+
42
+ # Test commands
43
+ npx one-image-optimizer --help
44
+ npx oio-compress
45
+ npx oio-webp
46
+ ```
47
+
48
+ ### 4. Verify Package Contents
49
+
50
+ ```bash
51
+ # See what will be published
52
+ npm pack --dry-run
53
+
54
+ # Check the tarball
55
+ npm pack
56
+ tar -tzf one-image-optimizer-1.0.1.tgz
57
+ ```
58
+
59
+ ### 5. Check .npmignore
60
+
61
+ Ensure these are included:
62
+ - āœ… `bin/` directory
63
+ - āœ… `src/` directory
64
+ - āœ… `scripts/` directory
65
+ - āœ… `one-image-optimizer.config.js` (template)
66
+ - āœ… `package.json`
67
+ - āœ… `README.md`
68
+
69
+ Ensure these are excluded:
70
+ - āœ… `node_modules/`
71
+ - āœ… Test directories
72
+ - āœ… `.git/`
73
+ - āœ… Development files
74
+
75
+ ---
76
+
77
+ ## šŸš€ Publishing Steps
78
+
79
+ ### Step 1: Login to NPM
80
+
81
+ ```bash
82
+ npm login
83
+ ```
84
+
85
+ Enter your credentials:
86
+ - Username
87
+ - Password
88
+ - Email
89
+ - 2FA code (if enabled)
90
+
91
+ ### Step 2: Publish
92
+
93
+ ```bash
94
+ npm publish
95
+ ```
96
+
97
+ Expected output:
98
+ ```
99
+ + one-image-optimizer@1.0.1
100
+ ```
101
+
102
+ ### Step 3: Verify on NPM
103
+
104
+ Visit: https://www.npmjs.com/package/one-image-optimizer
105
+
106
+ Check:
107
+ - āœ… Version shows `1.0.1`
108
+ - āœ… README displays correctly
109
+ - āœ… Files tab shows `bin/` directory
110
+ - āœ… Package size is reasonable
111
+
112
+ ---
113
+
114
+ ## 🧪 Post-Publishing Verification
115
+
116
+ ### Test Fresh Installation
117
+
118
+ ```bash
119
+ # In a new directory
120
+ mkdir fresh-test
121
+ cd fresh-test
122
+ npm init -y
123
+
124
+ # Install from npm
125
+ npm install one-image-optimizer
126
+
127
+ # Verify config file was created
128
+ ls one-image-optimizer.config.js
129
+
130
+ # Test all commands
131
+ npx one-image-optimizer
132
+ npx oio-compress
133
+ npx oio-webp
134
+ npx oio-rename
135
+ npx oio-empty
136
+ ```
137
+
138
+ ### Expected Behavior
139
+
140
+ 1. āœ… Config file auto-created
141
+ 2. āœ… All `npx` commands work
142
+ 3. āœ… No "missing scripts" errors
143
+ 4. āœ… Commands execute properly
144
+
145
+ ---
146
+
147
+ ## šŸ“¢ Announce the Fix
148
+
149
+ ### Update Existing Users
150
+
151
+ If you have users on v1.0.0, notify them:
152
+
153
+ **GitHub Release Notes:**
154
+ ```markdown
155
+ ## v1.0.1 - CLI Commands Fixed šŸŽ‰
156
+
157
+ ### šŸ› Bug Fix
158
+ - Fixed: Commands now work properly when installed in other projects
159
+ - Users no longer need to manually add scripts to their package.json
160
+
161
+ ### šŸ”„ Migration
162
+ Update to the latest version:
163
+ ```bash
164
+ npm install one-image-optimizer@latest
165
+ ```
166
+
167
+ ### šŸ“ New Usage
168
+ Commands are now available via `npx`:
169
+ ```bash
170
+ npx one-image-optimizer
171
+ npx oio-compress
172
+ npx oio-webp
173
+ npx oio-rename
174
+ ```
175
+
176
+ See the updated [README](README.md) for full documentation.
177
+ ```
178
+
179
+ ### NPM Package Description
180
+
181
+ Update the package description on npmjs.com to include:
182
+ ```
183
+ āœ… Now with working CLI commands! Use npx one-image-optimizer to get started.
184
+ ```
185
+
186
+ ---
187
+
188
+ ## šŸ” Troubleshooting
189
+
190
+ ### If publish fails:
191
+
192
+ **Error: "You do not have permission to publish"**
193
+ ```bash
194
+ # Check you're logged in
195
+ npm whoami
196
+
197
+ # Login again
198
+ npm login
199
+ ```
200
+
201
+ **Error: "Version already exists"**
202
+ ```bash
203
+ # Bump version
204
+ npm version patch # 1.0.1 -> 1.0.2
205
+ npm publish
206
+ ```
207
+
208
+ **Error: "Package name already taken"**
209
+ - The package name is already yours, this shouldn't happen
210
+ - If it does, check you're logged in as the correct user
211
+
212
+ ---
213
+
214
+ ## šŸ“Š Success Metrics
215
+
216
+ After publishing, monitor:
217
+ - āœ… Download count increases
218
+ - āœ… No new issues about "missing scripts"
219
+ - āœ… Positive feedback from users
220
+ - āœ… Stars/forks on GitHub (if applicable)
221
+
222
+ ---
223
+
224
+ ## šŸŽÆ Next Steps After Publishing
225
+
226
+ 1. āœ… Update GitHub repository (if you have one)
227
+ 2. āœ… Add GitHub release for v1.0.1
228
+ 3. āœ… Update any documentation sites
229
+ 4. āœ… Notify users via social media/email
230
+ 5. āœ… Monitor npm downloads and issues
231
+
232
+ ---
233
+
234
+ ## šŸ“ Command Reference
235
+
236
+ ### Publishing Commands
237
+ ```bash
238
+ npm login # Login to npm
239
+ npm publish # Publish package
240
+ npm version patch # Bump patch version
241
+ npm version minor # Bump minor version
242
+ npm version major # Bump major version
243
+ ```
244
+
245
+ ### Testing Commands
246
+ ```bash
247
+ npm link # Link package locally
248
+ npm pack # Create tarball
249
+ npm pack --dry-run # Preview what will be published
250
+ ```
251
+
252
+ ### Verification Commands
253
+ ```bash
254
+ npm whoami # Check logged-in user
255
+ npm view one-image-optimizer # View package info
256
+ npm view one-image-optimizer versions # View all versions
257
+ ```
258
+
259
+ ---
260
+
261
+ **Ready to publish?** Follow the steps above and your package will be fixed! šŸš€
File without changes
package/QUICK_START.md CHANGED
@@ -1,167 +1,96 @@
1
- # šŸŽÆ QUICK START GUIDE
1
+ # šŸš€ Quick Start Guide - one-image-optimizer
2
2
 
3
- ## āœ… COMPLETED SETUP
3
+ ## Installation
4
4
 
5
- All files have been created and dependencies installed successfully!
6
-
7
- ---
8
-
9
- ## šŸ“‹ WHAT TO DO NOW (Step-by-Step)
10
-
11
- ### **STEP 1: Test Locally First** ⚔
12
-
13
- Before publishing, let's test the package:
14
-
15
- 1. **Create a test folder with images:**
16
- ```bash
17
- mkdir test-images
18
- mkdir "test-images/Product Photos"
19
- mkdir "test-images/Hero Images"
20
- ```
21
-
22
- 2. **Copy some test images** (JPG/PNG files) into these folders
23
-
24
- 3. **Edit the config file** that was just created:
25
- - Open: `one-image-optimizer.config.js`
26
- - Change `ROOT_FOLDER: './assets/images'` to `ROOT_FOLDER: './test-images'`
27
-
28
- 4. **Run the optimizer:**
29
- ```bash
30
- npm run one-image-optimizer
31
- ```
5
+ ```bash
6
+ npm install one-image-optimizer
7
+ ```
32
8
 
33
- 5. **Test individual commands:**
34
- ```bash
35
- npm run compress
36
- npm run webp
37
- ```
9
+ ## Setup
10
+
11
+ After installation, edit the auto-generated config file:
12
+
13
+ ```javascript
14
+ // one-image-optimizer.config.js
15
+ module.exports = {
16
+ ROOT_FOLDER: './assets/images', // šŸ‘ˆ Change this to your images folder
17
+ COMPRESS_THRESHOLD_MB: 1,
18
+ MAX_WIDTH: 1920,
19
+ MAX_HEIGHT: 1080,
20
+ WEBP_QUALITY: 80,
21
+ JPEG_QUALITY: 75,
22
+ IMAGE_EXTENSIONS: ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp', '.tiff']
23
+ };
24
+ ```
38
25
 
39
- ---
26
+ ## Usage
40
27
 
41
- ### **STEP 2: Publish to npm** šŸ“¦
28
+ ### Full Optimization (Recommended)
42
29
 
43
- Once testing is successful:
30
+ Run all steps in sequence:
44
31
 
45
- 1. **Login to npm:**
46
- ```bash
47
- npm login
48
- ```
49
- (Create account at https://npmjs.com if needed)
32
+ ```bash
33
+ npx one-image-optimizer
34
+ ```
50
35
 
51
- 2. **Update package.json:**
52
- - Change `"author": "Your Name"` to your actual name
53
- - Add your email and repository URL
36
+ This will:
37
+ 1. āœ… Compress images > 1MB
38
+ 2. āœ… Rename based on folder names
39
+ 3. āœ… Convert to WebP format
54
40
 
55
- 3. **Publish:**
56
- ```bash
57
- npm publish
58
- ```
41
+ ### Individual Commands
59
42
 
60
- 4. **If name is taken**, update package.json:
61
- ```json
62
- {
63
- "name": "@yourusername/one-image-optimizer"
64
- }
65
- ```
43
+ ```bash
44
+ # Compress only
45
+ npx oio-compress
66
46
 
67
- ---
47
+ # Convert to WebP only
48
+ npx oio-webp
68
49
 
69
- ## šŸŽ® COMMANDS AVAILABLE
50
+ # Rename only
51
+ npx oio-rename
70
52
 
71
- | Command | Description |
72
- |---------|-------------|
73
- | `npm run one-image-optimizer` | Run full optimization (compress → rename → webp) |
74
- | `npm run compress` | Compress images > 1MB only |
75
- | `npm run webp` | Convert to WebP only |
76
- | `npm run empty-folders` | Delete all files (āš ļø destructive) |
53
+ # Empty folders (āš ļø destructive!)
54
+ npx oio-empty
55
+ ```
77
56
 
78
- ---
57
+ ## Global Installation (Optional)
79
58
 
80
- ## šŸ“ FILES CREATED
81
-
82
- āœ… `package.json` - Package configuration with all dependencies
83
- āœ… `src/cli.js` - CLI entry point
84
- āœ… `src/index.js` - Main orchestrator with confirmation prompts
85
- āœ… `src/utils.js` - Config loader and utilities
86
- āœ… `src/imagescompress.js` - Compression logic (refactored)
87
- āœ… `src/imgfolderrename.js` - Rename logic (refactored)
88
- āœ… `src/webpconverter.js` - WebP conversion (refactored)
89
- āœ… `src/emptythefolder.js` - Empty folders logic (refactored)
90
- āœ… `src/scripts/compress-only.js` - Individual compress command
91
- āœ… `src/scripts/webp-only.js` - Individual webp command
92
- āœ… `src/scripts/empty-folders-only.js` - Individual empty command
93
- āœ… `scripts/postinstall.js` - Auto-creates config file
94
- āœ… `one-image-optimizer.config.js` - Config template
95
- āœ… `README.md` - User documentation
96
- āœ… `.npmignore` - Exclude test files from package
97
- āœ… `IMPLEMENTATION_GUIDE.md` - Full implementation guide
59
+ For shorter commands:
98
60
 
99
- ---
61
+ ```bash
62
+ npm install -g one-image-optimizer
100
63
 
101
- ## šŸ”§ HOW IT WORKS
64
+ # Then use without npx:
65
+ one-image-optimizer
66
+ oio-compress
67
+ oio-webp
68
+ oio-rename
69
+ ```
102
70
 
103
- ### When users install your package:
71
+ ## Common Issues
104
72
 
73
+ ### Config file not found
105
74
  ```bash
75
+ # Reinstall to recreate config
106
76
  npm install one-image-optimizer
107
77
  ```
108
78
 
109
- 1. āœ… Package is installed to `node_modules/`
110
- 2. āœ… Postinstall script runs automatically
111
- 3. āœ… Config file `one-image-optimizer.config.js` is created in their project root
112
- 4. āœ… User edits config to set their image folder path
113
- 5. āœ… User runs: `npm run one-image-optimizer`
114
- 6. āœ… Confirmation prompt appears
115
- 7. āœ… All optimizations run in sequence:
116
- - Compress images > 1MB
117
- - Rename based on folder names
118
- - Convert to WebP format
119
-
120
- ---
121
-
122
- ## āš™ļø KEY FEATURES IMPLEMENTED
123
-
124
- āœ… **Auto-config creation** - Config file created on install
125
- āœ… **Confirmation prompts** - User must confirm before changes
126
- āœ… **Sequential execution** - Scripts run one after another
127
- āœ… **Individual commands** - Can run each script separately
128
- āœ… **Config-based paths** - No hardcoded paths
129
- āœ… **Windows support** - File lock handling included
130
- āœ… **Colored output** - Beautiful console messages
131
- āœ… **Error handling** - Graceful error messages
132
- āœ… **Progress tracking** - Shows step-by-step progress
133
-
134
- ---
135
-
136
- ## 🚨 IMPORTANT NOTES
137
-
138
- 1. **Test thoroughly** before publishing
139
- 2. **Use test images** you don't mind modifying
140
- 3. **Backup important images** before running
141
- 4. **The empty-folders command is destructive** - use with caution
142
- 5. **Package name must be unique** on npm
143
-
144
- ---
145
-
146
- ## šŸ“ž NEXT IMMEDIATE STEPS
147
-
148
- 1. āœ… Dependencies installed ← **DONE**
149
- 2. ā³ Create test folder with images ← **DO THIS NOW**
150
- 3. ā³ Edit config file
151
- 4. ā³ Run `npm run one-image-optimizer`
152
- 5. ā³ Verify it works
153
- 6. ā³ Publish to npm
154
-
155
- ---
79
+ ### Commands not working
80
+ ```bash
81
+ # Update to latest version
82
+ npm install one-image-optimizer@latest
156
83
 
157
- ## šŸ“š DOCUMENTATION
84
+ # Clear cache and reinstall
85
+ npm cache clean --force
86
+ rm -rf node_modules
87
+ npm install
88
+ ```
158
89
 
159
- - **Full Guide:** `IMPLEMENTATION_GUIDE.md`
160
- - **User Docs:** `README.md`
161
- - **Config Template:** `one-image-optimizer.config.js`
90
+ ### Path does not exist
91
+ - Check `ROOT_FOLDER` in config points to a valid directory
92
+ - Use relative paths from project root (e.g., `./assets/images`)
162
93
 
163
94
  ---
164
95
 
165
- **You're ready to test! šŸš€**
166
-
167
- Start by creating a test folder with some images and running the optimizer.
96
+ **Need help?** Check the full [README.md](README.md) for detailed documentation.
package/README.md CHANGED
@@ -45,7 +45,13 @@ module.exports = {
45
45
  Run all optimization steps in sequence:
46
46
 
47
47
  ```bash
48
- npm run one-image-optimizer
48
+ npx one-image-optimizer
49
+ ```
50
+
51
+ Or if installed globally:
52
+
53
+ ```bash
54
+ one-image-optimizer
49
55
  ```
50
56
 
51
57
  This will:
@@ -61,13 +67,28 @@ Run specific optimization steps:
61
67
 
62
68
  ```bash
63
69
  # Compress images only
64
- npm run compress
70
+ npx oio-compress
65
71
 
66
72
  # Convert to WebP only
67
- npm run webp
73
+ npx oio-webp
74
+
75
+ # Rename images only
76
+ npx oio-rename
68
77
 
69
78
  # Empty all files in folders (āš ļø destructive!)
70
- npm run empty-folders
79
+ npx oio-empty
80
+ ```
81
+
82
+ **Tip:** You can also install globally to use shorter commands:
83
+
84
+ ```bash
85
+ npm install -g one-image-optimizer
86
+
87
+ # Then use without npx:
88
+ one-image-optimizer
89
+ oio-compress
90
+ oio-webp
91
+ oio-rename
71
92
  ```
72
93
 
73
94
  ## šŸ“‹ How It Works
@@ -121,11 +142,12 @@ npm install one-image-optimizer
121
142
  # Set ROOT_FOLDER to your images directory
122
143
 
123
144
  # 3. Run full optimization
124
- npm run one-image-optimizer
145
+ npx one-image-optimizer
125
146
 
126
147
  # 4. Or run individual commands
127
- npm run compress
128
- npm run webp
148
+ npx oio-compress
149
+ npx oio-webp
150
+ npx oio-rename
129
151
  ```
130
152
 
131
153
  ## šŸ› Troubleshooting
File without changes
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ const compressImageMain = require("../src/imagescompress");
4
+ const { loadConfig } = require("../src/utils");
5
+ const chalk = require("chalk");
6
+
7
+ async function run() {
8
+ try {
9
+ console.log(
10
+ chalk.cyan.bold(
11
+ "\n╔════════════════════════════════════════════════════════╗",
12
+ ),
13
+ );
14
+ console.log(
15
+ chalk.cyan.bold(
16
+ "ā•‘ ONE IMAGE OPTIMIZER - Compress Only ā•‘",
17
+ ),
18
+ );
19
+ console.log(
20
+ chalk.cyan.bold(
21
+ "ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n",
22
+ ),
23
+ );
24
+
25
+ const config = loadConfig();
26
+ await compressImageMain(config);
27
+
28
+ console.log(chalk.green.bold("āœ… Compression complete!\n"));
29
+ } catch (error) {
30
+ console.error(chalk.red("āŒ Error:"), error.message);
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ run();
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ const emptyFoldersMain = require("../src/emptythefolder");
4
+ const { loadConfig } = require("../src/utils");
5
+ const chalk = require("chalk");
6
+
7
+ async function run() {
8
+ try {
9
+ console.log(
10
+ chalk.cyan.bold(
11
+ "\n╔════════════════════════════════════════════════════════╗",
12
+ ),
13
+ );
14
+ console.log(
15
+ chalk.cyan.bold(
16
+ "ā•‘ ONE IMAGE OPTIMIZER - Empty Folders Only ā•‘",
17
+ ),
18
+ );
19
+ console.log(
20
+ chalk.cyan.bold(
21
+ "ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n",
22
+ ),
23
+ );
24
+
25
+ const config = loadConfig();
26
+ await emptyFoldersMain(config);
27
+
28
+ console.log(chalk.green.bold("āœ… Folders emptied!\n"));
29
+ } catch (error) {
30
+ console.error(chalk.red("āŒ Error:"), error.message);
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ run();
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ const runAllOptimizations = require("../src/index");
4
+
5
+ // Run the main optimization function
6
+ runAllOptimizations().catch((error) => {
7
+ console.error("Fatal error:", error);
8
+ process.exit(1);
9
+ });
package/bin/rename.js ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ const renameImagesMain = require("../src/imgfolderrename");
4
+ const { loadConfig } = require("../src/utils");
5
+ const chalk = require("chalk");
6
+
7
+ async function run() {
8
+ try {
9
+ console.log(
10
+ chalk.cyan.bold(
11
+ "\n╔════════════════════════════════════════════════════════╗",
12
+ ),
13
+ );
14
+ console.log(
15
+ chalk.cyan.bold(
16
+ "ā•‘ ONE IMAGE OPTIMIZER - Rename Only ā•‘",
17
+ ),
18
+ );
19
+ console.log(
20
+ chalk.cyan.bold(
21
+ "ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n",
22
+ ),
23
+ );
24
+
25
+ const config = loadConfig();
26
+ await renameImagesMain(config);
27
+
28
+ console.log(chalk.green.bold("āœ… Renaming complete!\n"));
29
+ } catch (error) {
30
+ console.error(chalk.red("āŒ Error:"), error.message);
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ run();
package/bin/webp.js ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ const convertImageToWebpMain = require("../src/webpconverter");
4
+ const { loadConfig } = require("../src/utils");
5
+ const chalk = require("chalk");
6
+
7
+ async function run() {
8
+ try {
9
+ console.log(
10
+ chalk.cyan.bold(
11
+ "\n╔════════════════════════════════════════════════════════╗",
12
+ ),
13
+ );
14
+ console.log(
15
+ chalk.cyan.bold(
16
+ "ā•‘ ONE IMAGE OPTIMIZER - WebP Only ā•‘",
17
+ ),
18
+ );
19
+ console.log(
20
+ chalk.cyan.bold(
21
+ "ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n",
22
+ ),
23
+ );
24
+
25
+ const config = loadConfig();
26
+ await convertImageToWebpMain(config);
27
+
28
+ console.log(chalk.green.bold("āœ… WebP conversion complete!\n"));
29
+ } catch (error) {
30
+ console.error(chalk.red("āŒ Error:"), error.message);
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ run();
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "one-image-optimizer",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "src/index.js",
5
5
  "description": "Optimize PNG, JPEG images by compressing them and converting them to webp format.",
6
6
  "keywords": ["npm", "image", "optimizer", "webp", "compress", "tool"],
7
7
  "author": "Your Name",
8
8
  "license": "MIT",
9
9
  "bin": {
10
- "one-image-optimizer": "src/cli.js"
10
+ "one-image-optimizer": "bin/one-image-optimizer.js",
11
+ "oio-compress": "bin/compress.js",
12
+ "oio-webp": "bin/webp.js",
13
+ "oio-rename": "bin/rename.js",
14
+ "oio-empty": "bin/empty-folders.js"
11
15
  },
12
16
  "scripts": {
13
- "postinstall": "node scripts/postinstall.js",
14
- "one-image-optimizer": "node src/cli.js",
15
- "compress": "node src/scripts/compress-only.js",
16
- "webp": "node src/scripts/webp-only.js",
17
- "empty-folders": "node src/scripts/empty-folders-only.js",
18
- "rename": "node src/scripts/rename-only.js"
17
+ "postinstall": "node scripts/postinstall.js"
19
18
  },
20
19
  "dependencies": {
21
20
  "sharp": "^0.33.0",