45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const rootDir = path.resolve(__dirname, '..');
|
|
const configPath = path.join(rootDir, 'sea-config.json');
|
|
|
|
if (!fs.existsSync(configPath)) {
|
|
console.error(`Error: Configuration file not found at ${configPath}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
const outputPath = path.resolve(rootDir, config.output || 'dist/dashback');
|
|
const outputDir = path.dirname(outputPath);
|
|
|
|
// Ensure the target output directory exists
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
|
|
console.log('Building Node.js Single Executable Application (SEA)...');
|
|
console.log(`Node version: ${process.version}`);
|
|
console.log(`Config: ${path.relative(rootDir, configPath)}`);
|
|
console.log(`Target: ${path.relative(rootDir, outputPath)}`);
|
|
|
|
try {
|
|
execFileSync(process.execPath, ['--build-sea', configPath], {
|
|
cwd: rootDir,
|
|
stdio: 'inherit',
|
|
});
|
|
|
|
// Ensure executable permissions on POSIX systems
|
|
if (process.platform !== 'win32' && fs.existsSync(outputPath)) {
|
|
fs.chmodSync(outputPath, 0o755);
|
|
}
|
|
|
|
console.log(`\nSuccessfully built SEA executable: ${path.relative(rootDir, outputPath)}`);
|
|
} catch (err) {
|
|
console.error('\nFailed to build SEA:', err.message);
|
|
process.exit(1);
|
|
}
|