filecat
Version:
FileCat Server Manager
160 lines (147 loc) • 8.92 kB
JavaScript
const {Listr} = require("listr2");
const webpack = require('webpack');
const os = require("os");
const config = require('./config/webpack.web.config.js');
const args = process.argv.slice(2)??[]; // slice to remove the first two default values
let serverConfig ;
const is_exe = args[0]==="exe"
const is_npm = args[0]==="npm"
if (args.length ===0 || is_npm) {
serverConfig = require('./config/webpack.npm.config.js');
console.log('npm打包')
} else if (is_exe) {
console.log('二进制打包')
serverConfig = require('./config/webpack.exe.config.js');
} else {
console.error('无法识别打包环境')
}
const {copyFileSync} = require("fs");
const fs = require("fs");
const path = require("path");
const {rimraf} = require("rimraf");
const fse = require("fs-extra");
const {copy_wintun_dll} = require("./config/common-bin.config");
const {execSync} = require("child_process");
// const test_p = path.join(process.cwd(), "node_modules","node-process-watcher");
// const test_p2 = path.join(process.cwd(), "node_modules","better-sqlite3");
// console.log(`存在node-process-watcher ${fs.existsSync(test_p)}`);
// console.log(`存在better-sqlite3 ${fs.existsSync(test_p2)}`);
function ensure_copyFileSync(sourcePath, destPath) {
fse.ensureDirSync(path.dirname(destPath))
copyFileSync(sourcePath, destPath);
}
function get_platform () {
const platform = os.platform();
if(platform === "win32") {
return 'win'
} else if (platform === "linux") {
return 'linux'
} else if (platform === "darwin") {
return 'mac'
}
}
function get_exe() {
const arch = os.platform()
if(arch === "win32") {
return '7za.exe'
} else {
return '7za'
}
}
const tasksLister = new Listr(
[
{
title:"清理build目录执行tsc",
task:async ()=>{
fse.removeSync(path.join(__dirname, "..", "build"));
execSync("npx tsc")
}
},
{
title:"子线程构建",
task:async ()=>{
return Promise.all([new Promise((res, rej) => {
const config = {...serverConfig};
config['entry'] = path.join(__dirname, "..", "build", "server", "main","threads","filecat","threads.work.filecat.js")
config['output'] = {...config['output']}
config['output']['filename'] = 'threads.work.filecat.js'
// 第一个
webpack(config, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(err || stats.toString());
rej(false);
return;
}
res(true);
});
})])
}
},
{
title: "构建服务端",
task: async () => {
return new Promise((res, rej) => {
webpack(serverConfig, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(err || stats.toString());
rej(false);
return;
}
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "bin", "win-process.node"), path.join(__dirname, "..", "build", "win-process.node"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "bin", "linux-process.node"), path.join(__dirname, "..", "build", "linux-process.node"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "tun","ts","linux","linuxtun.node"), path.join(__dirname, "..", "build", "linuxtun.node"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "tun","ts","win","wintun.node"), path.join(__dirname, "..", "build", "wintun.node"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "wintun-amd64.dll"), path.join(__dirname, "..", "build", "wintun-amd64.dll"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "wintun-arm.dll"), path.join(__dirname, "..", "build", "wintun-arm.dll"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "wintun-arm64.dll"), path.join(__dirname, "..", "build", "wintun-arm64.dll"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "wintun-x86.dll"), path.join(__dirname, "..", "build", "wintun-x86.dll"))
// copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "bin", "ffmpeg"), path.join(__dirname, "..", "build", "ffmpeg"))
// copyFileSync(path.resolve("build/server/main/domain/file/file.worker.js"), path.join(__dirname, "..", "build", "file.worker.js"))
// 复制 子进程监控脚本
// ensure_copyFileSync(path.resolve("src/main/watch.js"), path.join(__dirname, "..", "build", "watch.js"))
if(is_exe) {
copy_wintun_dll()
fs.copyFileSync(path.resolve('package.json'), path.resolve('build','package.json'));
fse.copySync(path.resolve('node_modules','7zip-min'), path.resolve('build','node_modules','7zip-min'));
fse.copySync(path.resolve('node_modules','7zip-bin','package.json'), path.resolve('build','node_modules','7zip-bin','package.json'));
fse.copySync(path.resolve('node_modules','7zip-bin','index.js'), path.resolve('build','node_modules','7zip-bin','index.js'));
fse.copySync(path.resolve('node_modules','7zip-bin',get_platform(),os.arch(),get_exe()), path.resolve('build','node_modules','7zip-bin',get_platform(),os.arch(),get_exe()));
}
ensure_copyFileSync(path.resolve("node_modules/node-unrar-js/esm/js/unrar.wasm"), path.join(__dirname, "..", "build", "unrar.wasm"))
ensure_copyFileSync(path.resolve("node_modules/jieba-wasm/pkg/nodejs/jieba_rs_wasm_bg.wasm"), path.join(__dirname, "..", "build", "jieba_rs_wasm_bg.wasm"))
rimraf.sync(path.join(__dirname,"..","build","server"));
rimraf.sync(path.join(__dirname,"..","build","build")); //better-sqlite3 莫名其妙的
res(true);
});
})
},
},
{
title: "构建web",
task: async () => {
return new Promise((res, rej) => {
webpack(config, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(err || stats.toString());
rej(false);
return;
}
fse.copySync(path.join(__dirname, "..", "src", "web", "meta", 'resources',"assets","excalidraw-assets"),path.join(__dirname, "..", "build", "dist","excalidraw-assets"));
copyFileSync(path.join(__dirname, "..", "src", "web", "project", 'component',"file","component","image","js","filerobot-image-editor.min.js"), path.join(__dirname, "..", "build", "dist","filerobot-image-editor.min.js"));
copyFileSync(path.join(__dirname, "..", "src", "web", "project", "component","proxy","rdp","client","js","rle.js"), path.join(__dirname, "..", "build", "dist","rle.js"));
copyFileSync(path.join(__dirname, "..", "src", "web", "meta","resources","img","favicon-16x16.png"), path.join(__dirname, "..", "build", "dist","favicon-16x16.png"));
copyFileSync(path.join(__dirname, "..", "src", "web", "meta", "resources","img","favicon-32x32.png"), path.join(__dirname, "..", "build", "dist","favicon-32x32.png"));
copyFileSync(path.join(__dirname, "..", "src", "web", "meta", "resources","css","themes","dark.css"), path.join(__dirname, "..", "build", "dist","dark.css"));
// copyFileSync(path.join(__dirname, "..", "src", "web", "meta", "component","resources","img","svg.png"), path.join(__dirname, "..", "build", "dist","svg.png"))
res(true);
});
})
},
// options: {persistentOutput: true},
},
],
{
exitOnError: true,
}
);
tasksLister.run();