-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.js
executable file
·37 lines (33 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { pathToFileURL } from 'node:url';
import checkConfigPath from './lib/checkConfigPath.js';
import convert from './lib/convert.js';
import findConfig from './lib/findConfig.js';
import { enableVerbose } from './lib/log.js';
import optimize from './lib/optimize.js';
import prepareConfig from './lib/prepareConfig.js';
import prepareFilePaths from './lib/prepareFilePaths.js';
import prepareOutputPath from './lib/prepareOutputPath.js';
export default async function optimizt({ paths, avif, webp, force, lossless, verbose, output, config }) {
const configFilepath = pathToFileURL(config ? checkConfigPath(config) : findConfig());
const configData = await import(configFilepath);
const preparedConfig = prepareConfig(configData);
if (verbose) enableVerbose();
if (avif || webp) {
await convert({
paths: prepareFilePaths(paths, ['gif', 'jpeg', 'jpg', 'png']),
lossless,
avif,
webp,
force,
output: prepareOutputPath(output),
config: preparedConfig.convert,
});
} else {
await optimize({
paths: prepareFilePaths(paths, ['gif', 'jpeg', 'jpg', 'png', 'svg']),
lossless,
output: prepareOutputPath(output),
config: preparedConfig.optimize,
});
}
}