Skip to content

Commit

Permalink
fix: prevent crash on copy and move action when file does not exits (#23
Browse files Browse the repository at this point in the history
)
  • Loading branch information
François Rosato committed Mar 9, 2020
1 parent 98ab1bb commit 5495d49
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,30 @@ export const onPostBuild = async ({ pathPrefix }, { additionalPaths = [] }) => {
const publicFolder = "./public";
const assetFolder = path.join(publicFolder, `.${pathPrefix}`);

const copy = (fileOrFolder) => {
const currentPath = path.join(publicFolder, fileOrFolder);
const newPath = path.join(assetFolder, fileOrFolder);
try {
if (fs.existsSync(currentPath)) {
return fs.copy(currentPath, newPath);
}
} catch (err) {
console.error(err);
return Promise.resolve();
}
};

const move = (fileOrFolder) => {
const currentPath = path.join(publicFolder, fileOrFolder);
const newPath = path.join(assetFolder, fileOrFolder);
return fs.move(currentPath, newPath);
try {
if (fs.existsSync(currentPath)) {
return fs.move(currentPath, newPath);
}
} catch (err) {
console.error(err);
return Promise.resolve();
}
};

const filterFilesIn = (folder) =>
Expand Down

0 comments on commit 5495d49

Please sign in to comment.