mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
Some checks are pending
Document deploy / sync-images (push) Waiting to run
Document deploy / generate-timestamp (push) Blocked by required conditions
Document deploy / build-images (map[domain:https://fastgpt.cn suffix:cn]) (push) Blocked by required conditions
Document deploy / build-images (map[domain:https://fastgpt.io suffix:io]) (push) Blocked by required conditions
Document deploy / update-images (map[deployment:fastgpt-docs domain:https://fastgpt.cn kube_config:KUBE_CONFIG_CN suffix:cn]) (push) Blocked by required conditions
Document deploy / update-images (map[deployment:fastgpt-docs domain:https://fastgpt.io kube_config:KUBE_CONFIG_IO suffix:io]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / get-vars (push) Waiting to run
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:amd64 runs-on:ubuntu-24.04]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:arm64 runs-on:ubuntu-24.04-arm]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / release-fastgpt-images (push) Blocked by required conditions
* add manual create http toolset (#5743) * add manual create http toolset * optimize code * optimize * fix * fix * rename filename * feat: integrate ts-rest (#5741) * feat: integrate ts-rest * chore: classify core contract and pro contract * chore: update lockfile * chore: tweak dir structure * chore: tweak dir structure * update tsrest code (#5755) * doc * update tsrest code * fix http toolset (#5753) * fix http toolset * fix * perf: http toolset * fix: toolresponse result (#5760) * doc * fix: toolresponse result * fix: mongo watch * remove log * feat: integrated to minio (#5748) * feat: migrate to minio * feat: migrate apps' and dataset's avatar to minio * feat: migrate more avatars to minio * fix: lock file * feat: migrate copyright settings' logo to minio * feat: integrate minio * chore: improve code * chore: rename variables * refactor: s3 class * fix: s3 and mongo operations * chore: add session for avatar source * fix: init s3 buckets * fix: bugbot issues * expired time code * perf: avatar code * union type * export favouriteContract * empty bucket check --------- Co-authored-by: archer <545436317@qq.com> * refactor: zod schema to generate OpenAPI instead (#5771) * doc * fix: text split code (#5773) * fix: toolresponse result * remove log * stream remove * fix: text split code * fix: workflow (#5779) * fix: toolresponse result * remove log * fix: value check * fix: workflow * openapi doc * perf: bucket delete cron * doc * feat: apikey health * feat: export variables * api code move * perf: workflow performance (#5783) * perf: reactflow context * perf: workflow context split * perf: nodeList computed map * perf: nodes dependen * perf: workflow performance * workflow performance * removel og * lock * version * loop drag * reactflow size * reactflow size * fix: s3init (#5784) * doc * fix: s3init * perf: dynamic import * remove moongose dep * worker build * worker code * perf: worker build * fix: error throw * doc * doc * fix: build * fix: dockerfile * nextjs config * fix: worker * fix: build (#5791) * fix: build * vector cache code * fix: app info modal avatar upload method replace (#5787) * fix: app info modal avatar upload method replace * chore: replace all useSelectFile with useUploadAvatar * remove invalid code * add size * Update projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/nodes/render/RenderInput/templates/CommonInputForm.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update projects/app/src/pageComponents/app/detail/WorkflowComponents/context/workflowInitContext.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
153 lines
5.3 KiB
TypeScript
153 lines
5.3 KiB
TypeScript
import { build, BuildOptions, context } from 'esbuild';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
// 项目路径
|
|
const ROOT_DIR = path.resolve(__dirname, '../../..');
|
|
const WORKER_SOURCE_DIR = path.join(ROOT_DIR, 'packages/service/worker');
|
|
const WORKER_OUTPUT_DIR = path.join(__dirname, '../worker');
|
|
|
|
/**
|
|
* Worker 预编译脚本
|
|
* 用于在 Turbopack 开发环境下编译 Worker 文件
|
|
*/
|
|
async function buildWorkers(watch: boolean = false) {
|
|
console.log('🔨 开始编译 Worker 文件...\n');
|
|
|
|
// 确保输出目录存在
|
|
if (!fs.existsSync(WORKER_OUTPUT_DIR)) {
|
|
fs.mkdirSync(WORKER_OUTPUT_DIR, { recursive: true });
|
|
}
|
|
|
|
// 扫描 worker 目录
|
|
if (!fs.existsSync(WORKER_SOURCE_DIR)) {
|
|
console.error(`❌ Worker 源目录不存在: ${WORKER_SOURCE_DIR}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const workers = fs.readdirSync(WORKER_SOURCE_DIR).filter((item) => {
|
|
const fullPath = path.join(WORKER_SOURCE_DIR, item);
|
|
const isDir = fs.statSync(fullPath).isDirectory();
|
|
const hasIndexTs = fs.existsSync(path.join(fullPath, 'index.ts'));
|
|
return isDir && hasIndexTs;
|
|
});
|
|
|
|
if (workers.length === 0) {
|
|
return;
|
|
}
|
|
|
|
// esbuild 通用配置
|
|
const commonConfig: BuildOptions = {
|
|
bundle: true,
|
|
platform: 'node',
|
|
format: 'cjs',
|
|
target: 'node18',
|
|
sourcemap: false,
|
|
// Tree Shaking 和代码压缩优化
|
|
minify: true,
|
|
treeShaking: true,
|
|
keepNames: false,
|
|
// 移除调试代码
|
|
drop: process.env.NODE_ENV === 'production' ? ['console', 'debugger'] : []
|
|
};
|
|
|
|
if (watch) {
|
|
// Watch 模式:使用 esbuild context API
|
|
const contexts = await Promise.all(
|
|
workers.map(async (worker) => {
|
|
const entryPoint = path.join(WORKER_SOURCE_DIR, worker, 'index.ts');
|
|
const outfile = path.join(WORKER_OUTPUT_DIR, `${worker}.js`);
|
|
|
|
const config: BuildOptions = {
|
|
...commonConfig,
|
|
entryPoints: [entryPoint],
|
|
outfile,
|
|
logLevel: 'info'
|
|
};
|
|
|
|
try {
|
|
const ctx = await context(config);
|
|
await ctx.watch();
|
|
console.log(`👁️ ${worker} 正在监听中...`);
|
|
return ctx;
|
|
} catch (error: any) {
|
|
console.error(`❌ ${worker} Watch 启动失败:`, error.message);
|
|
return null;
|
|
}
|
|
})
|
|
);
|
|
|
|
// 过滤掉失败的 context
|
|
const validContexts = contexts.filter((ctx) => ctx !== null);
|
|
|
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
console.log(`✅ ${validContexts.length}/${workers.length} 个 Worker 正在监听中`);
|
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
console.log('\n💡 提示: 按 Ctrl+C 停止监听\n');
|
|
|
|
// 保持进程运行
|
|
process.on('SIGINT', async () => {
|
|
console.log('\n\n🛑 正在停止 Worker 监听...');
|
|
await Promise.all(validContexts.map((ctx) => ctx?.dispose()));
|
|
console.log('✅ 已停止');
|
|
process.exit(0);
|
|
});
|
|
} else {
|
|
// 单次编译模式
|
|
const buildPromises = workers.map(async (worker) => {
|
|
const entryPoint = path.join(WORKER_SOURCE_DIR, worker, 'index.ts');
|
|
const outfile = path.join(WORKER_OUTPUT_DIR, `${worker}.js`);
|
|
|
|
try {
|
|
const config: BuildOptions = {
|
|
...commonConfig,
|
|
entryPoints: [entryPoint],
|
|
outfile
|
|
};
|
|
|
|
await build(config);
|
|
console.log(`✅ ${worker} 编译成功 → ${path.relative(process.cwd(), outfile)}`);
|
|
return { success: true, worker };
|
|
} catch (error: any) {
|
|
console.error(`❌ ${worker} 编译失败:`, error.message);
|
|
return { success: false, worker, error };
|
|
}
|
|
});
|
|
|
|
// 等待所有编译完成
|
|
const results = await Promise.all(buildPromises);
|
|
|
|
// 统计结果
|
|
const successCount = results.filter((r) => r.success).length;
|
|
const failCount = results.filter((r) => !r.success).length;
|
|
|
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
console.log(`✅ 编译成功: ${successCount}/${workers.length}`);
|
|
if (failCount > 0) {
|
|
console.log(`❌ 编译失败: ${failCount}/${workers.length}`);
|
|
const failedWorkers = results.filter((r) => !r.success).map((r) => r.worker);
|
|
console.log(`失败的 Worker: ${failedWorkers.join(', ')}`);
|
|
// 非监听模式下,如果有失败的编译,退出并返回错误码
|
|
process.exit(1);
|
|
}
|
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
}
|
|
}
|
|
|
|
// 解析命令行参数
|
|
const args = process.argv.slice(2);
|
|
const watch = args.includes('--watch') || args.includes('-w');
|
|
|
|
// 显示启动信息
|
|
console.log('');
|
|
console.log('╔═══════════════════════════════════════╗');
|
|
console.log('║ FastGPT Worker 预编译工具 v1.0 ║');
|
|
console.log('╚═══════════════════════════════════════╝');
|
|
console.log('');
|
|
|
|
// 执行编译
|
|
buildWorkers(watch).catch((err) => {
|
|
console.error('\n❌ Worker 编译过程发生错误:', err);
|
|
process.exit(1);
|
|
});
|