Skip to content

Commit

Permalink
feat(cli): show warning when ImageOptim.app is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Dec 23, 2018
1 parent 24c4e37 commit 44f3055
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const PNGQUANT_SPEED = '1';
export const PNGQUANT_BIN_PATH = '/Applications/ImageAlpha.app/Contents/MacOS/pngquant';
export const IMAGEOPTIM_BIN_PATH = '/Applications/ImageOptim.app/Contents/MacOS/ImageOptim';

export const HOMEPAGE_URL = 'https://github.com/JamieMason/ImageOptim-CLI';
export const ASSISTIVE_DEVICES_URL = `${HOMEPAGE_URL}/#jpegmini-and-support-for-assistive-devices`;
export const IMAGEALPHA_URL = 'https://pngmini.com/';
export const IMAGEOPTIM_URL = 'https://imageoptim.com/mac';
export const JPEG_MINI_URL = 'https://itunes.apple.com/us/app/jpegmini/id498944723';

export const IMAGEALPHA: IApp = {
bundleId: 'net.pornel.ImageAlpha',
name: 'ImageAlpha',
Expand Down
8 changes: 6 additions & 2 deletions src/run-imagealpha.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { pathExists } from 'fs-extra';
import { AppRunner, IOptions } from '.';
import { IMAGEALPHA } from './constants';
import { IMAGEALPHA, IMAGEALPHA_URL, PNGQUANT_BIN_PATH } from './constants';
import { isSupported } from './is-supported';
import { info, verbose } from './log';
import { info, verbose, warning } from './log';
import { pngquant } from './pngquant';

export const runImageAlpha: AppRunner = async (options: IOptions) => {
info(`Running ${IMAGEALPHA.name}...`);
const pngFilePaths = options.files.supported
.map((file) => file.tmp)
.filter(isSupported(IMAGEALPHA.supports));
if (!(await pathExists(PNGQUANT_BIN_PATH))) {
return warning(`ImageAlpha.app is not installed (${IMAGEALPHA_URL})`);
}
await pngquant(pngFilePaths, options);
verbose(`${IMAGEALPHA.name} has finished`);
};
8 changes: 6 additions & 2 deletions src/run-imageoptim.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { stdout } from 'execa';
import { pathExists } from 'fs-extra';
import { AppRunner } from '.';
import { IMAGEOPTIM, IMAGEOPTIM_BIN_PATH } from './constants';
import { info, verbose } from './log';
import { IMAGEOPTIM, IMAGEOPTIM_BIN_PATH, IMAGEOPTIM_URL } from './constants';
import { info, verbose, warning } from './log';

export const runImageOptim: AppRunner = async (options) => {
info(`Running ${IMAGEOPTIM.name}...`);
if (!(await pathExists(IMAGEOPTIM_BIN_PATH))) {
return warning(`ImageOptim.app is not installed (${IMAGEOPTIM_URL})`);
}
await stdout(IMAGEOPTIM_BIN_PATH, [options.tmpDir]);
verbose(`${IMAGEOPTIM.name} has finished`);
};
9 changes: 3 additions & 6 deletions src/run-jpegmini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import {
runJpegMini as startJpegMini,
supportsAssistiveDevices
} from './applescript';
import { ASSISTIVE_DEVICES_URL, HOMEPAGE_URL, JPEG_MINI_URL } from './constants';
import { info, verbose, warning } from './log';

export const runJpegMini: AppRunner = async (options) => {
const homepageUrl = 'https://github.com/JamieMason/ImageOptim-CLI';
const jpegMiniUrl = 'https://itunes.apple.com/us/app/jpegmini/id498944723';
const assistiveDevicesUrl = `${homepageUrl}/#jpegmini-and-support-for-assistive-devices`;

verbose('Locating JPEGmini installation');
const jpegMini = getJpegMini();

Expand All @@ -21,11 +18,11 @@ export const runJpegMini: AppRunner = async (options) => {
const [app, canAutomate] = await Promise.all([jpegMini, assistiveDeviceSupport]);

if (!app) {
return warning(`JPEGmini is not installed (${jpegMiniUrl})`);
return warning(`JPEGmini is not installed (${JPEG_MINI_URL})`);
}

if (!canAutomate) {
return warning(`Support for assistive devices needed, see ${assistiveDevicesUrl}`);
return warning(`Support for assistive devices needed, see ${ASSISTIVE_DEVICES_URL}`);
}

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

0 comments on commit 44f3055

Please sign in to comment.