auto-image-converter 1.1.10 → 1.1.12
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/bin/watcher.mjs +16 -7
- package/package.json +1 -1
package/bin/watcher.mjs
CHANGED
|
@@ -9,13 +9,22 @@ const config = (await import(pathToFileURL(configPath).href)).default;
|
|
|
9
9
|
|
|
10
10
|
const watchDir = config.dir || "public";
|
|
11
11
|
const absWatchDir = path.resolve(process.cwd(), watchDir);
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
// В chokidar нужно передавать glob с POSIX слэшами
|
|
14
|
+
const baseDirPosix = absWatchDir.split(path.sep).join(path.posix.sep);
|
|
15
|
+
const watchPath = `${baseDirPosix}/**/*.{png,jpg,jpeg}`;
|
|
13
16
|
|
|
14
17
|
console.log(`👀 Watching for image changes on: ${watchPath}`);
|
|
15
18
|
|
|
16
|
-
chokidar
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
chokidar
|
|
20
|
+
.watch(watchPath, { ignoreInitial: true })
|
|
21
|
+
.on("add", async (filePath) => {
|
|
22
|
+
if (/\.(png|jpe?g)$/i.test(filePath)) {
|
|
23
|
+
console.log(`➕ New image: ${filePath}`);
|
|
24
|
+
try {
|
|
25
|
+
await convertImages(config);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error("Ошибка при конвертации:", err.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|