-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-electron.js
More file actions
284 lines (233 loc) Ā· 7.8 KB
/
build-electron.js
File metadata and controls
284 lines (233 loc) Ā· 7.8 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/bin/env node
/**
* Flake Wire Electron Build Script (Node.js version)
* Cross-platform build script for the Electron application
*/
const fs = require('fs');
const path = require('path');
const { execSync, spawn } = require('child_process');
// Colors for console output
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m'
};
// Build configuration
const BUILD_DIR = 'dist';
const CLIENT_BUILD_DIR = 'client/dist';
const CLIENT_BUILD_FALLBACK = 'client/build';
// Utility functions
function log(message, color = colors.reset) {
console.log(`${color}${message}${colors.reset}`);
}
function logInfo(message) {
log(`[INFO] ${message}`, colors.green);
}
function logWarning(message) {
log(`[WARN] ${message}`, colors.yellow);
}
function logError(message) {
log(`[ERROR] ${message}`, colors.red);
}
function logStep(message) {
log(`š ${message}`, colors.blue);
}
function logSuccess(message) {
log(`ā
${message}`, colors.green);
}
function commandExists(command) {
try {
require('child_process').execSync(`which ${command}`, { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}
function execCommand(command, cwd = process.cwd(), options = {}) {
try {
logInfo(`Running: ${command}`);
const result = execSync(command, {
cwd,
stdio: 'inherit',
...options
});
return result;
} catch (error) {
logError(`Command failed: ${command}`);
throw error;
}
}
function checkPrerequisites() {
logStep('Checking prerequisites...');
// Check Node.js and npm
if (!commandExists('node')) {
logError('Node.js is not installed. Please install Node.js first.');
process.exit(1);
}
if (!commandExists('npm')) {
logError('npm is not installed. Please install npm first.');
process.exit(1);
}
// Check required directories
const requiredDirs = ['server', 'client', 'electron'];
for (const dir of requiredDirs) {
if (!fs.existsSync(dir)) {
logError(`Required directory not found: ${dir}`);
process.exit(1);
}
}
logSuccess('Prerequisites check passed');
}
function installDependencies() {
logStep('Installing dependencies...');
// Install root dependencies
execCommand('npm install');
// Install server dependencies
execCommand('npm install', path.join(process.cwd(), 'server'));
// Install client dependencies
execCommand('npm install', path.join(process.cwd(), 'client'));
// Check ffmpeg-static
const ffmpegStaticPath = path.join('server', 'node_modules', 'ffmpeg-static');
if (!fs.existsSync(ffmpegStaticPath)) {
logWarning('ffmpeg-static not found. Installing now...');
execCommand('npm install ffmpeg-static', path.join(process.cwd(), 'server'));
}
logSuccess('Dependencies installed');
}
function cleanBuilds() {
logStep('Cleaning previous builds...');
const dirsToClean = [BUILD_DIR, CLIENT_BUILD_DIR, CLIENT_BUILD_FALLBACK];
for (const dir of dirsToClean) {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true, force: true });
}
}
logSuccess('Previous builds cleaned');
}
function buildClient() {
logStep('Building the new client interface...');
const clientDir = path.join(process.cwd(), 'client');
execCommand('npm run build', clientDir);
const distPath = path.join(clientDir, 'dist');
if (!fs.existsSync(distPath)) {
logError('Client build failed! No dist directory created.');
process.exit(1);
}
logSuccess('Client build completed');
}
function prepareServer() {
logStep('Preparing server files...');
// Server files are already in JavaScript format
logSuccess('Server preparation completed');
}
function buildElectron() {
logStep('Building Electron application...');
// Set environment variables
process.env.NODE_ENV = 'production';
process.env.ELECTRON_TRANSCODE = 'true';
// Determine platform
const platform = process.platform;
let buildCommand = 'npm run electron:pack';
switch (platform) {
case 'linux':
logInfo('Building for Linux...');
buildCommand = 'npx electron-builder --linux';
break;
case 'darwin':
logInfo('Building for macOS...');
buildCommand = 'npx electron-builder --mac';
break;
case 'win32':
logInfo('Building for Windows...');
buildCommand = 'npx electron-builder --win';
break;
default:
logWarning(`Unknown platform: ${platform}. Building for all platforms...`);
buildCommand = 'npm run electron:pack';
}
try {
execCommand(buildCommand);
} catch (error) {
logError('Electron build failed');
throw error;
}
// Check if build was successful
if (!fs.existsSync(BUILD_DIR)) {
logError('Electron build failed! No dist directory created.');
process.exit(1);
}
logSuccess('Electron build completed');
}
function showResults() {
logStep('Build completed successfully! š');
console.log('\n' + colors.green + 'Build artifacts:' + colors.reset);
if (fs.existsSync(BUILD_DIR)) {
const files = fs.readdirSync(BUILD_DIR);
files.forEach(file => {
const filePath = path.join(BUILD_DIR, file);
const stats = fs.statSync(filePath);
const size = stats.isFile() ? ` (${(stats.size / 1024 / 1024).toFixed(2)} MB)` : '';
console.log(` ${file}${size}`);
});
}
console.log('\n' + colors.blue + 'š To run the Electron application:' + colors.reset);
console.log('\nDevelopment mode:');
console.log(' npm run electron:dev');
console.log('\nProduction mode (from built package):');
const platform = process.platform;
switch (platform) {
case 'linux':
console.log(` ./${BUILD_DIR}/Flake-Wire.AppImage`);
console.log(` # or: dpkg -i ${BUILD_DIR}/flake-wire_*.deb`);
break;
case 'darwin':
console.log(` open ${BUILD_DIR}/Flake-Wire.dmg`);
break;
case 'win32':
console.log(` ${BUILD_DIR}/Flake-Wire-Setup.exe`);
break;
default:
console.log(` Check the ${BUILD_DIR} directory for your platform's installer`);
}
console.log('\n' + colors.green + 'ā
Electron build process completed successfully!' + colors.reset);
console.log('\n' + colors.yellow + 'Notes:' + colors.reset);
console.log('- The application includes an embedded ffmpeg for MKV support');
console.log('- MKV files will be automatically processed for compatibility');
console.log('- The built application includes both server and client components');
console.log('- No external server setup required for the built application');
}
// Main build process
async function main() {
try {
console.log(colors.blue + 'š¬ Flake Wire Electron Build Script' + colors.reset);
console.log('==================================');
checkPrerequisites();
cleanBuilds();
installDependencies();
buildClient();
prepareServer();
buildElectron();
showResults();
} catch (error) {
logError(`Build failed: ${error.message}`);
process.exit(1);
}
}
// Handle process interruption
process.on('SIGINT', () => {
logWarning('\nBuild process interrupted by user');
process.exit(1);
});
process.on('SIGTERM', () => {
logWarning('\nBuild process terminated');
process.exit(1);
});
// Run the build
if (require.main === module) {
main();
}
module.exports = { main };