import mkdirp from 'mkdirp' ; import globby from 'globby' ; import path from 'path' ; import ejs from 'ejs' ; import fs from 'fs' ; import { promisify } from 'util' ; const renderTemplate = async ( sourceFile , destFile , data = { } ) => { const content = await promisify ( fs . readFile ) ( sourceFile ) ; const result = ejs . render ( content . toString ( ) , data , { filename : sourceFile , } ) ; await mkdirp ( path . dirname ( destFile ) ) ; await promisify ( fs . writeFile ) ( destFile , result ) ; } ; export const generateProject = async ( projectName , sourcePath , destPath ) => { for ( const relativePath of globby . sync ( '**' , { cwd : sourcePath } ) ) { const sourceFile = path . join ( sourcePath , relativePath ) ; const destFile = path . join ( destPath , relativePath ) ; await renderTemplate ( sourceFile , destFile , { projectName , version : require ( '../../package.json' ) . version , } ) ; } } ;