template-dir
Copies files and folders from source directory to destination directory (all directories recursively or just files from the source directory) with template style from template-file
Installation
$ npm i template-dir --saveor
$ yarn add template-dirUsage
In this section you will see two example usages. One example copies the complete source directory tree to the destination and replaces all variables within the templates. The other example will only copy files within the source directory to the destination directory and replaces all variables within the templates.
The given source directory tree:
.
+-- source/directory/
|
+-- dir-1
| |
| +-- file-2
|
+-- dir-2
| |
| +-- file-3
|
+-- template-1The given template-1:
My name is {{name}} and I am {{age}} years old.example one
The template-dir module example WITH copying recursive all files and directories:
const templateDir = require('template-dir'); // import templateDir from 'template-dir';
// if we set onlyFiles to false it copies the complete directory tree
// from 'source/directory' to 'destination/directory'
// excluding 'dir-1'
templateDir(
{
source: 'source/directory',
destination: 'destination/directory',
onlyFiles: false,
exclude: ['dir-1'], // add as many directories as you want to the array
},
{
name: 'Lukas',
age: '25',
},
);The example above will copy the source directory tree to the 'destination/directory' and replace all variables within all files
The destination directory tree:
.
+-- destination/directory/
|
+-- dir-2
| |
| +-- file-3
|
+-- template-1The template-1 with filled variables:
My name is Lukas and I am 25 years old.example two
The template-dir module example WITHOUT copying recursive all files and directories:
const templateDir = require('template-dir'); // import templateDir from 'template-dir';
// if we set onlyFiles to true it copies only the files
// within 'source/directory' to 'destination/directory'
templateDir(
{
source: 'source/directory',
destination: 'destination/directory',
onlyFiles: true
},
{
name: 'Lukas',
age: '25',
},
);The example above will only copy the files within the source directory and will not recursively copy all directories and files.
The destination directory tree:
.
+-- destination/directory/
|
+-- template-1The template-1 with filled variables:
My name is Lukas and I am 25 years old.LICENSE
MIT © Lukas Aichbauer