forked from Isidore-Newman-School/Beau-VanDenburgh-19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
90 lines (82 loc) · 2.62 KB
/
build.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
78
79
80
81
82
83
84
85
86
87
88
89
90
const packager = require('electron-packager');
const fs = require('fs');
var config=null, processed_files = 0;
console.log("Removing old build files")
deleteFolderRecursive("./tmp");
deleteFolderRecursive("./build");
packager(config = {
dir:"./src", //location of source files
icon:"./src/assets/img/logo_full_fuzzy.ico", //location of the icon
out:"./tmp", //where to put the executable
})
.catch(err=>{//log build errors
console.log(
"Errors were encountered:"
);
console.log(err);
})
.then(function (path) {
console.log("cleaning up...")
console.log(path)
fs.renameSync(path[0],'./build')
fs.rmdirSync('./tmp')
var node_modules = "./build/resources/app/node_modules"
var important_folders = ["build","dist"];
fs.readdirSync(node_modules).forEach( library => {
fs.readdirSync(node_modules + '/' + library)
.filter (subfolder => !important_folders.includes(subfolder))
.forEach(subfolder => {
deleteFolderRecursive(node_modules + "/" + library + "/" + subfolder)
});
});
deleteAnythingThatStartsWithPeriods("./build");
})
.then(function () {//success!
console.log(
" \r"+
"+==============+\n"+
"|BUILD SUCCESS!|\n"+
"+==============+\n"+
"\n"+
"You can copy the folder inside ./build to your desktop, and launch the program by double clicking on Project-Delta.app or Project-Delta.exe. type `npm run msi` to make a windows installer if you are on windows"
);
})
function deleteFolderRecursive(path) {
if( fs.existsSync(path) ) {
if(fs.lstatSync(path).isDirectory()){
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
updateDeleteProgress(curPath)
}
});
try {
updateDeleteProgress(path)
fs.rmdirSync(path);
} catch(e) {
fs.rmdirSync(path);
}
} else {
fs.unlinkSync(path);
}
}
};
function updateDeleteProgress(str){
process.stdout.write(`${processed_files++} files deleted\r`);
}
function deleteAnythingThatStartsWithPeriods(path) {
if( fs.existsSync(path) ) {
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteAnythingThatStartsWithPeriods(curPath);
} else if(file[0]==".") { // delete file
console.log(file)
fs.unlinkSync(curPath);
}
});
}
};