auto-image-converter 1.0.19 → 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.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import chokidar from "chokidar";
3
+ import path from "path";
4
+ import { convertImages } from "../lib/converter.js";
5
+ import { pathToFileURL } from "url";
6
+ import { fileURLToPath } from "url";
7
+
8
+ const configPath = path.resolve(process.cwd(), "image-converter.config.mjs");
9
+ const config = (await import(pathToFileURL(configPath).href)).default;
10
+
11
+ const watcher = chokidar.watch(config.dir || "public", {
12
+ ignored: /(^|[\/\\])\../,
13
+ persistent: true,
14
+ ignoreInitial: false,
15
+ });
16
+
17
+ console.log("👀 Watching for image changes...");
18
+
19
+ watcher.on("add", async (filePath) => {
20
+ if (/\.(png|jpe?g)$/i.test(filePath)) {
21
+ console.log("➕ New image:", filePath);
22
+ await convertImages(config);
23
+ }
24
+ });
package/lib/converter.js CHANGED
@@ -16,17 +16,12 @@ export async function convertImages({
16
16
  ? path.join(dir, "**", "*.{png,jpg,jpeg}")
17
17
  : path.join(dir, "*.{png,jpg,jpeg}");
18
18
 
19
- // Преобразуем \ → /
20
19
  const pattern = rawPattern.split(path.sep).join(path.posix.sep);
21
- console.log("Ищу файлы по пути:", pattern);
22
20
  const files = await fg(pattern, { caseSensitiveMatch: false });
23
- console.log("Текущая директория:", process.cwd());
24
- console.log(`нашел файлы, ${files}, количество, ${files.length}`);
25
21
 
26
22
  for (const file of files) {
27
23
  const ext = path.extname(file);
28
24
  const outFile = file.replace(ext, `.${format}`);
29
- console.log(`Записываю файл: ${outFile}`);
30
25
 
31
26
  const image = sharp(file);
32
27
  const buffer =
@@ -36,7 +31,6 @@ export async function convertImages({
36
31
 
37
32
  await fs.writeFile(outFile, buffer);
38
33
  if (removeOriginal) await fs.unlink(file);
39
-
40
34
  console.log(`✓ ${file} → ${outFile}`);
41
35
  }
42
36
  }
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "auto-image-converter",
3
- "version": "1.0.19",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "bin": {
6
- "auto-convert-images": "./bin/index.js"
6
+ "auto-convert-images": "./bin/index.js",
7
+ "auto-convert-images:watch": "./bin/watch.mjs"
7
8
  },
8
9
  "dependencies": {
10
+ "chokidar": "^4.0.3",
9
11
  "commander": "^14.0.0",
10
12
  "fast-glob": "^3.3.3",
11
13
  "sharp": "^0.34.2"