The best library for this is copy-template-dir.
Given a source folder and a destination folder, copy from one to the other.
const copy = require('copy-template-dir')
const path = require('path')
const vars = { foo: 'bar' }
const inDir = path.join(process.cwd(), 'templates')
const outDir = path.join(process.cwd(), 'dist')
copy(inDir, outDir, vars, (err, createdFiles) => {
if (err) throw err
createdFiles.forEach(filePath => console.log(`Created ${filePath}`))
console.log('done!')
})
// promise based alternative
const {promisify} = require('utils')
promisify(copy(inDir, outDir, vars))
.then(() => console.log('done'))
.catch(err => throw err)
- Scaffolding is nice to have for your CLI.
Other Express templating libraries:
As well as specific template flavors: