Skip to content

Commit

Permalink
fix(npm): update dependencies
Browse files Browse the repository at this point in the history
Refs #191
  • Loading branch information
JamieMason committed Nov 13, 2021
1 parent 060c40a commit 585f08e
Show file tree
Hide file tree
Showing 19 changed files with 1,212 additions and 2,616 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
env: {
es6: true,
node: true,
},
overrides: [
{
files: ['*.ts'],
rules: {
'@typescript-eslint/no-var-requires': 0
},
},
{
files: ['*.spec.ts'],
env: {
jest: true,
},
},
],
};
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.11.1
16.13.0
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"arrowParens": "always",
"printWidth": 100,
"proseWrap": "always",
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
}
44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@
"Tom Chen (@tomchentw)"
],
"dependencies": {
"chalk": "2.4.2",
"commander": "3.0.1",
"execa": "2.0.4",
"chalk": "4.1.1",
"commander": "8.3.0",
"execa": "5.1.1",
"expect-more": "1.2.0",
"fs-extra": "8.1.0",
"globby": "10.0.1",
"pretty-bytes": "5.3.0"
"globby": "11.0.4",
"pretty-bytes": "5.6.0"
},
"devDependencies": {
"@types/execa": "2.0.0",
"@types/fs-extra": "8.0.0",
"@types/globby": "9.1.0",
"@types/node": "12.7.5",
"nexe": "2.0.0-rc.34",
"prettier": "1.18.2",
"rimraf": "3.0.0",
"tslint": "5.20.0",
"typescript": "3.6.3"
"@types/fs-extra": "9.0.13",
"@types/node": "16.11.7",
"@typescript-eslint/eslint-plugin": "5.3.1",
"@typescript-eslint/parser": "5.3.1",
"eslint": "8.2.0",
"nexe": "3.3.7",
"organize-imports-cli": "0.8.0",
"prettier": "2.4.1",
"rimraf": "3.0.2",
"typescript": "4.4.4"
},
"engines": {
"node": ">=8.0.0"
"node": ">=16.13.0"
},
"files": [
"dist",
Expand Down Expand Up @@ -77,18 +80,19 @@
"license": "MIT",
"repository": "JamieMason/ImageOptim-CLI",
"resolutions": {
"lodash": "4.17.13",
"ws": "3.3.1"
"globby": "<12"
},
"scripts": {
"build": "npm run build:ts && npm run build:bin",
"build:bin": "nexe --target 'mac-x64-10.13.0' --input dist/imageoptim.js --output dist/imageoptim",
"build:bin": "nexe --target 'mac-x64-12.18.2' --input dist/imageoptim.js --output dist/imageoptim",
"build:ts": "tsc --project .",
"format": "prettier --write './src/**/*.ts'",
"lint": "tslint --fix --project ./tsconfig.json",
"format": "npm run format:imports && npm run format:prettier",
"format:imports": "organize-imports-cli ./src/**/*.ts",
"format:prettier": "prettier --write './src/**/*.ts'",
"lint": "eslint --ext .ts .",
"lint:fix": "npm run format && npm run lint -- --fix",
"postbuild": "rimraf dist/*.js",
"prebuild": "rimraf dist ./test/dist",
"prelint": "npm run format",
"prepack": "npm run build"
}
}
2 changes: 1 addition & 1 deletion src/applescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
JPEGMINI_PRO,
JPEGMINI_PRO_RETAIL,
JPEGMINI_RETAIL,
TMPDIR
TMPDIR,
} from './constants';
import { osascript } from './osascript';

Expand Down
22 changes: 11 additions & 11 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const supports = {
'.TGA',
'.tga',
'.TIFF',
'.tiff'
'.tiff',
],
jpegmini: ['.JPEG', '.jpeg', '.JPG', '.jpg']
jpegmini: ['.JPEG', '.jpeg', '.JPG', '.jpg'],
};

export const SUPPORTED_FILE_TYPES = [
...supports.imageAlpha,
...supports.imageOptim,
...supports.jpegmini
...supports.jpegmini,
].filter((value, i, list) => list.indexOf(value) === i);

