diff --git a/dist/cli.js b/dist/cli.js index 93e4074..aa89d08 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -583,6 +583,7 @@ function main() { console.error(`\u274C \u4E0D\u652F\u6301\u7684\u6784\u5EFA\u7C7B\u578B: ${options.buildType}`); process.exit(1); } + copyTemplateFiles(path3.join(pwd2, "dist")); } function packageBackend(projectDir, options) { const imageBase = path3.basename(projectDir); @@ -667,4 +668,26 @@ function packageInit(projectDir, options) { fs3.rmSync(path3.join(pwd, ".dockerignore"), { force: true }); } } +function copyTemplateFiles(dist) { + const templateDir = path3.join(__dirname, "../template"); + function copyDir(srcDir, destDir) { + if (!fs3.existsSync(destDir)) { + fs3.mkdirSync(destDir, { recursive: true }); + } + const entries = fs3.readdirSync(srcDir, { withFileTypes: true }); + for (const entry of entries) { + const srcPath = path3.join(srcDir, entry.name); + const destPath = path3.join(destDir, entry.name); + if (entry.isDirectory()) { + copyDir(srcPath, destPath); + } else { + if (fs3.existsSync(destPath)) { + continue; + } + fs3.copyFileSync(srcPath, destPath); + } + } + } + copyDir(templateDir, dist); +} main(); diff --git a/src/cli.ts b/src/cli.ts index d0cfd6d..6c0a55b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -271,6 +271,8 @@ function main(): void { console.error(`❌ 不支持的构建类型: ${options.buildType}`); process.exit(1); } + + copyTemplateFiles(path.join(pwd, "dist")); } function packageBackend(projectDir: string, options: BuildOptions): void { @@ -411,5 +413,33 @@ function packageInit(projectDir: string, options: BuildOptions): void { } } +function copyTemplateFiles( + dist: string, +) { + const templateDir = path.join(__dirname, "../template"); + // 递归复制 template 目录下的所有文件到 dist 目录 + function copyDir(srcDir: string, destDir: string) { + if (!fs.existsSync(destDir)) { + fs.mkdirSync(destDir, { recursive: true }); + } + const entries = fs.readdirSync(srcDir, { withFileTypes: true }); + for (const entry of entries) { + const srcPath = path.join(srcDir, entry.name); + const destPath = path.join(destDir, entry.name); + if (entry.isDirectory()) { + copyDir(srcPath, destPath); + } else { + // 如果文件存在就跳过 + if (fs.existsSync(destPath)) { + continue; + } + fs.copyFileSync(srcPath, destPath); + } + } + } + + copyDir(templateDir, dist); +} + // 执行主函数 main(); diff --git a/template/docker-compose.yaml b/template/docker-compose.yaml new file mode 100644 index 0000000..d35a79f --- /dev/null +++ b/template/docker-compose.yaml @@ -0,0 +1,68 @@ +version: '3.8' + +services: + # ======================= + # MySQL 数据库 + # ======================= + mysql: + image: mysql:8.2 + container_name: mysql_container + restart: always + environment: + MYSQL_ROOT_PASSWORD: your_root_password + MYSQL_DATABASE: your_database + MYSQL_USER: your_user + MYSQL_PASSWORD: your_password + network_mode: host + volumes: + - mysql_data:/var/lib/mysql + + # ======================= + # Redis 缓存 + # ======================= + redis: + image: redis:7.2 + container_name: redis_container + restart: always + network_mode: host + volumes: + - redis_data:/data + + # ======================= + # MinIO 对象存储 + # ======================= + minio: + image: minio/minio:latest + container_name: minio_container + restart: always + environment: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin + command: server /data --console-address ":9001" + network_mode: host + volumes: + - minio_data:/data + + # ======================= + # Nginx 网关 + # ======================= + nginx: + image: nginx:latest + container_name: nginx_container + restart: always + network_mode: host + volumes: + - ./conf.d:/etc/nginx/conf.d:ro + - ./html:/usr/share/nginx/html:ro + depends_on: + - mysql + - redis + - minio + +# ======================= +# 数据卷 +# ======================= +volumes: + mysql_data: + redis_data: + minio_data: diff --git a/template/nginx/conf.d/config.conf b/template/nginx/conf.d/config.conf new file mode 100644 index 0000000..8986a29 --- /dev/null +++ b/template/nginx/conf.d/config.conf @@ -0,0 +1,64 @@ + +# WebSocket support +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + + +server { + listen 3021; + server_name 192.168.34.21; + index index.html index.htm index.jsp; + root /usr/share/nginx/html/haina-cn/web; + + gzip on; + gzip_min_length 1k; + gzip_comp_level 2; + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php; + gzip_vary on; + gzip_disable "MSIE [1-6]\."; + + + location ~ ^/oak-api/.*$ { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + #try_files $uri /index.html; + proxy_set_header X-Real-IP $remote_addr; + rewrite /oak-api/(.*) /$1 break; + proxy_read_timeout 1500; + proxy_connect_timeout 1500; + proxy_send_timeout 1500; + send_timeout 1500; + client_max_body_size 10m; + proxy_pass http://192.168.34.21:3011; + } + + location ~ ^/oak-skt/.*$ { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + #try_files $uri /index.html; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header X-Real-IP $remote_addr; + rewrite /oak-skt/(.*) /$1 break; + proxy_read_timeout 1500; + proxy_connect_timeout 1500; + proxy_send_timeout 1500; + send_timeout 1500; + client_max_body_size 10m; + proxy_pass http://192.168.34.21:8080; + } + + location / { + try_files $uri $uri/ /index.html; + } + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } +} \ No newline at end of file