Skip to content

Commit 5190f6f

Browse files
committed
fix globby
1 parent bb2a1f8 commit 5190f6f

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

src/index.js

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -44,75 +44,77 @@ export default (options = {}) => {
4444

4545
return globby(
4646
// Finds all the images we want based on dir and inputFormat
47-
`${dirGlob}/**/!(*@*|*#*).{${inputFormat.join(',')}}`,
47+
`${dirGlob}/**/*.{${inputFormat.join(',')}}`,
4848
)
4949
.then((images) => Promise.allSettled(
5050
// Map them into jimp objects
51-
images.map((image) => {
51+
images
52+
.filter((d) => d.indexOf('@') < 0 && d.indexOf('#') < 0)
53+
.map((image) => {
5254
// generate the output path
53-
const imagePathSplit = image.split('.');
54-
const imagePathPre = imagePathSplit.slice(0, -1).join('.');
55-
const imageFormat = imagePathSplit[imagePathSplit.length - 1];
55+
const imagePathSplit = image.split('.');
56+
const imagePathPre = imagePathSplit.slice(0, -1).join('.');
57+
const imageFormat = imagePathSplit[imagePathSplit.length - 1];
5658

57-
// process image format options
58-
const formats = Array.from(new Set(
59-
arrayify(outputFormat)
59+
// process image format options
60+
const formats = Array.from(new Set(
61+
arrayify(outputFormat)
6062
// If format is match, we match to the input format
61-
.map((format) => (format === 'match' ? imageFormat : format))
63+
.map((format) => (format === 'match' ? imageFormat : format))
6264
// If format is jpeg, we map to jpg
63-
.map((format) => (format === 'jpeg' ? 'jpg' : format)),
64-
));
65+
.map((format) => (format === 'jpeg' ? 'jpg' : format)),
66+
));
6567

66-
// An array of objects that contain sizes and formats of all our outputs.
67-
let outputs = sizes.reduce(
68-
(acc, scaleWidth) => [...acc, ...formats.map((format) => ({ format, scaleWidth }))],
69-
[],
70-
);
68+
// An array of objects that contain sizes and formats of all our outputs.
69+
let outputs = sizes.reduce(
70+
(acc, scaleWidth) => [...acc, ...formats.map((format) => ({ format, scaleWidth }))],
71+
[],
72+
);
7173

72-
// if skipExisting is set
73-
if (skipExisting) {
74+
// if skipExisting is set
75+
if (skipExisting) {
7476
// Filter out images that already exist
75-
outputs = outputs.filter(
76-
({ format, scaleWidth }) => !fs.existsSync(`${imagePathPre}@${scaleWidth}w.${format}`),
77-
);
77+
outputs = outputs.filter(
78+
({ format, scaleWidth }) => !fs.existsSync(`${imagePathPre}@${scaleWidth}w.${format}`),
79+
);
7880

79-
// if images already exist, we can skip this rest of this process
80-
if (outputs.length === 0) return null;
81-
}
81+
// if images already exist, we can skip this rest of this process
82+
if (outputs.length === 0) return null;
83+
}
8284

83-
// ////////////////////////////////////////////
84-
// Everything below is expensive, so we want to short-circuit this as much as possible
85-
// load in the image
86-
return jimp.read(image)
87-
.then((jimpObj) => Promise.allSettled(
88-
outputs
85+
// ////////////////////////////////////////////
86+
// Everything below is expensive, so we want to short-circuit this as much as possible
87+
// load in the image
88+
return jimp.read(image)
89+
.then((jimpObj) => Promise.allSettled(
90+
outputs
8991
// Get only the sizes that we need to generate
90-
.reduce((acc, val) => {
91-
if (acc.indexOf(val.scaleWidth) < 0) return [...acc, val.scaleWidth];
92-
return acc;
93-
}, [])
94-
.map((scaleWidth) => {
92+
.reduce((acc, val) => {
93+
if (acc.indexOf(val.scaleWidth) < 0) return [...acc, val.scaleWidth];
94+
return acc;
95+
}, [])
96+
.map((scaleWidth) => {
9597
// If the width we want to scale to is larger than the original
9698
// width and forceUpscale is not set, we skip this.
97-
if (scaleWidth > jimpObj.bitmap.width && !forceUpscale) {
98-
return Promise.resolve();
99-
}
99+
if (scaleWidth > jimpObj.bitmap.width && !forceUpscale) {
100+
return Promise.resolve();
101+
}
100102

101-
// Save all of the output images
102-
return Promise.all(
103-
outputs
103+
// Save all of the output images
104+
return Promise.all(
105+
outputs
104106
// only get the outputs of the current width
105-
.filter((d) => d.scaleWidth === scaleWidth)
106-
.map((d) => d.format)
107-
.map((format) => jimpObj
108-
.clone()
109-
.resize(scaleWidth, jimp.AUTO)
110-
.quality(quality)
111-
.write(`${imagePathPre}@${scaleWidth}w.${format}`)),
112-
);
113-
}),
114-
));
115-
}).filter((d) => !!d),
107+
.filter((d) => d.scaleWidth === scaleWidth)
108+
.map((d) => d.format)
109+
.map((format) => jimpObj
110+
.clone()
111+
.resize(scaleWidth, jimp.AUTO)
112+
.quality(quality)
113+
.write(`${imagePathPre}@${scaleWidth}w.${format}`)),
114+
);
115+
}),
116+
));
117+
}).filter((d) => !!d),
116118
));
117119
},
118120
};

0 commit comments

Comments
 (0)