auto-image-converter 1.1.13 → 1.1.14
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 +15 -15
- package/package.json +1 -1
package/bin/watcher.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import chokidar from "chokidar";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import { convertImages } from "../lib/converter.js";
|
|
@@ -9,29 +8,30 @@ const config = (await import(pathToFileURL(configPath).href)).default;
|
|
|
9
8
|
|
|
10
9
|
const watchDir = config.dir || "public";
|
|
11
10
|
const absWatchDir = path.resolve(process.cwd(), watchDir);
|
|
11
|
+
const watchPath = path.join(absWatchDir, "**", "*.{png,jpg,jpeg}");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
const watchPath = absWatchDir;
|
|
15
|
-
|
|
16
|
-
console.log(`👀 Watching for image changes on directory: ${watchPath}`);
|
|
13
|
+
console.log(`👀 Watching for image changes on directory: ${absWatchDir}`);
|
|
17
14
|
|
|
18
15
|
chokidar
|
|
19
16
|
.watch(watchPath, {
|
|
20
|
-
ignored: /(^|[\/\\])\../, // игнор скрытых файлов и папок
|
|
21
|
-
persistent: true,
|
|
22
17
|
ignoreInitial: true,
|
|
23
18
|
awaitWriteFinish: {
|
|
24
|
-
stabilityThreshold: 500,
|
|
19
|
+
stabilityThreshold: 500,
|
|
25
20
|
pollInterval: 100,
|
|
26
21
|
},
|
|
27
22
|
})
|
|
28
23
|
.on("add", async (filePath) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
console.log(`➕ New image: ${filePath}`);
|
|
25
|
+
try {
|
|
26
|
+
// Запускаем полную конвертацию всех файлов из конфига
|
|
27
|
+
await convertImages({
|
|
28
|
+
dir: absDir,
|
|
29
|
+
format: config.targetFormat || config.format || "webp",
|
|
30
|
+
quality: config.quality ?? 80,
|
|
31
|
+
recursive: config.recursive ?? true,
|
|
32
|
+
removeOriginal: config.removeOriginal ?? false,
|
|
33
|
+
});
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error("Ошибка при конвертации:", err.message);
|
|
36
36
|
}
|
|
37
37
|
});
|