diff --git a/.npmignore b/.npmignore
index 18e58ba2..4f4960b9 100644
--- a/.npmignore
+++ b/.npmignore
@@ -12,6 +12,7 @@ __snapshots__/*
*.js.map
src/*
dist/models/*.js
+!dist/models/meta.js
bin/install
# Declaration files
diff --git a/README.md b/README.md
index b67805c1..2282d715 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,9 @@ PWA Asset Generator automates the image generation in a creative way. Having [Pu
* When itβs an image source, it is centered over the background option you provide π
* When itβs an HTML source, you can go as creative as you like; position your logo, use SVG filters, use variable fonts, use gradient backgrounds, use typography and etc. Your html file is rendered on Chrome before taking screenshots for each resolution π¨
-* It uses [puppeteer-core](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteer-vs-puppeteer-core) instead of puppeteer and only installs Chromium if it doesn't exist on the system. Saves waste of ~100mb of disk space and many seconds from the world for each user π
+* It uses [puppeteer-core](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteer-vs-puppeteer-core) instead of puppeteer and only installs Chromium if it doesn't exist on the system. Saves waste of ~110-150mb of disk space and many seconds from the world per each user π
+
+* Supports dark mode splash screens on iOS! So, you can provide both light π and dark π splash screen images to differentiate your apps look & feel based on user preference π
## Install
@@ -76,9 +78,10 @@ $ pwa-asset-generator --help
-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]
- -f --favicon Generate favicon [default: false]
+ -f --favicon Generate favicon image and HTML meta tag [default: false]
-l --landscape-only Only generate landscape splash screens [default: false]
-r --portrait-only Only generate portrait splash screens [default: false]
+ -d --dark-mode Generate iOS splash screen meta with (prefers-color-scheme: dark) media attr [default: false]
-u --single-quotes Generate HTML meta tags with single quotes [default: false]
-g --log Logs the steps of the library process [default: true]
@@ -88,6 +91,8 @@ $ pwa-asset-generator --help
$ pwa-asset-generator https://your-cdn-server.com/assets/logo.png ./ -t jpeg -q 90 --splash-only --portrait-only
$ pwa-asset-generator logo.svg ./assets --scrape false --icon-only --path "%PUBLIC_URL%"
$ pwa-asset-generator logo.svg ./assets --icon-only --favicon
+ $ pwa-asset-generator logo.svg ./assets --dark-mode --background dimgrey --splash-only --type jpeg --quality 80
+ $ pwa-asset-generator logo.svg ./assets --padding "calc(50vh - 5%) calc(50vw - 10%)"
$ pwa-asset-generator https://raw.githubusercontent.com/onderceylan/pwa-asset-generator/HEAD/static/logo.png ./temp -p "15%" -b "linear-gradient(to right, #fa709a 0%, #fee140 100%)"
Flag examples
@@ -105,6 +110,7 @@ $ pwa-asset-generator --help
--favicon
--landscape-only
--portrait-only
+ --dark-mode
--single-quotes
--log false
```
@@ -115,7 +121,7 @@ $ pwa-asset-generator --help
const pwaAssetGenerator = require('pwa-asset-generator');
(async () => {
- const { savedImages, htmlContent, manifestJsonContent } = await pwaAssetGenerator.generateImages(
+ const { savedImages, htmlMeta, manifestJsonContent } = await pwaAssetGenerator.generateImages(
'https://raw.githubusercontent.com/onderceylan/pwa-asset-generator/HEAD/static/logo.png',
'./temp',
{
@@ -130,4 +136,16 @@ const pwaAssetGenerator = require('pwa-asset-generator');
## Troubleshooting
+### "No usable sandbox!" error on Linux
In case of getting "No usable sandbox!" error on Linux, you need to enable [system sandboxing](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox).
+
+### How to make an image smaller or larger relative to the background?
+The default value for the padding surrounding the image is 10%. But it's just a css padding value that you can configure and override yourself with **-p --padding** option.
+
+1. You can use a more advanced padding value based on your taste and goal;
+
+ **Larger logo:** `--padding "calc(50vh - 20%) calc(50vw - 40%)"`
+
+ **Smaller logo:** `--padding "calc(50vh - 5%) calc(50vw - 10%)"`
+
+2. You can create your own html input file which uses css media queries and provides different padding options based on breakpoints: https://material.io/design/layout/responsive-layout-grid.html#breakpoints
diff --git a/src/__snapshots__/cli.test.ts.snap b/src/__snapshots__/cli.test.ts.snap
index 781e2eb7..27c79a58 100644
--- a/src/__snapshots__/cli.test.ts.snap
+++ b/src/__snapshots__/cli.test.ts.snap
@@ -17,12 +17,14 @@ exports[`generates icons and splash screens when both only flags exist 1`] = `
+
+
@@ -104,12 +106,14 @@ exports[`generates icons and splash screens with path prefix 1`] = `
+
+
@@ -191,6 +195,7 @@ exports[`generates icons only 1`] = `
+
@@ -205,6 +210,7 @@ exports[`generates landscape splash screens only 1`] = `
"
+
@@ -243,6 +249,7 @@ exports[`generates portrait splash screens only 1`] = `
"
+
@@ -281,6 +288,7 @@ exports[`generates splash screens only 1`] = `
"
+
diff --git a/src/__snapshots__/main.test.ts.snap b/src/__snapshots__/main.test.ts.snap
index 4038a41a..72959448 100644
--- a/src/__snapshots__/main.test.ts.snap
+++ b/src/__snapshots__/main.test.ts.snap
@@ -1,14 +1,328 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`generates icons and splash screens when called via function 1`] = `
+exports[`generates dark mode splash screen html as part of htmlMeta 1`] = `
Object {
- "htmlContent": "
-
-
-
-
-
+ "htmlMeta": Object {
+ "appleLaunchImageDarkMode": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "appleMobileWebAppCapable": "
+",
+ },
+ "manifestJsonContent": Array [],
+ "savedImages": Array [
+ Object {
+ "height": 2732,
+ "name": "apple-splash-dark-2048-2732",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-2048-2732.jpeg",
+ "scaleFactor": 2,
+ "width": 2048,
+ },
+ Object {
+ "height": 2048,
+ "name": "apple-splash-dark-2732-2048",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2732-2048.jpeg",
+ "scaleFactor": 2,
+ "width": 2732,
+ },
+ Object {
+ "height": 2388,
+ "name": "apple-splash-dark-1668-2388",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-1668-2388.jpeg",
+ "scaleFactor": 2,
+ "width": 1668,
+ },
+ Object {
+ "height": 1668,
+ "name": "apple-splash-dark-2388-1668",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2388-1668.jpeg",
+ "scaleFactor": 2,
+ "width": 2388,
+ },
+ Object {
+ "height": 2224,
+ "name": "apple-splash-dark-1668-2224",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-1668-2224.jpeg",
+ "scaleFactor": 2,
+ "width": 1668,
+ },
+ Object {
+ "height": 1668,
+ "name": "apple-splash-dark-2224-1668",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2224-1668.jpeg",
+ "scaleFactor": 2,
+ "width": 2224,
+ },
+ Object {
+ "height": 2048,
+ "name": "apple-splash-dark-1536-2048",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-1536-2048.jpeg",
+ "scaleFactor": 2,
+ "width": 1536,
+ },
+ Object {
+ "height": 1536,
+ "name": "apple-splash-dark-2048-1536",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2048-1536.jpeg",
+ "scaleFactor": 2,
+ "width": 2048,
+ },
+ Object {
+ "height": 2688,
+ "name": "apple-splash-dark-1242-2688",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-1242-2688.jpeg",
+ "scaleFactor": 3,
+ "width": 1242,
+ },
+ Object {
+ "height": 1242,
+ "name": "apple-splash-dark-2688-1242",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2688-1242.jpeg",
+ "scaleFactor": 3,
+ "width": 2688,
+ },
+ Object {
+ "height": 2436,
+ "name": "apple-splash-dark-1125-2436",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-1125-2436.jpeg",
+ "scaleFactor": 3,
+ "width": 1125,
+ },
+ Object {
+ "height": 1125,
+ "name": "apple-splash-dark-2436-1125",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2436-1125.jpeg",
+ "scaleFactor": 3,
+ "width": 2436,
+ },
+ Object {
+ "height": 1792,
+ "name": "apple-splash-dark-828-1792",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-828-1792.jpeg",
+ "scaleFactor": 2,
+ "width": 828,
+ },
+ Object {
+ "height": 828,
+ "name": "apple-splash-dark-1792-828",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-1792-828.jpeg",
+ "scaleFactor": 2,
+ "width": 1792,
+ },
+ Object {
+ "height": 2208,
+ "name": "apple-splash-dark-1242-2208",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-1242-2208.jpeg",
+ "scaleFactor": 3,
+ "width": 1242,
+ },
+ Object {
+ "height": 1242,
+ "name": "apple-splash-dark-2208-1242",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-2208-1242.jpeg",
+ "scaleFactor": 3,
+ "width": 2208,
+ },
+ Object {
+ "height": 1334,
+ "name": "apple-splash-dark-750-1334",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-750-1334.jpeg",
+ "scaleFactor": 2,
+ "width": 750,
+ },
+ Object {
+ "height": 750,
+ "name": "apple-splash-dark-1334-750",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-1334-750.jpeg",
+ "scaleFactor": 2,
+ "width": 1334,
+ },
+ Object {
+ "height": 1136,
+ "name": "apple-splash-dark-640-1136",
+ "orientation": "portrait",
+ "path": "temp/apple-splash-dark-640-1136.jpeg",
+ "scaleFactor": 2,
+ "width": 640,
+ },
+ Object {
+ "height": 640,
+ "name": "apple-splash-dark-1136-640",
+ "orientation": "landscape",
+ "path": "temp/apple-splash-dark-1136-640.jpeg",
+ "scaleFactor": 2,
+ "width": 1136,
+ },
+ ],
+}
+`;
+
+exports[`generates favicon html as part of htmlMeta 1`] = `
+Object {
+ "htmlMeta": Object {
+ "appleMobileWebAppCapable": "
+",
+ "appleTouchIcon": "
+
+
+
+",
+ "favicon": "
+",
+ },
+ "manifestJsonContent": Array [
+ Object {
+ "sizes": "192x192",
+ "src": "temp/manifest-icon-192.png",
+ "type": "image/png",
+ },
+ Object {
+ "sizes": "512x512",
+ "src": "temp/manifest-icon-512.png",
+ "type": "image/png",
+ },
+ ],
+ "savedImages": Array [
+ Object {
+ "height": 180,
+ "name": "apple-icon-180",
+ "orientation": null,
+ "path": "temp/apple-icon-180.png",
+ "scaleFactor": undefined,
+ "width": 180,
+ },
+ Object {
+ "height": 167,
+ "name": "apple-icon-167",
+ "orientation": null,
+ "path": "temp/apple-icon-167.png",
+ "scaleFactor": undefined,
+ "width": 167,
+ },
+ Object {
+ "height": 152,
+ "name": "apple-icon-152",
+ "orientation": null,
+ "path": "temp/apple-icon-152.png",
+ "scaleFactor": undefined,
+ "width": 152,
+ },
+ Object {
+ "height": 120,
+ "name": "apple-icon-120",
+ "orientation": null,
+ "path": "temp/apple-icon-120.png",
+ "scaleFactor": undefined,
+ "width": 120,
+ },
+ Object {
+ "height": 192,
+ "name": "manifest-icon-192",
+ "orientation": null,
+ "path": "temp/manifest-icon-192.png",
+ "scaleFactor": undefined,
+ "width": 192,
+ },
+ Object {
+ "height": 512,
+ "name": "manifest-icon-512",
+ "orientation": null,
+ "path": "temp/manifest-icon-512.png",
+ "scaleFactor": undefined,
+ "width": 512,
+ },
+ Object {
+ "height": 196,
+ "name": "favicon-196",
+ "orientation": null,
+ "path": "temp/favicon-196.png",
+ "scaleFactor": undefined,
+ "width": 196,
+ },
+ ],
+}
+`;
+
+exports[`generates icons and splash screens when called via function 1`] = `
+Object {
+ "htmlMeta": Object {
+ "appleLaunchImage": "
",
+ "appleMobileWebAppCapable": "
+",
+ "appleTouchIcon": "
+
+
+
+",
+ },
"manifestJsonContent": Array [
Object {
"sizes": "192x192",
diff --git a/src/cli.ts b/src/cli.ts
index 658554cb..c58a7094 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -24,9 +24,10 @@ $ pwa-asset-generator --help
-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]
- -f --favicon Generate favicon [default: false]
+ -f --favicon Generate favicon image and HTML meta tag [default: false]
-l --landscape-only Only generate landscape splash screens [default: false]
-r --portrait-only Only generate portrait splash screens [default: false]
+ -d --dark-mode Generate iOS splash screen meta with (prefers-color-scheme: dark) media attr [default: false]
-u --single-quotes Generate HTML meta tags with single quotes [default: false]
-g --log Logs the steps of the library process [default: true]
@@ -36,6 +37,8 @@ $ pwa-asset-generator --help
$ pwa-asset-generator https://your-cdn-server.com/assets/logo.png ./ -t jpeg -q 90 --splash-only --portrait-only
$ pwa-asset-generator logo.svg ./assets --scrape false --icon-only --path "%PUBLIC_URL%"
$ pwa-asset-generator logo.svg ./assets --icon-only --favicon
+ $ pwa-asset-generator logo.svg ./assets --dark-mode --background dimgrey --splash-only --type jpeg --quality 80
+ $ pwa-asset-generator logo.svg ./assets --padding "calc(50vh - 5%) calc(50vw - 10%)"
$ pwa-asset-generator https://raw.githubusercontent.com/onderceylan/pwa-asset-generator/HEAD/static/logo.png ./temp -p "15%" -b "linear-gradient(to right, #fa709a 0%, #fee140 100%)"
Flag examples
@@ -53,6 +56,7 @@ $ pwa-asset-generator --help
--favicon
--landscape-only
--portrait-only
+ --dark-mode
--single-quotes
--log false
`,
@@ -69,6 +73,7 @@ const logger = preLogger('cli', cli.flags);
(async (): Promise => {
try {
await generateImages(cli.input[0], cli.input[1], cli.flags, logger);
+ process.exit(0);
} catch (e) {
logger.error(e);
process.exit(1);
diff --git a/src/config/constants.ts b/src/config/constants.ts
index 36963112..9ec1dc04 100644
--- a/src/config/constants.ts
+++ b/src/config/constants.ts
@@ -1,4 +1,30 @@
import { Orientation } from '../models/image';
+import { HTMLMetaNames, HTMLMetaSelector } from '../models/meta';
+
+const HTML_META_ORDERED_SELECTOR_LIST: HTMLMetaSelector[] = [
+ {
+ name: HTMLMetaNames.favicon,
+ selector: 'link[rel="icon"]',
+ },
+ {
+ name: HTMLMetaNames.appleTouchIcon,
+ selector: 'link[rel="apple-touch-icon"]',
+ },
+ {
+ name: HTMLMetaNames.appleMobileWebAppCapable,
+ selector: 'meta[name="apple-mobile-web-app-capable"]',
+ },
+ {
+ name: HTMLMetaNames.appleLaunchImage,
+ selector:
+ 'link[rel="apple-touch-startup-image"]:not([media^="(prefers-color-scheme: dark)"])',
+ },
+ {
+ name: HTMLMetaNames.appleLaunchImageDarkMode,
+ selector:
+ 'link[rel="apple-touch-startup-image"][media^="(prefers-color-scheme: dark)"]',
+ },
+];
export default {
FLAGS: {
@@ -79,6 +105,11 @@ export default {
alias: 'f',
default: false,
},
+ darkMode: {
+ type: 'boolean',
+ alias: 'd',
+ default: false,
+ },
},
PUPPETEER_LAUNCH_ARGS: [
@@ -121,16 +152,19 @@ export default {
FAVICON_SIZES: [196],
+ HTML_META_ORDERED_SELECTOR_LIST,
+
FAVICON_FILENAME_PREFIX: 'favicon',
APPLE_ICON_FILENAME_PREFIX: 'apple-icon',
APPLE_SPLASH_FILENAME_PREFIX: 'apple-splash',
+ APPLE_SPLASH_FILENAME_DARK_MODE_POSTFIX: '-dark',
MANIFEST_ICON_FILENAME_PREFIX: 'manifest-icon',
APPLE_HIG_SPLASH_SCR_SPECS_DATA_GRID_SELECTOR: 'table tbody tr',
WAIT_FOR_SELECTOR_TIMEOUT: 1000,
BROWSER_SHELL_TIMEOUT: 60000,
- FAVICON_META_HTML: (size: number, url: string, mimeType: string): string => `\
-
+ FAVICON_META_HTML: (size: number, url: string, mimeType: string): string =>
+ `
`,
SHELL_HTML_FOR_LOGO: (
@@ -163,8 +197,8 @@ export default {