Files
thebet365/pack.mjs
Mars e52cac7444 feat(deploy): add Docker full-stack deployment and server pack scripts
Enable one-click production deploy via docker-compose.prod.yml, with deployment docs and zip packaging for Baota upload.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 16:24:06 +08:00

64 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 生成部署用 zip排除 node_modules、构建产物、.git、本地 .env 等。
* 用法: node pack.mjs
* 输出: release/thebet365-deploy-YYYYMMDD-HHmmss.zip
*/
import { execSync } from 'node:child_process';
import { mkdirSync, statSync } from 'node:fs';
import { basename, join } from 'node:path';
const root = process.cwd();
const projectName = basename(root);
const parent = join(root, '..');
const stamp = new Date()
.toISOString()
.replace(/[-:]/g, '')
.slice(0, 15)
.replace('T', '-');
const outDir = join(root, 'release');
const outFile = join(outDir, `thebet365-deploy-${stamp}.zip`);
/** 相对项目根目录的路径 */
const excludePaths = [
'node_modules',
'.git',
'.env',
'.env.local',
'.env.docker',
'apps/api/.env',
'apps/api/dist',
'apps/player/dist',
'apps/admin/dist',
'release',
];
mkdirSync(outDir, { recursive: true });
const excludeArgs = excludePaths
.map((p) => `--exclude=${projectName}/${p}`)
.join(' ');
const cmd = `tar -a -c -f "${outFile}" ${excludeArgs} -C "${parent}" "${projectName}"`;
console.log('Packing deployment archive...');
console.log('Excluding:');
for (const p of excludePaths) console.log(` - ${p}/`);
console.log('');
try {
execSync(cmd, { stdio: 'inherit' });
} catch {
console.error('\nPack failed. Ensure tar is available (Windows 10+ / Linux / macOS).');
process.exit(1);
}
const sizeMb = (statSync(outFile).size / (1024 * 1024)).toFixed(2);
console.log(`\nDone: ${outFile}`);
console.log(`Size: ${sizeMb} MB`);
console.log('\nUpload to server, extract under /www/wwwroot/thebet365, then:');
console.log(' cp .env.docker.example .env.docker');
console.log(' docker compose -f docker-compose.prod.yml --env-file .env.docker up -d --build');