Skip to content

Commit

Permalink
Copy All Files Instead of Move (#32)
Browse files Browse the repository at this point in the history
Copy all files instead of moving them #31
  • Loading branch information
stephenreid committed May 18, 2020
1 parent e797072 commit 27880ad
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,18 @@ do not add 'icons' to paths parameter!`,
}
};

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

const filesExtensions = fileTypes.join("|");
const filesRegex = RegExp(`.*.(${filesExtensions})$`);
const filterFilesIn = (folder) =>
fs.readdirSync(folder).filter((file) => filesRegex.test(file));

const filesInPublicFolder = filterFilesIn(publicFolder);
const thingsToMove = paths

const thingsToCopy = ["icons"]
.concat(paths)
.concat(additionalPaths)
.concat(filesInPublicFolder);

const thingsToCopy = ["icons"];

// Copy icons
// Copy all files to the new prefix
await Promise.all(thingsToCopy.map(copy));
// Move files and directories
await Promise.all(thingsToMove.map(move));
};

1 comment on commit 27880ad

@raurir
Copy link
Contributor

@raurir raurir commented on 27880ad May 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @stephenreid

Please sign in to comment.