Skip to content

Commit

Permalink
fix(file.js, pwa.js, package.json): fix Windows backslash paths being…
Browse files Browse the repository at this point in the history
… added to icon and html content

Introduce the slash npm package to use in converting backslash paths generated for saved images to
slash paths, which are needed for generated html and manifest json content

fix #36
  • Loading branch information
leonelngande authored and onderceylan committed Aug 30, 2019
1 parent 64f6c3f commit 24fef99
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions helpers/file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const slash = require('slash');
const crypto = require('crypto');
const fileUrl = require('file-url');
const constants = require('../config/constants');
Expand Down Expand Up @@ -124,6 +125,10 @@ const addHashPostfixToImages = savedImages => {
);
};

const convertBackslashPathToSlashPath = backSlashPath => {
return slash(backSlashPath);
};

const saveHtmlShell = (imagePath, options, isUrl) => {
const imageUrl = isUrl ? imagePath : getFileUrlOfPath(imagePath);
const htmlContent = constants.SHELL_HTML_FOR_LOGO(
Expand All @@ -137,6 +142,7 @@ const saveHtmlShell = (imagePath, options, isUrl) => {

module.exports = {
addHashPostfixToImages,
convertBackslashPathToSlashPath,
saveHtmlShell,
isHtmlFile,
isImageFile,
Expand Down
18 changes: 14 additions & 4 deletions helpers/pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const generateIconsContentForManifest = (savedImages, manifestJsonPath) => {
)
.map(({ path, width, height }) => ({
src: manifestJsonPath
? file.getRelativeFilePath(manifestJsonPath, path)
: path,
? file.convertBackslashPathToSlashPath(
file.getRelativeFilePath(manifestJsonPath, path),
)
: file.convertBackslashPathToSlashPath(path),
sizes: `${width}x${height}`,
type: `image/${file.getExtension(path)}`,
}));
Expand All @@ -24,7 +26,11 @@ const generateAppleTouchIconHtml = (savedImages, indexHtmlPath) => {
.map(({ width, path }) =>
constants.APPLE_TOUCH_ICON_META_HTML(
width,
indexHtmlPath ? file.getRelativeFilePath(indexHtmlPath, path) : path,
indexHtmlPath
? file.convertBackslashPathToSlashPath(
file.getRelativeFilePath(indexHtmlPath, path),
)
: file.convertBackslashPathToSlashPath(path),
),
)
.join('');
Expand All @@ -39,7 +45,11 @@ const generateAppleLaunchImageHtml = (savedImages, indexHtmlPath) => {
constants.APPLE_LAUNCH_SCREEN_META_HTML(
width,
height,
indexHtmlPath ? file.getRelativeFilePath(indexHtmlPath, path) : path,
indexHtmlPath
? file.convertBackslashPathToSlashPath(
file.getRelativeFilePath(indexHtmlPath, path),
)
: file.convertBackslashPathToSlashPath(path),
scaleFactor,
orientation,
),
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"lodash.isequal": "^4.5.0",
"lodash.uniqwith": "^4.5.0",
"meow": "^5.0.0",
"puppeteer": "^1.19.0"
"puppeteer": "^1.19.0",
"slash": "^3.0.0"
},
"devDependencies": {
"@jedmao/semantic-release-npm-github-config": "^1.0.6",
Expand Down

0 comments on commit 24fef99

Please sign in to comment.