auto-image-converter 1.0.10 → 1.0.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/index.js +13 -3
- package/lib/converter.js +5 -3
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -2,15 +2,25 @@
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
4
4
|
import { convertImages } from "../lib/converter.js";
|
|
5
|
-
import fs from "fs/promises";
|
|
6
5
|
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
6
|
const CONFIG_PATH = path.resolve(process.cwd(), "image-converter.config.mjs");
|
|
9
7
|
|
|
10
8
|
try {
|
|
11
9
|
const configModule = await import(pathToFileURL(CONFIG_PATH).href);
|
|
12
10
|
const config = configModule.default;
|
|
13
|
-
|
|
11
|
+
|
|
12
|
+
const absDir = path.resolve(
|
|
13
|
+
process.cwd(),
|
|
14
|
+
config.source || config.dir || "."
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
await convertImages({
|
|
18
|
+
dir: absDir,
|
|
19
|
+
format: config.targetFormat || config.format || "webp",
|
|
20
|
+
quality: config.quality ?? 80,
|
|
21
|
+
recursive: config.recursive ?? true,
|
|
22
|
+
removeOriginal: config.removeOriginal ?? false,
|
|
23
|
+
});
|
|
14
24
|
} catch (e) {
|
|
15
25
|
console.error("❌ Ошибка загрузки конфигурации:", e.message);
|
|
16
26
|
process.exit(1);
|
package/lib/converter.js
CHANGED
|
@@ -13,9 +13,11 @@ export async function convertImages({
|
|
|
13
13
|
removeOriginal,
|
|
14
14
|
}) {
|
|
15
15
|
const pattern = recursive
|
|
16
|
-
?
|
|
17
|
-
:
|
|
18
|
-
|
|
16
|
+
? path.join(dir, "**", "*.{png,jpg,jpeg}")
|
|
17
|
+
: path.join(dir, "*.{png,jpg,jpeg}");
|
|
18
|
+
console.log("Ищу файлы по пути:", pattern);
|
|
19
|
+
const files = await fg(pattern, { caseSensitiveMatch: false });
|
|
20
|
+
console.log("Текущая директория:", process.cwd());
|
|
19
21
|
console.log("нашел файлы", files);
|
|
20
22
|
|
|
21
23
|
for (const file of files) {
|