删除不再使用的 Docker 相关文件,包括 Dockerfile、docker-compose.yml 和 .dockerignore,简化项目结构以提升可维护性。同时,更新 DEPLOYMENT.md 文档,调整 Next.js 配置说明,确保与新部署方式一致。
This commit is contained in:
51
scripts/clean-standalone.js
Normal file
51
scripts/clean-standalone.js
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* 构建前清理 .next/standalone,避免 Next.js build 时 EBUSY(目录被占用)
|
||||
* 若曾运行 pnpm start,请先 Ctrl+C 停掉再 build
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const rootDir = path.join(__dirname, '..');
|
||||
const standaloneDir = path.join(rootDir, '.next', 'standalone');
|
||||
|
||||
const RETRIES = 5;
|
||||
const DELAY_MS = 2000;
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((r) => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
if (!fs.existsSync(standaloneDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let attempt = 1; attempt <= RETRIES; attempt++) {
|
||||
try {
|
||||
fs.rmSync(standaloneDir, { recursive: true, force: true, maxRetries: 3 });
|
||||
console.log('[clean-standalone] 已删除 .next/standalone');
|
||||
return;
|
||||
} catch (e) {
|
||||
if (e.code === 'EBUSY' || e.code === 'EPERM' || e.code === 'ENOTEMPTY') {
|
||||
if (attempt < RETRIES) {
|
||||
console.warn('[clean-standalone] 目录被占用,%ds 后重试 (%d/%d)...', DELAY_MS / 1000, attempt, RETRIES);
|
||||
await sleep(DELAY_MS);
|
||||
} else {
|
||||
console.error('[clean-standalone] 无法删除 .next/standalone:目录被占用');
|
||||
console.error(' 请先关闭:pnpm start、或占用该目录的其它程序(如资源管理器、杀毒)');
|
||||
console.error(' 然后重新执行:pnpm build');
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user