Skip to content

Instantly share code, notes, and snippets.

@harrietty
Created June 19, 2017 07:35
Show Gist options
  • Save harrietty/a018a93e4047d52d02a54be0b0ea14c2 to your computer and use it in GitHub Desktop.
Save harrietty/a018a93e4047d52d02a54be0b0ea14c2 to your computer and use it in GitHub Desktop.
const CURR_DIR = process.cwd();
inquirer.prompt(QUESTIONS)
.then(answers => {
const projectChoice = answers['project-choice'];
const projectName = answers['project-name'];
const templatePath = `${__dirname}/templates/${projectChoice}`;
fs.mkdirSync(`${CURR_DIR}/${projectName}`);
createDirectoryContents(templatePath, projectName);
});
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');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment