Skip to content

Commit 6c3d799

Browse files
committed
fix(cli): exit with error status if an app is not installed
BREAKING CHANGE: The following scenarios will display an error and exit with a status code of 1, where previously they would display a warning: + Not using `--no-imageoptim` when ImageOptim.app is not installed. + Using `--imagealpha` when ImageAlpha.app is not installed. + Using `--jpegmini` when JPEGmini.app is not installed. Closes #180
1 parent e7c84ac commit 6c3d799

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/log.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export const bug = (err: Error): void => {
1616
process.exit(1);
1717
};
1818

19+
export const panic = (value: string): void => {
20+
console.log(color.red('! %s'), value);
21+
process.exit(1);
22+
};
23+
1924
export const result = (
2025
label: string = 'TOTAL',
2126
prettySizeBefore: string,

src/run-imagealpha.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { pathExists } from 'fs-extra';
22
import { AppRunner, IOptions } from '.';
33
import { IMAGEALPHA, IMAGEALPHA_URL, PNGQUANT_BIN_PATH } from './constants';
44
import { isSupported } from './is-supported';
5-
import { info, verbose, warning } from './log';
5+
import { info, panic, verbose } from './log';
66
import { pngquant } from './pngquant';
77

88
export const runImageAlpha: AppRunner = async (options: IOptions) => {
@@ -11,7 +11,7 @@ export const runImageAlpha: AppRunner = async (options: IOptions) => {
1111
.map((file) => file.tmp)
1212
.filter(isSupported(IMAGEALPHA.supports));
1313
if (!(await pathExists(PNGQUANT_BIN_PATH))) {
14-
return warning(`ImageAlpha.app is not installed (${IMAGEALPHA_URL})`);
14+
return panic(`ImageAlpha.app is not installed (${IMAGEALPHA_URL})`);
1515
}
1616
await pngquant(pngFilePaths, options);
1717
verbose(`${IMAGEALPHA.name} has finished`);

src/run-imageoptim.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as execa from 'execa';
22
import { pathExists } from 'fs-extra';
33
import { AppRunner } from '.';
44
import { IMAGEOPTIM, IMAGEOPTIM_BIN_PATH, IMAGEOPTIM_URL } from './constants';
5-
import { info, verbose, warning } from './log';
5+
import { info, panic, verbose } from './log';
66

77
export const runImageOptim: AppRunner = async (options) => {
88
info(`Running ${IMAGEOPTIM.name}...`);
99
if (!(await pathExists(IMAGEOPTIM_BIN_PATH))) {
10-
return warning(`ImageOptim.app is not installed (${IMAGEOPTIM_URL})`);
10+
return panic(`ImageOptim.app is not installed (${IMAGEOPTIM_URL})`);
1111
}
1212
await execa(IMAGEOPTIM_BIN_PATH, [options.tmpDir]);
1313
verbose(`${IMAGEOPTIM.name} has finished`);

src/run-jpegmini.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
runJpegMini as startJpegMini,
66
supportsAssistiveDevices
77
} from './applescript';
8-
import { ASSISTIVE_DEVICES_URL, HOMEPAGE_URL, JPEG_MINI_URL } from './constants';
9-
import { info, verbose, warning } from './log';
8+
import { ASSISTIVE_DEVICES_URL, JPEG_MINI_URL } from './constants';
9+
import { info, panic, verbose } from './log';
1010

1111
export const runJpegMini: AppRunner = async (options) => {
1212
verbose('Locating JPEGmini installation');
@@ -18,11 +18,11 @@ export const runJpegMini: AppRunner = async (options) => {
1818
const [app, canAutomate] = await Promise.all([jpegMini, assistiveDeviceSupport]);
1919

2020
if (!app) {
21-
return warning(`JPEGmini is not installed (${JPEG_MINI_URL})`);
21+
return panic(`JPEGmini is not installed (${JPEG_MINI_URL})`);
2222
}
2323

2424
if (!canAutomate) {
25-
return warning(`Support for assistive devices needed, see ${ASSISTIVE_DEVICES_URL}`);
25+
return panic(`Support for assistive devices needed, see ${ASSISTIVE_DEVICES_URL}`);
2626
}
2727

2828
info(`Running ${app.name}...`);

0 commit comments

Comments
 (0)