export const TMPDIR = join(tmpdir(), 'imageoptim-cli');
Expand All @@ -56,49 +56,49 @@ export const JPEG_MINI_URL = 'https://itunes.apple.com/us/app/jpegmini/id4989447
export const IMAGEALPHA: IApp = {
bundleId: 'net.pornel.ImageAlpha',
name: 'ImageAlpha',
supports: supports.imageAlpha
supports: supports.imageAlpha,
};

export const IMAGEOPTIM: IApp = {
bundleId: 'net.pornel.ImageOptim',
name: 'ImageOptim',
supports: supports.imageOptim
supports: supports.imageOptim,
};

export const JPEGMINI: IApp = {
bundleId: 'com.icvt.JPEGmini',
name: 'JPEGmini',
supports: supports.jpegmini
supports: supports.jpegmini,
};

export const JPEGMINI_RETAIL: IApp = {
bundleId: 'com.icvt.JPEGmini-retail',
name: 'JPEGmini',
supports: supports.jpegmini
supports: supports.jpegmini,
};

export const JPEGMINI_LITE: IApp = {
bundleId: 'com.icvt.JPEGminiLite',
name: 'JPEGmini Lite',
supports: supports.jpegmini
supports: supports.jpegmini,
};

export const JPEGMINI_LITE_RETAIL: IApp = {
bundleId: 'com.icvt.JPEGminiLite-retail',
name: 'JPEGmini Lite',
supports: supports.jpegmini
supports: supports.jpegmini,
};

export const JPEGMINI_PRO: IApp = {
bundleId: 'com.icvt.JPEGmini-Pro',
name: 'JPEGmini Pro',
supports: supports.jpegmini
supports: supports.jpegmini,
};

export const JPEGMINI_PRO_RETAIL: IApp = {
bundleId: 'com.icvt.JPEGmini-Pro-retail',
name: 'JPEGmini Pro',
supports: supports.jpegmini
supports: supports.jpegmini,
};

export const ERROR_JPEGMINI_NOT_INSTALLED = 'ERROR_JPEGMINI_NOT_INSTALLED';
Expand Down
2 changes: 1 addition & 1 deletion src/filesize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import prettyBytes = require('pretty-bytes');
import prettyBytes from 'pretty-bytes';

export const formatFilesize = (value: number) => prettyBytes(value).replace(' ', '');
10 changes: 5 additions & 5 deletions src/get-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ const createStat = (label: string, sizeAfter: number, sizeBefore: number) => {
pretty: {
after: formatFilesize(sizeAfter),
before: formatFilesize(sizeBefore),
saving: formatFilesize(sizeSaving)
saving: formatFilesize(sizeSaving),
},
raw: {
after: sizeAfter,
before: sizeBefore,
percentSaving: getPercentOf(sizeBefore, sizeSaving),
saving: sizeSaving
}
saving: sizeSaving,
},
};
};

Expand All @@ -53,7 +53,7 @@ export const getStats = async (options: IOptions): Promise<IStats> => {
const sizeBefore = await getFileSize(source);
const sizeAfter = await getFileSize(tmp);
return createStat(source, sizeAfter, sizeBefore);
})
}),
);

