Skip to content

Commit

Permalink
feat(cli): added --splash-only and --icon-only flags
Browse files Browse the repository at this point in the history
Adding optional --splash-only and --icon-only flags makes it possible to only generate images for a
specific set. Now it's possible to generate splash screen images and icons with different options
per each set.

fix #3
  • Loading branch information
onderceylan committed Aug 15, 2019
1 parent 14f3323 commit e9ed94b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
30 changes: 26 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ const cli = meow(
-i --index Index html file path to automatically put splash screen meta tags in
-t --type Image type: png|jpeg [default: png]
-q --quality Image quality: 0...100 (Only for JPEG) [default: 100]
-h --splash-only Only generate splash screens [default: false]
-c --icon-only Only generate icons [default: false]
Examples
$ pwa-asset-generator logo.html .
$ pwa-asset-generator http://your-cdn-server.com/assets/logo.png . -t jpeg -q 90
$ pwa-asset-generator logo.svg ./assets --scrape false
$ pwa-asset-generator https://cdn.freebiesupply.com/logos/large/2x/amazon-icon-logo-png-transparent.png ./assets -p "20%" -b "linear-gradient(to top, #fad0c4 0%, #ffd1ff 100%)"
$ pwa-asset-generator https://your-cdn-server.com/assets/logo.png . -t jpeg -q 90
$ pwa-asset-generator logo.svg ./assets --scrape false --icon-only
$ pwa-asset-generator https://cdn.freebiesupply.com/logos/large/2x/amazon-icon-logo-png-transparent.png -p "10%" -b "linear-gradient(to top, #fad0c4 0%, #ffd1ff 100%)"
Flag examples
--background="rgba(255, 255, 255, .5)"
Expand All @@ -37,6 +39,8 @@ const cli = meow(
--index=./src/index.html
--type=jpeg
--quality=80
--splash-only=true
--icon-only=true
`,
{
flags: {
Expand Down Expand Up @@ -78,6 +82,16 @@ const cli = meow(
alias: 'q',
default: 100,
},
splashOnly: {
type: 'boolean',
alias: 'h',
default: false,
},
iconOnly: {
type: 'boolean',
alias: 'c',
default: false,
},
},
},
);
Expand All @@ -92,6 +106,14 @@ if (!source) {
process.exit(1);
}

if (options.splashOnly && options.iconOnly) {
logger.warn(
`Hmm, you wan't to _only_ generate both splash and icon set. Ignoring --x-only settings as this is default behavior`,
);
options.splashOnly = false;
options.iconOnly = false;
}

if (!output) {
output = process.cwd();
}
Expand All @@ -109,7 +131,7 @@ if (!output) {
logger.success(
`Icons are saved to Web App Manifest file ${options.manifest}`,
);
} else {
} else if (!options.splashOnly) {
logger.warn(
'Web App Manifest file is not specified, printing out the content to console instead',
);
Expand Down
6 changes: 4 additions & 2 deletions puppets.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ const saveImages = async (imageList, source, output, options) => {
const generateImages = async (source, output, options) => {
const splashScreenMetaData = await getSplashScreenMetaData(options);
const allImages = [
...images.getSplashScreenImages(splashScreenMetaData),
...images.getIconImages(),
...(!options.iconOnly
? images.getSplashScreenImages(splashScreenMetaData)
: []),
...(!options.splashOnly ? images.getIconImages() : []),
];

if (!(await file.pathExists(output, file.WRITE_ACCESS))) {
Expand Down

0 comments on commit e9ed94b

Please sign in to comment.