-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
127 lines (87 loc) · 3.64 KB
/
app.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import * as fs from "fs"
import * as path from "path";
const common = "common";
const user = "user";
const ballot = "ballot";
const vote = "voted";
const chaincode = "chaincode";
if (fs.existsSync(path.join(__dirname, common))) {
console.log(true);
}
deleteFolderRecursive(path.join(__dirname, "..", chaincode));
copy(path.join(__dirname, common), path.join(__dirname, "..", chaincode, user, common));
copy(path.join(__dirname, user), path.join(__dirname, "..", chaincode, user, "src"));
copyFile(path.join(__dirname, "..", "packagebak.json"), path.join(__dirname, "..", chaincode, user, "package.json"));
copyFile(path.join(__dirname, "..", "package-lock.json"), path.join(__dirname, "..", chaincode, user, "package-lock.json"));
copyFile(path.join(__dirname, "..", "tslint.json"), path.join(__dirname, "..", chaincode, user, "tslint.json"));
copy(path.join(__dirname, common), path.join(__dirname, "..", chaincode, ballot, common));
copy(path.join(__dirname, "..", "data"), path.join(__dirname, "..", chaincode, ballot, "data"));
copy(path.join(__dirname, ballot), path.join(__dirname, "..", chaincode, ballot, "src"));
copyFile(path.join(__dirname, "..", "packagebak.json"), path.join(__dirname, "..", chaincode, ballot, "package.json"));
copyFile(path.join(__dirname, "..", "package-lock.json"), path.join(__dirname, "..", chaincode, ballot, "package-lock.json"));
copyFile(path.join(__dirname, "..", "tslint.json"), path.join(__dirname, "..", chaincode, ballot, "tslint.json"));
copy(path.join(__dirname, common), path.join(__dirname, "..", chaincode, vote, common));
copy(path.join(__dirname, vote), path.join(__dirname, "..", chaincode, vote, "src"));
copyFile(path.join(__dirname, "..", "packagebak.json"), path.join(__dirname, "..", chaincode, vote, "package.json"));
copyFile(path.join(__dirname, "..", "package-lock.json"), path.join(__dirname, "..", chaincode, vote, "package-lock.json"));
copyFile(path.join(__dirname, "..", "tslint.json"), path.join(__dirname, "..", chaincode, vote, "tslint.json"));
function copy(from, to) {
const fromPath = path.resolve(from);
const toPath = path.resolve(to)
if (!fs.existsSync(toPath)) {
mkdirsSync(toPath);
}
fs.access(toPath, function (err) {
if (err) {
fs.mkdirSync(toPath)
}
})
fs.readdir(fromPath, function (err, paths) {
if (err) {
console.log(err)
return
}
paths.forEach(function (item) {
const newFromPath = fromPath + '/' + item
const newToPath = path.resolve(toPath + '/' + item)
fs.stat(newFromPath, function (err, stat) {
if (err) return
if (stat.isFile()) {
copyFile(newFromPath, newToPath)
}
if (stat.isDirectory()) {
copy(newFromPath, newToPath)
}
})
})
})
}
function copyFile(from, to) {
fs.copyFileSync(from, to);
}
function mkdirsSync(dirname, mode?) {
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirsSync(path.dirname(dirname), mode)) {
fs.mkdirSync(dirname, mode);
return true;
}
}
}
function deleteFolderRecursive(url) {
var files = [];
if (fs.existsSync(url)) {
files = fs.readdirSync(url);
files.forEach(function (file, index) {
var curPath = path.join(url, file);
if (fs.statSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(url);
} else {
}
}