copy-template-dir-ts
v1.0.0
Published
High throughput template dir writes
Downloads
516
Maintainers
Readme
copy-template-dir-ts
This is a rewrite of copy-template-dir with TypeScript and ESM support.
High throughput template dir writes. Supports variable injection using the
mustache {{ }}
syntax.
Installation
$ npm install copy-template-dir-ts
Usage
import copy from 'copy-template-dir-ts'
import path from 'path'
const vars = { foo: 'bar' }
const inDir = path.join(process.cwd(), 'templates')
const outDir = path.join(process.cwd(), 'dist')
const createdFiles = copy(inDir, outDir, vars)
for (const file of createdFiles) {
console.log(`Created ${file}`)
}
console.log('done!')
API
copyTemplateDir(templateDir, targetDir, vars)
Copy a directory of files over to the target directory, and inject the files with variables. Takes the following arguments:
- templateDir: The directory that holds the templates. Filenames prepended
with a
_
will have it removed when copying. Dotfiles need to be prepended with a_
. Files and filenames are populated with variables using the{{varName}}
syntax. - targetDir: the output directory
- vars: An object with variables that are injected into the template files and file names.