icon-gen
Advanced tools
Comparing version 1.2.1 to 1.2.2
# ChangeLog | ||
## v1.2.2 | ||
### Changes | ||
* Support Node v10.x [#90](https://github.com/akabekobeko/npm-icon-gen/issues/90) | ||
### Bug Fixes | ||
* CLI size specification is not working [#89](https://github.com/akabekobeko/npm-icon-gen/issues/89) | ||
## v1.2.1 | ||
@@ -4,0 +14,0 @@ |
@@ -58,9 +58,5 @@ 'use strict'; | ||
-h, --help Display this text. | ||
-v, --version Display the version number. | ||
-i, --input Path of the SVG file or PNG file directory. | ||
-o, --output Path of the output directory. | ||
-t, --type Type of the input file. | ||
@@ -70,14 +66,10 @@ 'svg' is the SVG file, 'png' is the PNG files directory. | ||
Default is 'svg'. | ||
-m, --modes Mode of the output files. | ||
Allowed values: ico, icns, favicon, all | ||
Default is 'all'. | ||
-n, --names Change an output file names for ICO and ICNS. | ||
ex: 'ico=foo,icns=bar' | ||
Default is 'app.ico' and 'app.ico'. | ||
-r, --report Display the process reports. | ||
Default is disable. | ||
-s, --sizes List of sizes to include for ICO and ICNS. | ||
@@ -94,5 +86,7 @@ ex: 'ico=[12,24,32],icns=[12,24,64]' | ||
$ icon-gen -i sample.svg -o ./dist -n ico=foo,icns=bar | ||
$ icon-gen -i sample.svg -o ./dist -s ico=[16,24,32],icns=[16,32,512] | ||
See also: | ||
https://github.com/akabekobeko/npm-icon-gen`; | ||
https://github.com/akabekobeko/npm-icon-gen | ||
`; | ||
@@ -348,3 +342,3 @@ /** | ||
case OUTPUT_MODES.icns: | ||
sizes[key] = values; | ||
sizes[key] = values.map(value => Number(value)); | ||
break; | ||
@@ -351,0 +345,0 @@ |
@@ -106,3 +106,3 @@ 'use strict'; | ||
* | ||
* @return {Array.<Number>} Sizes. | ||
* @return {Number[]} Sizes. | ||
*/ | ||
@@ -109,0 +109,0 @@ static getRequiredImageSizes() { |
@@ -54,3 +54,3 @@ 'use strict'; | ||
* @param {String} dir Path of the output files directory. | ||
* @param {Object} options Options. | ||
* @param {CLIOption} options Options from command line. | ||
* @param {Logger} logger Logger. | ||
@@ -74,3 +74,3 @@ * | ||
_pngGenerator2.default.generate(svgFilePath, workDir, options.modes, (err, images) => { | ||
_pngGenerator2.default.generate(svgFilePath, workDir, options, (err, images) => { | ||
if (err) { | ||
@@ -77,0 +77,0 @@ _del2.default.sync([workDir], { force: true }); |
@@ -34,2 +34,47 @@ 'use strict'; | ||
/** | ||
* Filter the sizes. | ||
* | ||
* @param {Number[]} sizes Original sizes. | ||
* @param {Number[]} filterSizes Filter sizes. | ||
* | ||
* @return {NUmber[]} Filterd sizes. | ||
*/ | ||
const filterSizes = (sizes = [], filterSizes = []) => { | ||
if (filterSizes.length === 0) { | ||
return sizes; | ||
} | ||
return sizes.filter(size => { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = filterSizes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
let filterSize = _step.value; | ||
if (size === filterSize) { | ||
return true; | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return false; | ||
}); | ||
}; | ||
/** | ||
* Generate the PNG files = require(SVG file. | ||
@@ -41,9 +86,9 @@ */ | ||
* | ||
* @param {String} src SVG file path. | ||
* @param {String} dir Output destination The path of directory. | ||
* @param {Array.<String>} modes Modes of an output files. | ||
* @param {Function} cb Callback function. | ||
* @param {Logger} logger Logger. | ||
* @param {String} src SVG file path. | ||
* @param {String} dir Output destination The path of directory. | ||
* @param {CLIOption} options Options from command line. | ||
* @param {Function} cb Callback function. | ||
* @param {Logger} logger Logger. | ||
*/ | ||
static generate(src, dir, modes, cb, logger) { | ||
static generate(src, dir, options, cb, logger) { | ||
_fs2.default.readFile(src, (err, svg) => { | ||
@@ -57,3 +102,3 @@ if (err) { | ||
const sizes = PNGGenerator.getRequiredImageSizes(modes); | ||
const sizes = PNGGenerator.getRequiredImageSizes(options); | ||
Promise.all(sizes.map(size => { | ||
@@ -72,17 +117,17 @@ return PNGGenerator._generatePNG(svg, size, dir, logger); | ||
* | ||
* @param {Array.<String>} modes Modes of an output files. | ||
* @param {CLIOption} options Options from command line. | ||
* | ||
* @return {Array.<Number>} The sizes of the image. | ||
* @return {Number[]} The sizes of the image. | ||
*/ | ||
static getRequiredImageSizes(modes) { | ||
static getRequiredImageSizes(options = {}) { | ||
let sizes = []; | ||
if (modes && 0 < modes.length) { | ||
modes.forEach(mode => { | ||
if (options.modes && 0 < options.modes.length) { | ||
options.modes.forEach(mode => { | ||
switch (mode) { | ||
case 'icns': | ||
sizes = sizes.concat(_icnsGenerator2.default.getRequiredImageSizes()); | ||
sizes = sizes.concat(filterSizes(_icnsGenerator2.default.getRequiredImageSizes(), options.sizes && options.sizes.icns)); | ||
break; | ||
case 'ico': | ||
sizes = sizes.concat(_icoGenerator2.default.getRequiredImageSizes()); | ||
sizes = sizes.concat(filterSizes(_icoGenerator2.default.getRequiredImageSizes(), options.sizes && options.sizes.ico)); | ||
break; | ||
@@ -102,3 +147,5 @@ | ||
if (sizes.length === 0) { | ||
sizes = _faviconGenerator2.default.getRequiredImageSizes().concat(_icnsGenerator2.default.getRequiredImageSizes().concat(_icoGenerator2.default.getRequiredImageSizes())); | ||
sizes = _faviconGenerator2.default.getRequiredImageSizes(); | ||
sizes = sizes.concat(filterSizes(_icnsGenerator2.default.getRequiredImageSizes(), options.sizes && options.sizes.icns)); | ||
sizes = sizes.concat(filterSizes(_icoGenerator2.default.getRequiredImageSizes(), options.sizes && options.sizes.ico)); | ||
} | ||
@@ -117,5 +164,5 @@ | ||
* | ||
* @param {Buffer} svg SVG data that has been parse by svg2png. | ||
* @param {Number} size The size (width/height) of the image. | ||
* @param {String} dir Path of the file output directory. | ||
* @param {Buffer} svg SVG data that has been parse by svg2png. | ||
* @param {Number} size The size (width/height) of the image. | ||
* @param {String} dir Path of the file output directory. | ||
* @param {Logger} logger Logger. | ||
@@ -122,0 +169,0 @@ * |
{ | ||
"name": "icon-gen", | ||
"description": "Generate an icon files from the SVG or PNG files", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "akabeko (http://akabeko.me/)", | ||
@@ -76,20 +76,21 @@ "license": "MIT", | ||
"svg2png": "4.1.1", | ||
"uuid": "^3.2.1" | ||
"uuid": "^3.3.2" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-power-assert": "^2.0.0", | ||
"babel-register": "^6.26.0", | ||
"esdoc": "^1.0.4", | ||
"esdoc": "^1.1.0", | ||
"esdoc-standard-plugin": "^1.0.0", | ||
"eslint": "^4.19.1", | ||
"eslint": "^5.3.0", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.9.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.7.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"mocha": "^5.0.5", | ||
"power-assert": "^1.4.4" | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-promise": "^3.8.0", | ||
"eslint-plugin-standard": "^3.1.0", | ||
"mocha": "^5.2.0", | ||
"power-assert": "^1.6.0", | ||
"rewire": "^4.0.1" | ||
} | ||
} |
149
README.md
@@ -78,23 +78,23 @@ # npm-icon-gen | ||
Required PNG files is below. Favicon outputs both the ICO and PNG files ( see: [audreyr/favicon-cheat-sheet](https://github.com/audreyr/favicon-cheat-sheet) ). | ||
Required PNG files is below. Favicon outputs both the ICO and PNG files (see: [audreyr/favicon-cheat-sheet](https://github.com/audreyr/favicon-cheat-sheet)). | ||
| Name | Size | ICO | ICNS | Fav ICO | Fav PNG | | ||
|---------:|:----------|:--------:|:--------:|:--------:|:--------:| | ||
| 16.png | 16x16 | ✔ | ✔ | ✔ | | | ||
| 24.png | 24x24 | ✔ | | ✔ | | | ||
| 32.png | 32x32 | ✔ | ✔ | ✔ | ✔ | | ||
| 48.png | 48x48 | ✔ | | ✔ | | | ||
| 57.png | 57x57 | | | | ✔ | | ||
| 64.png | 64x64 | ✔ | ✔ | ✔ | | | ||
| 72.png | 72x72 | | | | ✔ | | ||
| 96.png | 96x96 | | | | ✔ | | ||
| 120.png | 120x120 | | | | ✔ | | ||
| 128.png | 128x128 | ✔ | ✔ | | ✔ | | ||
| 144.png | 144x144 | | | | ✔ | | ||
| 152.png | 152x152 | | | | ✔ | | ||
| 195.png | 195x195 | | | | ✔ | | ||
| 228.png | 228x228 | | | | ✔ | | ||
| 256.png | 256x256 | ✔ | ✔ | | | | ||
| 512.png | 512x512 | | ✔ | | | | ||
| 1024.png | 1024x1024 | | ✔ | | | | ||
|Name |Size |ICO |ICNS |Fav ICO |Fav PNG | | ||
|-------:|--------:|:------:|:------:|:------:|:------:| | ||
| 16.png| 16x16|✔|✔|✔| | | ||
| 24.png| 24x24|✔| |✔| | | ||
| 32.png| 32x32|✔|✔|✔|✔| | ||
| 48.png| 48x48|✔| |✔| | | ||
| 57.png| 57x57| | | |✔| | ||
| 64.png| 64x64|✔|✔|✔| | | ||
| 72.png| 72x72| | | |✔| | ||
| 96.png| 96x96| | | |✔| | ||
| 120.png| 120x120| | | |✔| | ||
| 128.png| 128x128|✔|✔| |✔| | ||
| 144.png| 144x144| | | |✔| | ||
| 152.png| 152x152| | | |✔| | ||
| 195.png| 195x195| | | |✔| | ||
| 228.png| 228x228| | | |✔| | ||
| 256.png| 256x256|✔|✔| | | | ||
| 512.png| 512x512| |✔| | | | ||
|1024.png|1024x1024| |✔| | | | ||
@@ -109,35 +109,35 @@ ## Node API | ||
| Name | Type | Description | | ||
|:--------|:-------|:------------| | ||
| src | String | Path of the **SVG file** or **PNG files directory** that becomes the source. | | ||
| dest | String | Destination directory path. | | ||
| options | Object | Options. | | ||
|Name|Type|Description| | ||
|---|---|---| | ||
|src |`String`|Path of the **SVG file** or **PNG files directory** that becomes the source.| | ||
|dest |`String`|Destination directory path.| | ||
|options|`Object`|see: _Options_.| | ||
options: | ||
_Options:_ | ||
| Name | Type | Description | | ||
|:-------|:--------|:------------| | ||
| type | String | Type of input file. Allowed value is a `svg` or `png`. 'svg' is SVG file, `png` is PNG files directory. Default is `svg`. | | ||
| modes | Array | Mode of output files. Allow value is a `ico`, `icns`, `favicon` and `all`. Default is `all`. | | ||
| names | Object | Change an output file names for **ICO** and **ICNS**. | | ||
| report | Boolean | Display the process reports. Default is `false`, disable a report. | | ||
| sizes | Object | List of sizes to include for **ICO** and **ICNS**. | | ||
|Name|Type|Description| | ||
|---|---|---| | ||
|type |`String`|Type of input file. Allowed value is a `svg` or `png`. 'svg' is SVG file, `png` is PNG files directory. Default is `svg`.| | ||
|modes |`String[]`|Mode of output files. Allow value is a `ico`, `icns`, `favicon` and `all`. Default is `all`.| | ||
|names|`Object` |Change an output file names for **ICO** and **ICNS**. see: _Names_| | ||
|report|`Boolean` |Display the process reports. Default is `false`, disable a report.| | ||
|sizes|`Object`|List of sizes to include for **ICO** and **ICNS**. see: _Sizes_| | ||
names: | ||
_Names:_ | ||
Use this property is specified without an extension. Default name is the `app`. | ||
| Name | Type | Description | | ||
|:--------|:--|:--| | ||
| ico | String | Name of the `ico` file. | | ||
| icns | String | Name of the `icns` file. | | ||
|Name|Type|Description| | ||
|---|---|---| | ||
|ico |`String`|Name of the `ico` file.| | ||
|icns|`String`|Name of the `icns` file.| | ||
sizes: | ||
_Sizes:_ | ||
Use this property is specified without an extension. Default name is the `app`. | ||
| Name | Type | Description | | ||
|:--------|:--|:--| | ||
| ico | Array | List of sizes for the `ico` file. | | ||
| icns | Array | List of sizes for the `icns` file. | | ||
|Name|Type|Description| | ||
|---|---|---| | ||
|ico|`Number[]`|List of sizes for the `ico` file.| | ||
|icns|`Number[]`|List of sizes for the `icns` file.| | ||
@@ -149,40 +149,33 @@ ## CLI | ||
Generate an icon from the SVG or PNG file. | ||
Generate an icon from the SVG or PNG file. | ||
Options: | ||
-h, --help Display this text. | ||
Options: | ||
-h, --help Display this text. | ||
-v, --version Display the version number. | ||
-i, --input Path of the SVG file or PNG file directory. | ||
-o, --output Path of the output directory. | ||
-t, --type Type of the input file. | ||
'svg' is the SVG file, 'png' is the PNG files directory. | ||
Allowed values: svg, png | ||
Default is 'svg'. | ||
-m, --modes Mode of the output files. | ||
Allowed values: ico, icns, favicon, all | ||
Default is 'all'. | ||
-n, --names Change an output file names for ICO and ICNS. | ||
ex: 'ico=foo,icns=bar' | ||
Default is 'app.ico' and 'app.ico'. | ||
-r, --report Display the process reports. | ||
Default is disable. | ||
-s, --sizes List of sizes to include for ICO and ICNS. | ||
ex: 'ico=[12,24,32],icns=[12,24,64]' | ||
-v, --version Display the version number. | ||
Examples: | ||
$ icon-gen -i sample.svg -o ./dist -r | ||
$ icon-gen -i ./images -o ./dist -t png -r | ||
$ icon-gen -i sample.svg -o ./dist -m ico,favicon -r | ||
$ icon-gen -i sample.svg -o ./dist -n ico=foo,icns=bar | ||
$ icon-gen -i sample.svg -o ./dist -s ico=[16,24,32],icns=[16,32,512] | ||
-i, --input Path of the SVG file or PNG file directory. | ||
-o, --output Path of the output directory. | ||
-t, --type Type of the input file. | ||
'svg' is the SVG file, 'png' is the PNG files directory. | ||
Allowed values: svg, png | ||
Default is 'svg'. | ||
-m, --modes Mode of the output files. | ||
Allowed values: ico, icns, favicon, all | ||
Default is 'all'. | ||
-n, --names Change an output file names for ICO and ICNS. | ||
ex: 'ico=foo,icns=bar' | ||
Default is 'app.ico' and 'app.ico'. | ||
-r, --report Display the process reports. | ||
Default is disable. | ||
-s, --sizes List of sizes to include for ICO and ICNS. | ||
ex: 'ico=[12,24,32],icns=[12,24,64]' | ||
Examples: | ||
$ icon-gen -i sample.svg -o ./dist -r | ||
$ icon-gen -i ./images -o ./dist -t png -r | ||
$ icon-gen -i sample.svg -o ./dist -m ico,favicon -r | ||
$ icon-gen -i sample.svg -o ./dist -n ico=foo,icns=bar | ||
See also: | ||
https://github.com/akabekobeko/npm-icon-gen | ||
See also: | ||
https://github.com/akabekobeko/npm-icon-gen | ||
``` | ||
@@ -189,0 +182,0 @@ |
66451
15
15
1695
187
Updateduuid@^3.3.2