-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.js
49 lines (39 loc) · 1.21 KB
/
images.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
38
39
40
41
42
43
44
45
46
47
48
49
const { Command, flags } = require("@oclif/command");
const { spawn } = require("child_process");
const ora = require("ora");
class ImagesCommand extends Command {
async run() {
if (process.platform !== 'darwin') {
console.error('Non-macOS platforms not supported.')
process.exit(1);
}
const { flags } = this.parse(ImagesCommand);
const spinner = ora('Optimizing images').start();
const cmd = spawn("npx", [
"imageoptim",
'.',
`--quality ${flags.quality}`,
'-S'
]);
cmd.on("exit", (code) => {
if (code !== 0) {
return spinner.fail("Something went wrong. Use ImageOptim app directly: https://imageoptim.com/mac");
}
spinner.succeed('Images optimized');
});
}
}
ImagesCommand.description = `Optimize images to make them smaller - mac OS only
Optimize jpeg/jpg, png, gif, svg and webp files to make them web-ready
Requires ImageOptim to be installed in the system.
Install via brew: "brew update && brew cask install imageoptim"
Install with GUI: https://imageoptim.com/mac
`;
ImagesCommand.flags = {
quality: flags.string({
char: "q",
description: "Quality range",
default: "70-85",
})
};
module.exports = ImagesCommand;