UNPKG

800 BJavaScriptView Raw
1'use strict';
2
3const fs = require('fs');
4const path = require('path');
5
6const isFileSync = require('./isFileSync');
7const mkdirpSync = require('./mkdirpSync');
8
9function copyFiles(files, target_dir, options) {
10
11 if(!options)
12 options = {};
13
14 if(typeof files == 'string')
15 files = [files];
16
17 var cwd = options.cwd || process.cwd();
18
19 files.forEach((file_path, index) => {
20 if(!isFileSync(path.join(cwd, file_path)))
21 return;
22
23 let current_dir = path.dirname(file_path);
24 let content = fs.readFileSync(path.join(cwd, file_path));
25
26 mkdirpSync(path.join(target_dir, current_dir));
27
28 if(options.process)
29 content = options.process(content, file_path, index);
30
31 fs.writeFileSync(path.join(target_dir, file_path), content);
32 });
33
34}
35
36module.exports = copyFiles;