aberlaas-compress 2.18.1 → 2.20.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/lib/main.js +38 -31
- package/lib/png.js +37 -27
- package/package.json +17 -19
package/lib/main.js
CHANGED
|
@@ -1,41 +1,48 @@
|
|
|
1
1
|
import { _, pMap } from 'golgoth';
|
|
2
2
|
import { consoleError, firostError } from 'firost';
|
|
3
|
-
import compressPng from './png.js';
|
|
4
3
|
import compressDummy from './dummy.js';
|
|
4
|
+
import compressPng from './png.js';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export let __;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper to compress all supported formats
|
|
10
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
11
|
+
* @returns {boolean} True on success
|
|
12
|
+
*/
|
|
13
|
+
export async function run(cliArgs) {
|
|
14
|
+
const allTypesKeys = _.keys(__.types);
|
|
15
|
+
const userTypes = _.intersection(_.keys(cliArgs), allTypesKeys);
|
|
16
|
+
const typesToCompress = _.isEmpty(userTypes) ? allTypesKeys : userTypes;
|
|
17
|
+
|
|
18
|
+
let hasErrors = false;
|
|
19
|
+
await pMap(typesToCompress, async (type) => {
|
|
20
|
+
try {
|
|
21
|
+
const userPatterns = _.get(cliArgs, '_');
|
|
22
|
+
const compresser = __.types[type];
|
|
23
|
+
|
|
24
|
+
await compresser.run(userPatterns);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
__.consoleError(error.message);
|
|
27
|
+
hasErrors = true;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (hasErrors) {
|
|
32
|
+
throw firostError('ABERLAAS_COMPRESS', 'Error while compressing files');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
__ = {
|
|
7
39
|
types: {
|
|
8
40
|
png: compressPng,
|
|
9
41
|
dummy: compressDummy,
|
|
10
42
|
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
14
|
-
* @returns {boolean} True on success
|
|
15
|
-
*/
|
|
16
|
-
async run(cliArgs) {
|
|
17
|
-
const allTypesKeys = _.keys(this.types);
|
|
18
|
-
const userTypes = _.intersection(_.keys(cliArgs), allTypesKeys);
|
|
19
|
-
const typesToCompress = _.isEmpty(userTypes) ? allTypesKeys : userTypes;
|
|
20
|
-
|
|
21
|
-
let hasErrors = false;
|
|
22
|
-
await pMap(typesToCompress, async (type) => {
|
|
23
|
-
try {
|
|
24
|
-
const userPatterns = _.get(cliArgs, '_');
|
|
25
|
-
const compresser = this.types[type];
|
|
26
|
-
|
|
27
|
-
await compresser.run(userPatterns);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
this.__consoleError(error.message);
|
|
30
|
-
hasErrors = true;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (hasErrors) {
|
|
35
|
-
throw firostError('ERROR_COMPRESS', 'Error while compressing files');
|
|
36
|
-
}
|
|
43
|
+
consoleError,
|
|
44
|
+
};
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
__consoleError: consoleError,
|
|
46
|
+
export default {
|
|
47
|
+
run,
|
|
41
48
|
};
|
package/lib/png.js
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import { _ } from 'golgoth';
|
|
2
|
-
import { firostError, run, which } from 'firost';
|
|
3
|
-
import
|
|
2
|
+
import { firostError, run as firostRun, which } from 'firost';
|
|
3
|
+
import { findHostPackageFiles } from 'aberlaas-helper';
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export let __;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Compress files
|
|
9
|
+
* @param {Array} userPatterns Patterns to narrow the search down
|
|
10
|
+
* @returns {boolean} True on success
|
|
11
|
+
*/
|
|
12
|
+
export async function run(userPatterns) {
|
|
13
|
+
// Stop early if no bin
|
|
14
|
+
const binaryPath = await __.getBinaryPath();
|
|
15
|
+
if (!binaryPath) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const files = await __.getInputFiles(userPatterns);
|
|
21
|
+
if (_.isEmpty(files)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const command = `${binaryPath} ${files.join(' ')}`;
|
|
25
|
+
await firostRun(command, { stdout: false });
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw firostError('ABERLAAS_COMPRESS_PNG', error.message);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
__ = {
|
|
6
34
|
/**
|
|
7
35
|
* Find the png files to compress
|
|
8
36
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
@@ -12,7 +40,7 @@ export default {
|
|
|
12
40
|
const filePatterns = _.isEmpty(userPatterns)
|
|
13
41
|
? ['./**/*.png']
|
|
14
42
|
: userPatterns;
|
|
15
|
-
return await
|
|
43
|
+
return await findHostPackageFiles(filePatterns, ['.png']);
|
|
16
44
|
},
|
|
17
45
|
|
|
18
46
|
/**
|
|
@@ -20,29 +48,11 @@ export default {
|
|
|
20
48
|
* @returns {string|boolean} Path to the binary, or false if not found
|
|
21
49
|
*/
|
|
22
50
|
async getBinaryPath() {
|
|
23
|
-
return await
|
|
51
|
+
return await __.which('pngmin');
|
|
24
52
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @param {Array} userPatterns Patterns to narrow the search down
|
|
28
|
-
* @returns {boolean} True on success
|
|
29
|
-
*/
|
|
30
|
-
async run(userPatterns) {
|
|
31
|
-
// Stop early if no bin
|
|
32
|
-
const binaryPath = await this.getBinaryPath();
|
|
33
|
-
if (!binaryPath) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const files = await this.getInputFiles(userPatterns);
|
|
39
|
-
const command = `${binaryPath} ${files.join(' ')}`;
|
|
40
|
-
await run(command, { stdout: false });
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw firostError('PngCompressError', error.message);
|
|
43
|
-
}
|
|
53
|
+
which,
|
|
54
|
+
};
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
__which: which,
|
|
56
|
+
export default {
|
|
57
|
+
run,
|
|
48
58
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberlaas-compress",
|
|
3
3
|
"type": "module",
|
|
4
|
+
"sideEffects": false,
|
|
4
5
|
"description": "aberlaas compress command: Reduce image filesize",
|
|
5
|
-
"version": "2.
|
|
6
|
+
"version": "2.20.1",
|
|
6
7
|
"repository": "pixelastic/aberlaas",
|
|
7
8
|
"homepage": "https://projects.pixelastic.com/aberlaas/",
|
|
8
9
|
"author": "Tim Carry (@pixelastic)",
|
|
@@ -17,25 +18,22 @@
|
|
|
17
18
|
"engines": {
|
|
18
19
|
"node": ">=18.18.0"
|
|
19
20
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "../../scripts/local/build",
|
|
22
|
-
"build:prod": "../../scripts/local/build-prod",
|
|
23
|
-
"cms": "../../scripts/local/cms",
|
|
24
|
-
"serve": "../../scripts/local/serve",
|
|
25
|
-
"ci": "../../scripts/local/ci",
|
|
26
|
-
"release": "../../scripts/local/release",
|
|
27
|
-
"update-dependencies": "node ../../scripts/meta/update-dependencies.js",
|
|
28
|
-
"test:meta": "../../scripts/local/test-meta",
|
|
29
|
-
"test": "../../scripts/local/test",
|
|
30
|
-
"test:watch": "../../scripts/local/test-watch",
|
|
31
|
-
"compress": "../../scripts/local/compress",
|
|
32
|
-
"lint": "../../scripts/local/lint",
|
|
33
|
-
"lint:fix": "../../scripts/local/lint-fix"
|
|
34
|
-
},
|
|
35
21
|
"dependencies": {
|
|
36
|
-
"aberlaas-helper": "
|
|
37
|
-
"firost": "5.
|
|
22
|
+
"aberlaas-helper": "workspace:*",
|
|
23
|
+
"firost": "5.5.1",
|
|
38
24
|
"golgoth": "3.0.0"
|
|
39
25
|
},
|
|
40
|
-
"
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "cd ../docs && yarn run build",
|
|
28
|
+
"build:prod": "cd ../docs && yarn run build:prod",
|
|
29
|
+
"cms": "cd ../docs && yarn run cms",
|
|
30
|
+
"serve": "cd ../docs && yarn run serve",
|
|
31
|
+
"release": "cd ../.. && ./scripts/release",
|
|
32
|
+
"test:meta": "cd ../.. && ./scripts/test-meta",
|
|
33
|
+
"test": "cd ../.. && ./scripts/test",
|
|
34
|
+
"test:watch": "cd ../.. && ./scripts/test-watch",
|
|
35
|
+
"compress": "cd ../.. && ./scripts/compress",
|
|
36
|
+
"lint": "cd ../.. && ./scripts/lint",
|
|
37
|
+
"lint:fix": "cd ../.. && ./scripts/lint-fix"
|
|
38
|
+
}
|
|
41
39
|
}
|