@danhu90/work-template-cli
Version:
A CLI to bootstrap my projects
28 lines (19 loc) • 819 B
JavaScript
import * as fs from 'fs';
const CURR_DIR = process.cwd();
const createDirectoryContents = (templatePath, newProjectPath) => {
const filesToCreate = fs.readdirSync(templatePath);
filesToCreate.forEach(file => {
const origFilePath = `${templatePath}/${file}`;
const stats = fs.statSync(origFilePath);
if (stats.isFile()) {
const contents = fs.readFileSync(origFilePath, 'utf8');
if (file === '.npmignore') file = '.gitignore';
const writePath = `${CURR_DIR}/${newProjectPath}/${file}`;
fs.writeFileSync(writePath, contents, 'utf8');
} else if (stats.isDirectory()) {
fs.mkdirSync(`${CURR_DIR}/${newProjectPath}/${file}`);
createDirectoryContents(`${templatePath}/${file}`, `${newProjectPath}/${file}`)
}
});
};
export default createDirectoryContents;