auto-image-converter 1.1.5 → 1.1.7

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.
Files changed (2) hide show
  1. package/bin/watcher.mjs +21 -13
  2. package/package.json +2 -2
package/bin/watcher.mjs CHANGED
@@ -3,22 +3,30 @@ import chokidar from "chokidar";
3
3
  import path from "path";
4
4
  import { convertImages } from "../lib/converter.js";
5
5
  import { pathToFileURL } from "url";
6
- import { fileURLToPath } from "url";
7
6
 
8
7
  const configPath = path.resolve(process.cwd(), "image-converter.config.mjs");
8
+
9
+ // Импортируем конфиг
9
10
  const config = (await import(pathToFileURL(configPath).href)).default;
10
11
 
11
- const watcher = chokidar.watch(config.dir || "public", {
12
- ignored: /(^|[\/\\])\../,
13
- persistent: true,
14
- ignoreInitial: false,
15
- });
12
+ // Для наблюдения используем путь из конфига (fallback "public")
13
+ const watchPath = config.dir
14
+ ? path.posix.join(
15
+ config.dir.split(path.sep).join(path.posix.sep),
16
+ "**",
17
+ "*.{png,jpg,jpeg}"
18
+ )
19
+ : "public/**/*.{png,jpg,jpeg}";
16
20
 
17
- console.log("👀 Watching for image changes...");
21
+ console.log(`👀 Watching for image changes on: ${watchPath}`);
18
22
 
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
- });
23
+ chokidar
24
+ .watch(watchPath, { ignoreInitial: false })
25
+ .on("add", async (filePath) => {
26
+ console.log(`➕ New image: ${filePath}`);
27
+ try {
28
+ await convertImages(config);
29
+ } catch (err) {
30
+ console.error("Ошибка при конвертации:", err.message);
31
+ }
32
+ });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "auto-image-converter",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "auto-convert-images": "./bin/index.js",
7
- "auto-convert-images:watch": "./bin/watcher.mjs"
7
+ "auto-convert-images-watch": "./bin/watcher.mjs"
8
8
  },
9
9
  "dependencies": {
10
10
  "chokidar": "^4.0.3",