-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
executable file
·184 lines (145 loc) · 4.64 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env node
const { execSync, spawn } = require('child_process');
const { readFileSync, statSync, rmdirSync, mkdirSync } = require('fs');
// Check that the script is run from the root.
try {
const wailsJsonFile = statSync('./wails.json');
if (!wailsJsonFile.isFile()) {
throw new Error();
}
} catch {
console.log('Error: please run the build script from the Rolens project root.');
process.exit(1);
}
// Output version.
const version = JSON.parse(readFileSync('./wails.json').toString()).info.productVersion;
if (process.argv.includes('-v') || process.argv.includes('-version') || process.argv.includes('--version')) {
console.log(version);
process.exit(0);
}
// Output help text.
if (process.argv.includes('-h') || process.argv.includes('--help')) {
console.log(`Rolens build script v${version}`);
console.log('');
console.log('This script installs missing dependencies if any, and then compiles Rolens');
console.log('for the current platform.');
console.log('');
console.log('Options:');
console.log(' -h --help Show this help text and exit.');
console.log(' -q --quiet Do not output Wails build log.');
console.log(' -v --version Log the current Rolens version and exit.');
process.exit(0);
}
// Shared objects.
const quiet = process.argv.includes('-q') || process.argv.includes('--quiet');
const isWindows = process.platform === 'win32';
const missingDependencies = [];
function isNullish(val) {
return val === undefined || val === null;
}
// Check that Go ^1.20 is installed.
try {
const goMinorVersion = /go1\.([0-9][0-9])/.exec(
execSync('go version').toString()
)?.pop();
if (isNullish(goMinorVersion) || (parseInt(goMinorVersion) < 20)) {
throw new Error();
}
} catch {
missingDependencies.push({ name: 'Go ^1.20', url: 'https://go.dev/doc/install' });
}
// Check that Node.js ^16 is installed.
try {
const nodeMajorVersion = /v([0-9]{1,2})\.[0-9]{1,3}\.[0-9]{1,3}/.exec(
execSync('node --version').toString()
)?.pop();
if (isNullish(nodeMajorVersion) || (parseInt(nodeMajorVersion) < 16)) {
throw new Error();
}
} catch {
missingDependencies.push({ name: 'Node.js ^16', url: 'https://go.dev/doc/install' });
}
// Check that Wails is installed.
try {
const wailsMinorVersion = /v2\.([0-9])\.[0-9]/.exec(
execSync('wails version').toString()
)?.pop();
if (isNullish(wailsMinorVersion) || (parseInt(wailsMinorVersion) < 3)) {
throw new Error();
}
} catch {
missingDependencies.push({
name: 'Wails ^2.3',
command: 'go install github.com/wailsapp/wails/v2/cmd/wails@latest',
url: 'https://wails.io/docs/gettingstarted/installation',
});
}
// Check that NSIS is installed on Windows.
if (isWindows) {
try {
const nsisInstalled = /v3\.([0-9][0-9])/.test(execSync('makensis.exe /VERSION').toString());
if (!nsisInstalled) {
throw new Error();
}
} catch {
missingDependencies.push({
name: 'Nullsoft Install System ^3',
command: 'choco install nsis',
url: 'https://nsis.sourceforge.io/Download',
comment: 'Note: you should add makensis.exe to your path:\n setx /M PATH "%PATH%;C:\\Program Files (x86)\\NSIS\\Bin"'
});
}
}
// Report missing dependencies.
if (missingDependencies.length > 0) {
console.log('You are missing the following dependencies:');
for (const dependency of missingDependencies) {
console.log('');
console.log(`- ${dependency.name}`);
if (dependency.command) {
console.log(' Install it by executing:');
console.log(` ${dependency.command}`);
}
if (dependency.url) {
console.log(' Visit the following page for more information:');
console.log(` ${dependency.url}`);
}
if (dependency.comment) {
console.log(` ${dependency.comment}`);
}
}
process.exit(1);
}
// Clean output directory.
console.log('Cleaning output directory...');
try { rmdirSync('./build/bin'); } catch {}
try {
mkdirSync('./build/bin');
}
catch (err) {
console.log('Failed to create build output directory!');
}
// Build Rolens.
console.log(`Building Rolens ${version}...`);
console.log();
const proc = spawn('wails', [ 'build', '-clean', isWindows ? '-nsis' : '' ]);
if (!quiet) {
const suppressMessages = [
'Wails CLI',
'If Wails is useful',
'https://github.com/sponsors/leaanthony',
];
proc.stdout.on('data', data => {
for (let i = 0; i < suppressMessages.length; i++) {
if (data.toString().indexOf(suppressMessages[i]) !== -1) {
return;
}
}
process.stdout.write(data);
});
proc.stderr.on('data', data => process.stderr.write(data));
}
proc.on('exit', code => {
console.log();
process.exit(code);
});