-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle.js
57 lines (53 loc) · 1.24 KB
/
handle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* 将vue 更改的部分复制过来
*/
const ncp = require('ncp').ncp;
const fs = require('fs');
const path = require('path');
const list = [
{
source: '../src/platforms/web',
destination: './platforms/web',
},
{
source: '../src/core/vdom',
destination: './core/vdom',
},
];
const options = {
clear: true,
ncpOptions: {
clobber: true,
stopOnErr: true,
},
};
list.forEach((data) => {
let { source, destination } = data;
source = path.resolve(source);
destination = path.resolve(destination);
if (options.clear) {
emptyDir(destination);
console.log('清空目标文件夹成功!');
}
copyTo(source, destination, options.ncpOptions, () => {
console.log('复制到目标文件夹成功!');
});
});
function emptyDir(dir, cb) {
const files = fs.readdirSync(dir);
for (const file of files) {
const curentPath = path.join(dir, file);
const stat = fs.statSync(curentPath);
if (stat.isDirectory()) {
fs.rmdirSync(curentPath, {
recursive: true,
});
} else fs.unlinkSync(curentPath);
}
}
function copyTo(source, destination, options = {}, cb) {
ncp(source, destination, options, (err) => {
if (err) throw err;
if (typeof cb === 'function') cb();
});
}