const totalStats = fileStats.reduce((total, file) => {
Expand All @@ -64,6 +64,6 @@ export const getStats = async (options: IOptions): Promise<IStats> => {

return {
files: fileStats,
total: totalStats
total: totalStats,
};
};
39 changes: 19 additions & 20 deletions src/imageoptim.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import chalk from 'chalk';
import program = require('commander');
import { program } from 'commander';
import { sync } from 'globby';
import { homedir } from 'os';
import { join } from 'path';
import { cli } from './';
import {
PNGQUANT_NUMBER_OF_COLORS,
PNGQUANT_QUALITY,
PNGQUANT_SPEED,
SUPPORTED_FILE_TYPES,
TMPDIR,
VERSION
VERSION,
} from './constants';
import { isSupported } from './is-supported';

const patterns: string[] = [];

Expand All @@ -30,15 +28,15 @@ program
.option('-S, --no-stats', 'do not display file size savings and quality loss information')
.option(
'--number-of-colors <n>',
`ImageAlpha palette size, defaults to ${PNGQUANT_NUMBER_OF_COLORS}`
`ImageAlpha palette size, defaults to ${PNGQUANT_NUMBER_OF_COLORS}`,
)
.option(
'--quality <min>-<max>',
`ImageAlpha quality range from 0-100, defaults to ${PNGQUANT_QUALITY}`
`ImageAlpha quality range from 0-100, defaults to ${PNGQUANT_QUALITY}`,
)
.option(
'--speed <n>',
`ImageAlpha speed from 1 (brute-force) to 10 (fastest), defaults to ${PNGQUANT_SPEED}`
`ImageAlpha speed from 1 (brute-force) to 10 (fastest), defaults to ${PNGQUANT_SPEED}`,
);

program.on('--help', () => {
Expand All @@ -49,10 +47,10 @@ program.on('--help', () => {
ImageAlpha: ${chalk.blue.underline('https://pngmini.com')}
ImageOptim: ${chalk.blue.underline('https://imageoptim.com')}
JPEGmini Lite: ${chalk.blue.underline(
'https://itunes.apple.com/us/app/jpegmini-lite/id525742250'
'https://itunes.apple.com/us/app/jpegmini-lite/id525742250',
)}
JPEGmini Pro: ${chalk.blue.underline(
'https://itunes.apple.com/us/app/jpegmini-pro/id887163276'
'https://itunes.apple.com/us/app/jpegmini-pro/id887163276',
)}
JPEGmini: ${chalk.blue.underline('https://itunes.apple.com/us/app/jpegmini/id498944723')}
Expand All @@ -72,7 +70,7 @@ program.on('--help', () => {
${chalk.dim('Run ImageOptim.app over every image in a specific directory')}
imageoptim '~/Desktop'
`.trimRight()
`.trimRight(),
);
});

Expand All @@ -87,20 +85,21 @@ const supportedTypesPattern = SUPPORTED_FILE_TYPES.map((fileType) => `*${fileTyp
patterns.push(`!**/!(${supportedTypesPattern})`);

const filePaths = sync(patterns.map((pattern) => pattern.replace('~', homedir())));
const options = program.opts();

cli({
batchSize: 300,
enabled: {
color: program.color === true,
imageAlpha: program.imagealpha === true,
imageOptim: program.imageoptim === true,
jpegMini: program.jpegmini === true,
quit: program.quit === true,
stats: program.stats === true
color: options.color === true,
imageAlpha: options.imagealpha === true,
imageOptim: options.imageoptim === true,
jpegMini: options.jpegmini === true,
quit: options.quit === true,
stats: options.stats === true,
},
filePaths,
numberOfColors: program.numberOfColors || PNGQUANT_NUMBER_OF_COLORS,
quality: program.quality || PNGQUANT_QUALITY,
speed: program.speed || PNGQUANT_SPEED,
tmpDir: TMPDIR
numberOfColors: options.numberOfColors || PNGQUANT_NUMBER_OF_COLORS,
quality: options.quality || PNGQUANT_QUALITY,
speed: options.speed || PNGQUANT_SPEED,
tmpDir: TMPDIR,
});
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const runnersByName = {
imageAlpha: runImageAlpha,
imageOptim: runImageOptim,
jpegMini: runJpegMini,
stats: getStats
stats: getStats,
};

const cloneArray = (array: string[]) => [...array];
Expand Down Expand Up @@ -85,12 +85,12 @@ export const cli = async (options: ICliOptions) => {
enabled: options.enabled,
filePaths: filePaths.map((filePath) => ({
source: filePath,
tmp: join(options.tmpDir, filePath)
tmp: join(options.tmpDir, filePath),
})),
numberOfColors: options.numberOfColors,
quality: options.quality,
speed: options.speed,
tmpDir: options.tmpDir
tmpDir: options.tmpDir,
});
}
complete('Finished');
Expand Down

0 comments on commit 585f08e

Please sign in to comment.