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