Skip to content

Instantly share code, notes, and snippets.

@bodaso
Last active April 4, 2018 18:32
Show Gist options
  • Save bodaso/70db2fe98d00d9eab158c5bf5118af2b to your computer and use it in GitHub Desktop.
Save bodaso/70db2fe98d00d9eab158c5bf5118af2b to your computer and use it in GitHub Desktop.
Copy a folder and subfolders without all the `node_modules` folders within... tested with Node v9.10.1
// yarn add fs-extra --dev
const fs = require("fs-extra");
console.log("*** start ***");
// replace ".src" with your own folder
fs
.copy("./src", "./dist", {
filter: path => {
// console.log("path ===", path);
// skip filter on files
if (fs.lstatSync(path).isFile()) return true;
// return false if path is directory and string contains node_modules
return !(path.indexOf("node_modules") > -1);
}
})
.then(() => {
console.log("folder copied successfully!");
console.log("*** end ***");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment