-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.js
119 lines (108 loc) · 3.04 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
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
const { webpack } = require('webpack');
const { compile } = require('nexe');
const { minify } = require("terser");
var path = require('path');
var fs = require('fs');
const TerserPlugin = require('terser-webpack-plugin');
const nexeUpxPlugin = require('./utils/nexe-upx-plugin');
var cliArgs = (function() {
var args = {};
var arg, key;
for(var i = 0; i < process.argv.length; i++) {
if((arg = /^--([^=]+)(?:=(.+))?$/.exec(process.argv[i]))) {
key = arg[1];
args[arg[1]] = arg[2] || true;
}
else if(key) {
args[key] = process.argv[i];
key = null;
}
}
return args;
})();
var debugMode = !!cliArgs['debug'];
const deleteFolderRecursive = function(cpath) {
if (fs.existsSync(cpath)) {
fs.readdirSync(cpath).forEach((file, index) => {
const curPath = path.join(cpath, file);
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(cpath);
}
};
var srcBasePath = path.join(__dirname, "src");
if (!fs.existsSync(srcBasePath))
throw "src path not found";
var buildPath = path.join(__dirname, "build");
if (!fs.existsSync(buildPath))
fs.mkdirSync(buildPath);
var releasePath = path.join(__dirname, "release");
if (!fs.existsSync(releasePath))
fs.mkdirSync(releasePath);
function buildClient() {
console.log("Building Client to '" + releasePath + "'");
return (new Promise((resolve, reject) => {
webpack({
entry: path.join(srcBasePath, 'funding-tool.js'),
target: 'node',
mode: debugMode ? 'development' : 'production',
output: {
path: buildPath,
filename: "app.js"
},
}, (err, stats) => {
if(stats && stats.hasErrors())
console.error("webpack error", stats.compilation.errors);
if (err)
reject(err);
else
resolve();
});
})).then(() => {
let cliBuildList = [
{
arch: 'linux-x64',
output: 'funding-tool-amd64',
target: 'linux-x64-14.15.3'
},
{
arch: 'linux-x86',
output: 'funding-tool-x86',
target: 'linux-x86-14.15.3'
},
{
arch: 'win32-x64',
output: 'funding-tool-win64.exe',
target: 'windows-x64-14.15.3'
},
{
arch: 'win32-x86',
output: 'funding-tool-win32.exe',
target: 'windows-x86-14.15.3'
},
];
console.log("Building Client Executable to '" + releasePath + "'");
return Promise.all(cliBuildList.map((cliBuild) => {
return compile({
input: path.join(buildPath, 'app.js'),
output: path.join(releasePath, cliBuild.output),
target: cliBuild.target,
temp: buildPath,
silent: true,
resources: [ path.join(buildPath, 'app.js') ],
plugins: [ nexeUpxPlugin(!debugMode) ]
});
}));
}).then(() => {
console.log("build complete");
});
}
buildClient().then(() => {
console.log('success')
}, (err) => {
console.log('error', err)
});