-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron.conf.js
77 lines (73 loc) · 1.76 KB
/
electron.conf.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var fs = require('fs'),
stat = fs.stat;
// 复制目录
exists('./app', './buildsoure', copy);
deleteall('./build/package');
// 在复制目录前需要判断该目录是否存在,不存在需要先创建目录
function exists(src, dst, callback) {
fs.exists(dst, function (exists) {
// 已存在
if (exists) {
callback(src, dst);
}
// 不存在
else {
fs.mkdir(dst, function () {
callback(src, dst);
});
}
});
}
function copy(src, dst) {
// 读取目录中的所有文件/目录
fs.readdir(src, function (err, paths) {
if (err) {
throw err;
}
var exacLoop = function (index) {
if (index === paths.length - 1) console.log('\n\ncp electron files to buildsoure finished!!!\n\n');
};
paths.forEach(function (path, i) {
var _src = src + '/' + path,
_dst = dst + '/' + path,
readable, writable;
stat(_src, function (err, st) {
if (err) {
throw err;
}
// 判断是否为文件
if (st.isFile()) {
// 创建读取流
readable = fs.createReadStream(_src);
// 创建写入流
writable = fs.createWriteStream(_dst);
// 通过管道来传输流
readable.pipe(writable);
exacLoop(i);
}
// 如果是目录则递归调用自身
else if (st.isDirectory()) {
exists(_src, _dst, copy);
exacLoop(i);
} else {
exacLoop(i);
}
});
});
});
}
function deleteall(path) {
var files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) { // recurse
deleteall(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};