1 | 'use strict';
|
2 |
|
3 | const fs = require('fs');
|
4 | const path = require('path');
|
5 |
|
6 | const isFileSync = require('./isFileSync');
|
7 | const mkdirpSync = require('./mkdirpSync');
|
8 |
|
9 | function 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 |
|
36 | module.exports = copyFiles;
|