75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
// nexe.js - Compile i18n to Windows executable using nexe Node.js API
|
|
import { compile } from 'nexe';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
|
|
async function buildExecutable() {
|
|
const outputDir = './dist/win-64';
|
|
const outputFile = 'pm-i18n.exe';
|
|
const entryPoint = './dist-node/main_node.cjs';
|
|
const nexeTemp = '../../nexe-24';
|
|
const nodeVersion = '24.5.0';
|
|
|
|
// Ensure output directory exists
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
console.log(`📁 Created output directory: ${outputDir}`);
|
|
}
|
|
|
|
// Ensure nexe temp directory exists
|
|
if (!fs.existsSync(nexeTemp)) {
|
|
fs.mkdirSync(nexeTemp, { recursive: true });
|
|
console.log(`📁 Created temp directory: ${nexeTemp}`);
|
|
}
|
|
|
|
// Check if entry point exists
|
|
if (!fs.existsSync(entryPoint)) {
|
|
console.log(`❌ Entry point ${entryPoint} not found. Please run 'npm run build' first.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const outputPath = path.join(outputDir, outputFile);
|
|
|
|
console.log('📦 Compiling with nexe...');
|
|
console.log(` Entry: ${entryPoint}`);
|
|
console.log(` Output: ${outputPath}`);
|
|
console.log(` Temp: ${nexeTemp}`);
|
|
console.log(` Target: windows-x64-${nodeVersion}`);
|
|
|
|
try {
|
|
await compile({
|
|
input: entryPoint,
|
|
output: outputPath,
|
|
target: 'windows-x64-22.12.0',
|
|
build: true,
|
|
temp: nexeTemp,
|
|
clean: false,
|
|
name: 'pm-i18n',
|
|
make: ['-j4'],
|
|
loglevel: 'verbose',
|
|
resources: []
|
|
});
|
|
|
|
console.log(`✅ Successfully compiled to ${outputPath}`);
|
|
|
|
// Show file size
|
|
if (fs.existsSync(outputPath)) {
|
|
const stats = fs.statSync(outputPath);
|
|
const fileSizeInMB = (stats.size / (1024 * 1024)).toFixed(2);
|
|
console.log(`📊 Executable size: ${fileSizeInMB} MB`);
|
|
}
|
|
|
|
console.log('🎉 Build complete!');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Compilation failed:', error.message);
|
|
if (error.stack) {
|
|
console.error(error.stack);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Run the build
|
|
buildExecutable().catch(console.error);
|