项目作者: aichbauer

项目描述 :
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
高级语言: JavaScript
项目地址: git://github.com/aichbauer/node-template-dir.git
创建时间: 2017-09-14T17:48:14Z
项目社区:https://github.com/aichbauer/node-template-dir

开源协议:MIT License

下载


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

  1. $ npm i template-dir --save

or

  1. $ 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:

  1. .
  2. +-- source/directory/
  3. |
  4. +-- dir-1
  5. | |
  6. | +-- file-2
  7. |
  8. +-- dir-2
  9. | |
  10. | +-- file-3
  11. |
  12. +-- template-1

The given template-1:

  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:

  1. const templateDir = require('template-dir'); // import templateDir from 'template-dir';
  2. // if we set onlyFiles to false it copies the complete directory tree
  3. // from 'source/directory' to 'destination/directory'
  4. // excluding 'dir-1'
  5. templateDir(
  6. {
  7. source: 'source/directory',
  8. destination: 'destination/directory',
  9. onlyFiles: false,
  10. exclude: ['dir-1'], // add as many directories as you want to the array
  11. },
  12. {
  13. name: 'Lukas',
  14. age: '25',
  15. },
  16. );

The example above will copy the source directory tree to the ‘destination/directory’ and replace all variables within all files

The destination directory tree:

  1. .
  2. +-- destination/directory/
  3. |
  4. +-- dir-2
  5. | |
  6. | +-- file-3
  7. |
  8. +-- template-1

The template-1 with filled variables:

  1. My name is Lukas and I am 25 years old.

example two

The template-dir module example WITHOUT copying recursive all files and directories:

  1. const templateDir = require('template-dir'); // import templateDir from 'template-dir';
  2. // if we set onlyFiles to true it copies only the files
  3. // within 'source/directory' to 'destination/directory'
  4. templateDir(
  5. {
  6. source: 'source/directory',
  7. destination: 'destination/directory',
  8. onlyFiles: true
  9. },
  10. {
  11. name: 'Lukas',
  12. age: '25',
  13. },
  14. );

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:

  1. .
  2. +-- destination/directory/
  3. |
  4. +-- template-1

The template-1 with filled variables:

  1. My name is Lukas and I am 25 years old.

LICENSE

MIT © Lukas Aichbauer