Skip to content

Commit afa70fc

Browse files
committed
[init]: Initial Code
0 parents  commit afa70fc

File tree

5 files changed

+1274
-0
lines changed

5 files changed

+1274
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
import { program } from "commander";
4+
import path from "path";
5+
import fs from "fs";
6+
import { optimizeImages, watchDirectory } from "./utils/optimize.js";
7+
8+
program
9+
.name("optimize-images")
10+
.description("CLI tool for compressing and optimizing images")
11+
.version("1.0.0");
12+
13+
program
14+
.argument("<input>", "Input directory containing images")
15+
.option("-o, --output <directory>", "Output directory", "./optimized")
16+
.option("-q, --quality <number>", "Quality level (1-100)", "80")
17+
.option("--format <type>", "Output format (jpeg, png, webp, avif)", "jpeg")
18+
.option("--width <number>", "Max width of images")
19+
.option("--height <number>", "Max height of images")
20+
.option("--watch", "Watch the input directory for changes")
21+
.option("--report", "Generate optimization report");
22+
23+
program.action((input, options) => {
24+
const inputDir = path.resolve(input);
25+
const outputDir = path.resolve(options.output);
26+
27+
if (!fs.existsSync(inputDir)) {
28+
console.error(`Input directory does not exist: ${inputDir}`);
29+
process.exit(1);
30+
}
31+
32+
if (options.watch) {
33+
console.log(`Watching ${inputDir} for changes...`);
34+
watchDirectory(inputDir, outputDir, options);
35+
} else {
36+
optimizeImages(inputDir, outputDir, options);
37+
}
38+
});
39+
40+
program.parse(process.argv);

0 commit comments

Comments
 (0)