Skip to content

Commit 47ceba5

Browse files
feat: add configuration options and update packages
see tomchentw#8 for intention Signed-off-by: Patrick Kollitsch <[email protected]>
1 parent 5e3e0cb commit 47ceba5

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

lib/index.js

+40-28
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,56 @@
1-
"use strict";
2-
const fs = require("fs");
3-
const promisify = require("util.promisify");
1+
'use strict';
2+
const fs = require('fs');
3+
const promisify = require('util.promisify');
4+
const { cosmiconfigSync } = require('cosmiconfig');
45

56
const readFile = promisify(fs.readFile);
67
const writeFile = promisify(fs.writeFile);
78

8-
const plugins = [
9-
[
10-
"imagemin-gifsicle",
11-
{
12-
interlaced: true,
13-
},
14-
],
15-
[
16-
"imagemin-jpegtran",
17-
{
18-
progressive: true,
19-
},
20-
],
21-
[
22-
"imagemin-optipng",
23-
{
24-
optimizationLevel: 5,
25-
},
26-
],
27-
[
28-
"imagemin-svgo",
29-
{
9+
const explorerSync = cosmiconfigSync('imagemin-lint-staged');
10+
const { config } = explorerSync.search() || { config: false };
11+
12+
const gifsicleConfig =
13+
config && config.gifsicle
14+
? config.gifsicle
15+
: {
16+
interlaced: true
17+
};
18+
19+
const jpegtranConfig =
20+
config && config.jpegtran
21+
? config.jpegtran
22+
: {
23+
progressive: true
24+
};
25+
26+
const optipngConfig =
27+
config && config.optipng
28+
? config.optipng
29+
: {
30+
optimizationLevel: 5
31+
};
32+
33+
const svgoConfig =
34+
config && config.svgo
35+
? config.svgo
36+
: {
3037
plugins: [
3138
{
32-
name: "preset-default",
39+
name: 'preset-default',
3340
params: {
3441
overrides: {
3542
removeViewBox: false,
3643
},
3744
},
3845
},
3946
],
40-
},
41-
],
47+
};
48+
49+
const plugins = [
50+
['imagemin-gifsicle', gifsicleConfig],
51+
['imagemin-jpegtran', jpegtranConfig],
52+
['imagemin-optipng', optipngConfig],
53+
['imagemin-svgo', svgoConfig],
4254
].map(([name, opts]) => require(name)(opts));
4355

4456
const minifyFile = (exports.minifyFile = (filename) =>

package.json

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
{
2-
"name": "imagemin-lint-staged",
2+
"name": "@davidsneighbour/imagemin-lint-staged",
33
"version": "0.5.1",
44
"description": "imagemin CLI designed for lint-staged usage with sensible defaults",
55
"license": "MIT",
6+
"maintainers": [
7+
{
8+
"name": "davidsneighbour",
9+
"email": "[email protected]",
10+
"url": "https://github.com/davidsneighbour"
11+
}
12+
],
613
"author": {
714
"name": "tomchentw",
815
"email": "[email protected]",
916
"url": "https://github.com/tomchentw"
1017
},
1118
"repository": {
1219
"type": "git",
13-
"url": "https://github.com/tomchentw/imagemin-lint-staged"
20+
"url": "https://github.com/davidsneighbour/imagemin-lint-staged"
1421
},
1522
"bugs": {
16-
"url": "https://github.com/tomchentw/imagemin-lint-staged/issues"
23+
"url": "https://github.com/davidsneighbour/imagemin-lint-staged/issues"
1724
},
18-
"homepage": "https://github.com/tomchentw/imagemin-lint-staged/",
25+
"homepage": "https://github.com/davidsneighbour/imagemin-lint-staged/",
1926
"bin": "bin/index.js",
2027
"files": [
2128
"bin/",
@@ -56,21 +63,22 @@
5663
]
5764
},
5865
"dependencies": {
66+
"cosmiconfig": "^9.0.0",
5967
"imagemin-gifsicle": "^7.0.0",
6068
"imagemin-jpegtran": "^7.0.0",
6169
"imagemin-optipng": "^8.0.0",
62-
"imagemin-svgo": "^9.0.0",
63-
"util.promisify": "^1.0.0"
70+
"imagemin-svgo": "^10.0.1",
71+
"util.promisify": "^1.1.2"
6472
},
6573
"devDependencies": {
66-
"@babel/core": "^7.2.2",
67-
"@babel/preset-env": "^7.2.3",
68-
"babel-jest": "^28.1.1",
69-
"husky": "^8.0.1",
70-
"jest": "^28.1.1",
71-
"lint-staged": "^13.0.2",
72-
"prettier": "^2.7.1",
73-
"rimraf": "^3.0.2",
74+
"@babel/core": "^7.23.7",
75+
"@babel/preset-env": "^7.23.8",
76+
"babel-jest": "^29.7.0",
77+
"husky": "^8.0.3",
78+
"jest": "^29.7.0",
79+
"lint-staged": "^15.2.0",
80+
"prettier": "^3.2.4",
81+
"rimraf": "^5.0.5",
7482
"standard-version": "^9.5.0"
7583
},
7684
"husky": {

0 commit comments

Comments
 (0)