Skip to content

Commit

Permalink
fix(main): fix wrong icons file name when 'pathOverride' option is used
Browse files Browse the repository at this point in the history
When 'pathOverride' option is used, the file name in the manifest entry was not reflecting the image
file name generated.

fix #723
  • Loading branch information
onderceylan committed Nov 7, 2021
1 parent d7b488d commit 25cef00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2318,25 +2318,25 @@ Object {
Object {
"purpose": "any",
"sizes": "192x192",
"src": "./my-custom-path-override/manifest-icon-192.png",
"src": "./my-custom-path-override/manifest-icon-192.maskable.png",
"type": "image/png",
},
Object {
"purpose": "maskable",
"sizes": "192x192",
"src": "./my-custom-path-override/manifest-icon-192.png",
"src": "./my-custom-path-override/manifest-icon-192.maskable.png",
"type": "image/png",
},
Object {
"purpose": "any",
"sizes": "512x512",
"src": "./my-custom-path-override/manifest-icon-512.png",
"src": "./my-custom-path-override/manifest-icon-512.maskable.png",
"type": "image/png",
},
Object {
"purpose": "maskable",
"sizes": "512x512",
"src": "./my-custom-path-override/manifest-icon-512.png",
"src": "./my-custom-path-override/manifest-icon-512.maskable.png",
"type": "image/png",
},
],
Expand Down Expand Up @@ -2646,25 +2646,25 @@ Object {
Object {
"purpose": "any",
"sizes": "192x192",
"src": "./my-custom-path-override/manifest-icon-192.png",
"src": "./my-custom-path-override/manifest-icon-192.maskable.png",
"type": "image/png",
},
Object {
"purpose": "maskable",
"sizes": "192x192",
"src": "./my-custom-path-override/manifest-icon-192.png",
"src": "./my-custom-path-override/manifest-icon-192.maskable.png",
"type": "image/png",
},
Object {
"purpose": "any",
"sizes": "512x512",
"src": "./my-custom-path-override/manifest-icon-512.png",
"src": "./my-custom-path-override/manifest-icon-512.maskable.png",
"type": "image/png",
},
Object {
"purpose": "maskable",
"sizes": "512x512",
"src": "./my-custom-path-override/manifest-icon-512.png",
"src": "./my-custom-path-override/manifest-icon-512.maskable.png",
"type": "image/png",
},
],
Expand Down
23 changes: 11 additions & 12 deletions src/helpers/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { HTMLMeta, HTMLMetaNames, HTMLMetaSelector } from '../models/meta';

const generateOutputPath = (
options: Options,
imageName: string,
imagePath: string,
isManifest = false,
): string => {
Expand All @@ -27,7 +26,7 @@ const generateOutputPath = (
) as string;

if (pathOverride) {
return `${pathOverride}/${imageName}${path.extname(imagePath)}`;
return `${pathOverride}/${path.parse(imagePath).base}`;
}

if (pathPrefix && !isManifest) {
Expand All @@ -48,9 +47,9 @@ const generateIconsContentForManifest = (
.filter((image) =>
image.name.startsWith(constants.MANIFEST_ICON_FILENAME_PREFIX),
)
.reduce((curr, { path: imagePath, width, height, name }) => {
.reduce((curr, { path: imagePath, width, height }) => {
const icon: ManifestJsonIcon = {
src: generateOutputPath(options, name, imagePath),
src: generateOutputPath(options, imagePath),
sizes: `${width}x${height}`,
type: `image/${file.getExtension(imagePath)}`,
};
Expand All @@ -72,9 +71,9 @@ const generateAppleTouchIconHtml = (
.filter((image) =>
image.name.startsWith(constants.APPLE_ICON_FILENAME_PREFIX),
)
.map(({ path: imagePath, name }) =>
.map(({ path: imagePath }) =>
constants.APPLE_TOUCH_ICON_META_HTML(
generateOutputPath(options, name, imagePath),
generateOutputPath(options, imagePath),
options.xhtml,
),
)
Expand All @@ -87,10 +86,10 @@ const generateFaviconHtml = (
): string => {
return savedImages
.filter((image) => image.name.startsWith(constants.FAVICON_FILENAME_PREFIX))
.map(({ width, path: imagePath, name }) =>
.map(({ width, path: imagePath }) =>
constants.FAVICON_META_HTML(
width,
generateOutputPath(options, name, imagePath),
generateOutputPath(options, imagePath),
lookup(imagePath) as string,
options.xhtml,
),
Expand All @@ -104,10 +103,10 @@ const generateMsTileImageHtml = (
): string => {
return savedImages
.filter((image) => image.name.startsWith(constants.MS_ICON_FILENAME_PREFIX))
.map(({ width, height, path: imagePath, name }) =>
.map(({ width, height, path: imagePath }) =>
constants.MSTILE_IMAGE_META_HTML(
constants.MSTILE_SIZE_ELEMENT_NAME_MAP[`${width}x${height}`],
generateOutputPath(options, name, imagePath),
generateOutputPath(options, imagePath),
options.xhtml,
),
)
Expand All @@ -123,11 +122,11 @@ const generateAppleLaunchImageHtml = (
.filter((image) =>
image.name.startsWith(constants.APPLE_SPLASH_FILENAME_PREFIX),
)
.map(({ width, height, path: imagePath, name, scaleFactor, orientation }) =>
.map(({ width, height, path: imagePath, scaleFactor, orientation }) =>
constants.APPLE_LAUNCH_SCREEN_META_HTML(
width,
height,
generateOutputPath(options, name, imagePath),
generateOutputPath(options, imagePath),
scaleFactor as number,
orientation,
darkMode,
Expand Down

0 comments on commit 25cef00

Please sign in to comment.