@massimo-cassandro/create-favicons 1.1.0 → 1.2.0
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/package.json +2 -9
- package/src/create-favicons.mjs +10 -24
- package/src/defaults.mjs +4 -8
- package/src/print-frame.mjs +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@massimo-cassandro/create-favicons",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Favicon files builder",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-favicons": "./index.mjs"
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
|
|
18
17
|
"author": "Massimo Cassandro",
|
|
19
18
|
"license": "MIT",
|
|
20
19
|
"repository": {
|
|
@@ -43,14 +42,8 @@
|
|
|
43
42
|
},
|
|
44
43
|
"dependencies": {
|
|
45
44
|
"chalk": "^5.3.0",
|
|
46
|
-
"imagemin": "^8.0.1",
|
|
47
|
-
"imagemin-jpegtran": "^7.0.0",
|
|
48
|
-
"imagemin-pngquant": "^9.0.2",
|
|
49
45
|
"sharp": "^0.32.6",
|
|
50
|
-
"svgo": "^3.0
|
|
46
|
+
"svgo": "^3.2.0",
|
|
51
47
|
"to-ico": "^1.1.5"
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@massimo-cassandro/linters-config": "^1.6.1"
|
|
55
48
|
}
|
|
56
49
|
}
|
package/src/create-favicons.mjs
CHANGED
|
@@ -7,9 +7,6 @@ import chalk from 'chalk';
|
|
|
7
7
|
import sharp from 'sharp';
|
|
8
8
|
import toIco from 'to-ico';
|
|
9
9
|
import { optimize } from 'svgo';
|
|
10
|
-
import imagemin from 'imagemin';
|
|
11
|
-
import imageminJpegtran from 'imagemin-jpegtran';
|
|
12
|
-
import imageminPngquant from 'imagemin-pngquant';
|
|
13
10
|
|
|
14
11
|
import { printFrame } from './print-frame.mjs';
|
|
15
12
|
import { remove_homedir_string } from './remove-homedir-string.mjs';
|
|
@@ -17,6 +14,8 @@ import { remove_homedir_string } from './remove-homedir-string.mjs';
|
|
|
17
14
|
|
|
18
15
|
export function createFavicons(params) {
|
|
19
16
|
|
|
17
|
+
// const files = [];
|
|
18
|
+
|
|
20
19
|
try {
|
|
21
20
|
|
|
22
21
|
const output_dir = path.resolve(params.work_dir, params.output_dir);
|
|
@@ -27,6 +26,7 @@ export function createFavicons(params) {
|
|
|
27
26
|
|
|
28
27
|
|
|
29
28
|
// https://sharp.pixelplumbing.com/api-constructor
|
|
29
|
+
// https://sharp.pixelplumbing.com/api-output#png
|
|
30
30
|
Promise.all([
|
|
31
31
|
['apple-touch-icon.png', 180],
|
|
32
32
|
['icon-192.png', 192],
|
|
@@ -34,31 +34,16 @@ export function createFavicons(params) {
|
|
|
34
34
|
].map(size => {
|
|
35
35
|
sharp(path.resolve(params.work_dir, params.src_img))
|
|
36
36
|
.resize({ width: size[1], fit: 'inside' })
|
|
37
|
-
.png()
|
|
37
|
+
.png(params.png_parameters)
|
|
38
38
|
// .then(info => console.log(info))
|
|
39
39
|
// .toFile(`${output_dir}/${size[0]}`)
|
|
40
40
|
.toBuffer()
|
|
41
41
|
.then(bufferData => {
|
|
42
|
+
fs.writeFileSync(`${output_dir}/${size[0]}`, bufferData);
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
// https://github.com/imagemin/imagemin-jpegtran
|
|
47
|
-
// https://web.dev/use-imagemin-to-compress-images/
|
|
48
|
-
|
|
49
|
-
imagemin.buffer(bufferData, {
|
|
50
|
-
plugins: [
|
|
51
|
-
imageminJpegtran(),
|
|
52
|
-
imageminPngquant({
|
|
53
|
-
quality: params.imagemin_png_quality,
|
|
54
|
-
dithering: false,
|
|
55
|
-
strip: true,
|
|
56
|
-
verbose: true
|
|
57
|
-
})
|
|
58
|
-
]
|
|
59
|
-
}).then( result => {
|
|
60
|
-
fs.writeFileSync(`${output_dir}/${size[0]}`, result);
|
|
61
|
-
});
|
|
44
|
+
const stats = fs.statSync(`${output_dir}/${size[0]}`);
|
|
45
|
+
// console.log(`${size[0]}: ${(stats.size / 1024).toFixed(2)} kb`);
|
|
46
|
+
// files.push(`${size[0]}: ${(stats.size / 1024).toFixed(2)} kb`);
|
|
62
47
|
|
|
63
48
|
})
|
|
64
49
|
.catch(err => { throw err; });
|
|
@@ -186,13 +171,14 @@ export function createFavicons(params) {
|
|
|
186
171
|
{string: ''},
|
|
187
172
|
{string: 'I file generati sono nella directory:', color: 'green'},
|
|
188
173
|
{string: remove_homedir_string(output_dir), color: 'yellow'},
|
|
174
|
+
// {string: ''},
|
|
175
|
+
// {string: '*' + files.join('\n'), color: 'yellow'},
|
|
189
176
|
...extra_strings
|
|
190
177
|
],
|
|
191
178
|
frameColor: 'green',
|
|
192
179
|
frameType: 'single'
|
|
193
180
|
});
|
|
194
181
|
|
|
195
|
-
|
|
196
182
|
} catch(err) {
|
|
197
183
|
|
|
198
184
|
console.error(chalk.bgRed(` ${err} `));
|
package/src/defaults.mjs
CHANGED
|
@@ -73,16 +73,12 @@ export const defaults = {
|
|
|
73
73
|
// problemi di caching del browser
|
|
74
74
|
add_cache_buster: false,
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
// IMAGEMIN PARAMETERS
|
|
78
76
|
//****************************************************************************
|
|
77
|
+
|
|
78
|
+
// SHARP PNG PARAMETERS
|
|
79
79
|
// parametri per i file PNG
|
|
80
|
-
// vedi https://
|
|
81
|
-
|
|
82
|
-
// exceed the max quality. If conversion results in quality below the min quality
|
|
83
|
-
// the image won't be saved.
|
|
84
|
-
// Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG.
|
|
85
|
-
imagemin_png_quality: [0.3, 0.6]
|
|
80
|
+
// vedi https://sharp.pixelplumbing.com/api-output#png
|
|
81
|
+
png_parameters: {compressionLevel: 5, quality: 60, palette: true}
|
|
86
82
|
|
|
87
83
|
|
|
88
84
|
/*** INIT END ***/
|
package/src/print-frame.mjs
CHANGED
|
@@ -27,7 +27,6 @@ export function printFrame(options) {
|
|
|
27
27
|
|
|
28
28
|
options.strings = options.strings.map(item => {return {...string_defaults, ...item }; });
|
|
29
29
|
|
|
30
|
-
// TODO bold underline ecc...
|
|
31
30
|
// aggiunta spazi sulle righe `bg`
|
|
32
31
|
options.strings.forEach(item => {
|
|
33
32
|
if(/^bg/.test(item.color)) {
|