You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
const bytenode = require('bytenode');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { execSync } = require('child_process');
|
|
|
|
const distDir = path.join(__dirname, '../dist');
|
|
const srcDir = path.join(__dirname, '../src');
|
|
|
|
// 1. 创建干净的发布目录
|
|
if (fs.existsSync(distDir)) {
|
|
fs.rmSync(distDir, { recursive: true });
|
|
}
|
|
fs.mkdirSync(distDir);
|
|
|
|
console.log('--- 开始字节码编译保护 ---'.blue);
|
|
|
|
/**
|
|
* 核心逻辑:将所有业务 JS 编译为 V8 字节码 (.jsc)
|
|
*/
|
|
const filesToProtect = ['index.js', 'config.js', 'licenseManager.js'];
|
|
|
|
filesToProtect.forEach(file => {
|
|
const srcPath = path.join(srcDir, file);
|
|
const destPath = path.join(distDir, file.replace('.js', '.jsc'));
|
|
|
|
// 编译为字节码
|
|
bytenode.compileFile({
|
|
filename: srcPath,
|
|
output: destPath
|
|
});
|
|
|
|
console.log(`[已加密]: ${file} -> ${path.basename(destPath)}`.green);
|
|
});
|
|
|
|
// 2. 生成入口引导文件 (main.js)
|
|
// 这个文件将作为打包后的入口,它不包含任何核心业务逻辑,只负责加载加密后的字节码
|
|
const loaderContent = `
|
|
require('bytenode');
|
|
// 加载加密后的入口
|
|
require('./index.jsc');
|
|
`;
|
|
fs.writeFileSync(path.join(distDir, 'main.js'), loaderContent);
|
|
|
|
// 3. 拷贝其他必要资源 (如 recordings 文件夹占位)
|
|
console.log('[准备]: 正在生成打包配置...'.cyan);
|
|
|
|
// 4. 调用 pkg 进行二进制打包 (支持 Windows 和 Linux)
|
|
console.log('--- 开始二进制打包 (生成 EXE/Binary) ---'.blue);
|
|
|
|
try {
|
|
// 我们打包生成 Windows exe 和 Linux 二进制文件
|
|
// 注意:mediasoup 的 worker 进程是 C++ 编写的,打包时需确保它在可执行文件同级目录
|
|
execSync('npx pkg dist/main.js --targets node18-win-x64,node18-linux-x64 --out-path build');
|
|
console.log('\n[成功] 打包完成!请查看 build 目录。'.green.bold);
|
|
console.log('注意:运行程序时,请确保服务器上已安装 FFmpeg。'.yellow);
|
|
} catch (error) {
|
|
console.error('[失败] 打包过程中出现错误:', error.message);
|
|
}
|
|
|