services.printer/script/git-safety-check.cjs
liufumingren c5bd7138e8 feat: 添加蓝绿部署发布脚本系统
- 蓝绿部署 (v1/v2 双实例, 端口 4051/4052)

- 部署预检、远程部署、回滚

- 版本追踪、Git 安全 Hook

- Nginx upstream 自动切换
2026-07-25 01:31:13 +08:00

45 lines
1.2 KiB
JavaScript
Raw Permalink 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.

'use strict';
const path = require('node:path');
const { runCommandSafe } = require('./deploy-lib.cjs');
const BLOCKED_PATH_PATTERNS = [
/^config\/config\.local\.js$/,
/^config\/deploy\.config\.local\.cjs$/,
/^tmp\/(?!deploy\/)(?!docs\/).+/,
/^logs\//,
/^run\//,
/\.pem$/i,
/\.key$/i,
/^\.env(?:\..+)?$/,
];
function normalizePath(filePath) {
return filePath.replace(/\\/g, '/');
}
function listStagedFiles() {
const output = runCommandSafe('git', [ 'diff', '--cached', '--name-only', '--diff-filter=ACMR' ]);
if (!output) return [];
return output.split(/\r?\n/).map(item => normalizePath(item.trim())).filter(Boolean);
}
function main() {
const stagedFiles = listStagedFiles();
const blocked = stagedFiles.filter(filePath => BLOCKED_PATH_PATTERNS.some(pattern => pattern.test(filePath)));
if (blocked.length === 0) {
console.log('git safety check passed');
return;
}
console.error('以下文件禁止提交到 git,请先取消暂存:');
for (const filePath of blocked) {
console.error(`- ${filePath}`);
}
console.error('建议使用 git restore --staged <file> 取消暂存,再继续提交。');
process.exit(1);
}
main();