Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

template-dir

aichbauer2MIT2.0.1

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

recursive, file, directoy, copy, template, template-file, template-dir

readme

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

Build Status Build status Coverage Status

Installation

$ npm i template-dir --save

or

$ yarn add template-dir

Usage

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-1

The 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-1

The 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-1

The template-1 with filled variables:

My name is Lukas and I am 25 years old.

LICENSE

MIT © Lukas Aichbauer

changelog

2.0.1 - September, 19 2017

  • 3e98e77 Docs: update readme for new feat (aichbauer)

2.0.0 - September, 19 2017

  • e5a391f Test: update tests for new feat (aichbauer)
  • 9ada5e0 Test: update the fixtures (aichbauer)
  • 717c117 Feat: add exclude, change source, dest, onlyFiles exclude to one object (aichbauer)

1.0.0 - September, 14 2017

  • ca8b147 Chore: add missing email (aichbauer)
  • 7f3ffb6 Docs: fix installation for npm (aichbauer)
  • 98d476b Docs: add badges (aichbauer)
  • 798f1f1 Initial commit (aichbauer)