Skip to content

Instantly share code, notes, and snippets.

@harrietty
Created June 19, 2017 07:47
Show Gist options
  • Save harrietty/cc490c4c7e980da09c701d3d0f01a852 to your computer and use it in GitHub Desktop.
Save harrietty/cc490c4c7e980da09c701d3d0f01a852 to your computer and use it in GitHub Desktop.
function createDirectoryContents (templatePath, newProjectPath) {
const filesToCreate = fs.readdirSync(templatePath);
filesToCreate.forEach(file => {
const origFilePath = `${templatePath}/${file}`;
// get stats about the current file
const stats = fs.statSync(origFilePath);
if (stats.isFile()) {
const contents = fs.readFileSync(origFilePath, 'utf8');
const writePath = `${CURR_DIR}/${newProjectPath}/${file}`;
fs.writeFileSync(writePath, contents, 'utf8');
} else if (stats.isDirectory()) {
fs.mkdirSync(`${CURR_DIR}/${newProjectPath}/${file}`);
// recursive call
createDirectoryContents(`${templatePath}/${file}`, `${newProjectPath}/${file}`);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment