Generate a project based on a directory of template files and corresponding template values
npm install project-template
Generate a project based on a directory of template files and corresponding template values.
- Node JS v6+
``sh`
yarn add project-template
`sh`
yarn run example
See example/index.js
`js
const projectTemplate = require('project-template');
projectTemplate({
templatePath: '/path/to/templates',
buildPath: '/path/to/build',
params: {
'path/to/file.txt': {
firstParam: 'First param value',
secondParam: 'Second param value',
},
'path/to/different/file.txt': {
anotherParam: 'Another param value',
},
},
})
.then(files => console.log('Done', files))
.catch(err => console.error('Error', err));
`
- Template files are expected to use ect syntax
- Directory structure of files in templatePath is maintained in buildPathtemplatePath
- All files in with fileExtension must be included in paramstemplatePath
- Files in without fileExtension are just copied over to buildPathfileExtension
- You cannot have two files with the same file path where one has and the other doesn't
#### options
| Key | Type | Required | Default | Notes |
| --- | --- | --- | --- | --- |
| templatePath | String | Yes | | Directory path containing template files |
| buildPath | String | Yes | | Directory path to write generated files to |
| params | Object | No | {} | Keys are relative paths of template files (with fileExtension stripped). Values are objects of template variables |[]
| ignoreFiles | Array<String> | No | | File paths to ignore (exclude the fileExtension for template files). Useful for ect partials |ect
| fileExtension | String | No | | File extension of template files |
#### Result
The promise is resolved with an array of file paths of generated files, relative to the buildPath` directory.