@divriots/jampack 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compress.d.ts +1 -1
- package/dist/compress.js +5 -2
- package/dist/index.js +3 -2
- package/dist/optimize.d.ts +1 -1
- package/dist/optimize.js +5 -2
- package/package.json +1 -1
package/dist/compress.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import sharp from 'sharp';
|
|
2
2
|
import type { Image } from './types.js';
|
|
3
3
|
export declare const compressImage: (data: Buffer, resize: sharp.ResizeOptions, toWebp?: boolean) => Promise<Image | undefined>;
|
|
4
|
-
export declare function compress(
|
|
4
|
+
export declare function compress(exclude: string): Promise<void>;
|
package/dist/compress.js
CHANGED
|
@@ -158,9 +158,12 @@ const compressImageFile = async (file, toWebP = false) => {
|
|
|
158
158
|
const buffer = await fs.readFile(file);
|
|
159
159
|
return compressImage(buffer, {}, toWebP);
|
|
160
160
|
};
|
|
161
|
-
export async function compress(
|
|
161
|
+
export async function compress(exclude) {
|
|
162
162
|
beginProgress();
|
|
163
|
-
const
|
|
163
|
+
const globs = ['**/**'];
|
|
164
|
+
if (exclude)
|
|
165
|
+
globs.push('!' + exclude);
|
|
166
|
+
const paths = await globby(globs, { cwd: globalState.dir, absolute: true });
|
|
164
167
|
// "Parallel" processing
|
|
165
168
|
await Promise.all(paths.map(async (file) => {
|
|
166
169
|
if (!globalState.compressedFiles.has(file)) {
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ program
|
|
|
23
23
|
program.command('pack', { isDefault: true })
|
|
24
24
|
.description('todo')
|
|
25
25
|
.argument('<dir>', 'Directory to pack')
|
|
26
|
+
.option('--exclude <exclude>', 'Glob to exclude')
|
|
26
27
|
.option('--nowrite', 'No write')
|
|
27
28
|
.option('--onlycomp', 'Only compress')
|
|
28
29
|
.option('--onlyoptim', 'Only optimize')
|
|
@@ -32,12 +33,12 @@ program.command('pack', { isDefault: true })
|
|
|
32
33
|
if (!options.onlycomp) {
|
|
33
34
|
console.log('');
|
|
34
35
|
console.log(kleur.bgGreen(kleur.black(` PASS 1 - Optimizing `)));
|
|
35
|
-
await optimize();
|
|
36
|
+
await optimize(options.exclude);
|
|
36
37
|
}
|
|
37
38
|
if (!options.onlyoptim) {
|
|
38
39
|
console.log('');
|
|
39
40
|
console.log(kleur.bgGreen(kleur.black(` PASS 2 - Compressing the rest`)));
|
|
40
|
-
await compress(
|
|
41
|
+
await compress(options.exclude);
|
|
41
42
|
}
|
|
42
43
|
printDetails();
|
|
43
44
|
});
|
package/dist/optimize.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function optimize(): Promise<void>;
|
|
1
|
+
export declare function optimize(exclude?: string): Promise<void>;
|
package/dist/optimize.js
CHANGED
|
@@ -275,8 +275,11 @@ function setImageSize(img, meta) {
|
|
|
275
275
|
// Something when wrong
|
|
276
276
|
throw new Error('Unexpected issue when resolving image sizes');
|
|
277
277
|
}
|
|
278
|
-
export async function optimize() {
|
|
279
|
-
const
|
|
278
|
+
export async function optimize(exclude) {
|
|
279
|
+
const glob = ['**/*.{htm,html}'];
|
|
280
|
+
if (exclude)
|
|
281
|
+
glob.push('!' + exclude);
|
|
282
|
+
const paths = await globby(glob, { cwd: globalState.dir });
|
|
280
283
|
// Sequential async
|
|
281
284
|
await paths.reduce(async (previousPromise, item) => {
|
|
282
285
|
await previousPromise;
|