forked from m4heshd/whatsapp-desktop-dark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
90 lines (84 loc) · 3.4 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 path = require("path");
const fs = require('fs-extra');
const {exec} = require("child_process");
const {compile} = require('nexe');
let distDir = path.join(__dirname, 'dist', 'Windows');
let out = path.join(distDir, 'WADark.exe');
let stylePath = path.join(__dirname, 'styles', 'win32');
let distStylePath = path.join(distDir, 'styles', 'win32');
let target = 'windows-x86-12.9.1';
let platform = process.argv[2].trim();
switch (platform) {
case 'win32':
runBuild();
break;
case 'darwin':
distDir = path.join(__dirname, 'dist', 'macOS');
out = path.join(distDir, 'WADark');
stylePath = path.join(__dirname, 'styles', 'darwin');
distStylePath = path.join(distDir, 'styles', 'darwin');
target = 'mac-x64-12.9.1';
runBuild();
break;
default:
console.log('\x1b[31m%s\x1b[0m', 'Invalid platform type.\n');
}
function runBuild() {
compile({
input: path.join(__dirname, 'index.js'),
build: false,
output: out,
targets: target,
resources: ['gui/**/*']
}).then(() => {
try {
console.log('Copying resources..');
fs.copySync(stylePath, distStylePath);
fs.copySync(path.join(__dirname, 'info.json'), path.join(distDir, 'info.json'));
let themes = fs.readdirSync(path.join(__dirname, 'themes')).filter(x => x !== 'README.md');
let themeObjects = [];
themes.forEach(themeDir => {
themeObjects.push(JSON.parse(fs.readFileSync(path.join(__dirname, 'themes', themeDir, 'override.json'), 'utf8')))
});
fs.writeFileSync(path.join(distDir, 'override.json'), JSON.stringify(themeObjects, null, "\t"));
switch (platform) {
case 'win32':
setWinIcon();
break;
case 'darwin':
console.log('\x1b[32m%s\x1b[0m', '\nAll done. Run \'WADark\' from dist\\macOS directory.\n');
exec(`open "${distDir}"`);
break;
default:
console.log('\x1b[32m%s\x1b[0m', '\nAll done. Run the executable from dist directory.\n');
}
} catch (error) {
console.error(error);
}
}).catch(err => {
console.error(err);
});
}
function setWinIcon() {
if (process.platform === 'win32') {
let command = ' -open "' + out +'" ' +
'-save "' + out +'" ' +
'-action addoverwrite ' +
'-res "' + path.join(__dirname, 'icons', 'wa_dark.ico') + '" ' +
'-mask ICONGROUP,1,1033 ' +
'-log NUL';
exec(path.join('node_modules', 'resourcehacker', 'bin', 'ResourceHacker.exe') + command, function (error) {
if (error) {
console.log(error);
console.log('\x1b[31m%s\x1b[0m', 'Failed to set the windows executable icon.\n');
console.log('\x1b[32m%s\x1b[0m', '\nAll done. Run \'WADark.exe\' from dist\\Windows directory.\n');
exec(`start "" "${distDir}"`);
} else {
console.log('\x1b[32m%s\x1b[0m', '\nAll done. Run \'WADark.exe\' from dist\\Windows directory.\n');
exec(`start "" "${distDir}"`);
}
});
} else {
console.log('\x1b[32m%s\x1b[0m', '\nAll done. Run \'WADark.exe\' from dist\\Windows directory.\n');
}
}