diff --git a/scripts/pre-commit-check.js b/scripts/pre-commit-check.js index c34f0b7..78d6aa3 100644 --- a/scripts/pre-commit-check.js +++ b/scripts/pre-commit-check.js @@ -5,7 +5,8 @@ * 1) 仅处理 staged 文件,安全格式化(LF、行尾空白、文件尾换行); * 2) 检查 staged JS 语法; * 3) 检查 staged JSON 语法; - * 4) 拦截代码文件中的智能引号,避免引号边界问题。 + * 4) 拦截代码文件中的智能引号,避免引号边界问题; + * 5) 保护 legacy 完整版页面,禁止提交其变更。 */ const fs = require('fs'); @@ -34,6 +35,10 @@ const TEXT_EXTENSIONS = new Set([ const JS_EXTENSIONS = new Set(['.js', '.mjs', '.cjs']); const SMART_QUOTES_RE = /[\u2018\u2019\u201C\u201D]/u; +const PROTECTED_FILES = [ + 'src/giffgaff/giffgaff_complete_esim.html', + 'src/simyo/simyo_complete_esim.html' +]; function git(args, options = {}) { return execFileSync('git', args, { @@ -54,6 +59,18 @@ function getStagedFiles() { return output.split('\0').filter(Boolean); } +function getTouchedProtectedFiles() { + const output = git([ + 'diff', + '--cached', + '--name-only', + '-z', + '--', + ...PROTECTED_FILES + ]); + return output.split('\0').filter(Boolean); +} + function shouldFormat(relPath) { const ext = path.extname(relPath).toLowerCase(); if (TEXT_EXTENSIONS.has(ext)) { @@ -164,6 +181,16 @@ function runChecks(stagedFiles) { } function main() { + const touchedProtectedFiles = getTouchedProtectedFiles(); + if (touchedProtectedFiles.length > 0) { + console.error('\n❌ pre-commit 检查失败:'); + for (const relPath of touchedProtectedFiles) { + console.error(` - ${relPath}: 该文件受保护,禁止提交改动。`); + } + console.error(' - 如确需调整,请改为维护对应 modular 版本文件。'); + process.exit(1); + } + const stagedFiles = getStagedFiles(); if (stagedFiles.length === 0) { process.exit(0); diff --git a/scripts/pre-push-check.js b/scripts/pre-push-check.js index f9f23c9..7c39742 100644 --- a/scripts/pre-push-check.js +++ b/scripts/pre-push-check.js @@ -11,6 +11,10 @@ const { execFileSync, spawnSync } = require('child_process'); const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'; const RELATED_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.json']); +const PROTECTED_FILES = [ + 'src/giffgaff/giffgaff_complete_esim.html', + 'src/simyo/simyo_complete_esim.html' +]; function runGit(args) { return execFileSync('git', args, { @@ -77,6 +81,25 @@ function getRelatedFiles() { }); } +function getTouchedProtectedFiles() { + const range = getDiffRange(); + if (!range) { + return []; + } + + const output = runGit([ + 'diff', + '--name-only', + '--diff-filter=ACMR', + '-z', + range, + '--', + ...PROTECTED_FILES + ]); + + return output.split('\0').filter(Boolean); +} + function buildSteps(mode) { const steps = [ { @@ -132,6 +155,17 @@ function runStep(step) { function main() { const mode = resolveMode(); console.log(`\n🧭 pre-push 模式: ${mode}`); + + const touchedProtectedFiles = getTouchedProtectedFiles(); + if (touchedProtectedFiles.length > 0) { + console.error('\n❌ pre-push 检查失败:'); + for (const relPath of touchedProtectedFiles) { + console.error(` - ${relPath}: 该文件受保护,禁止推送包含其改动的提交。`); + } + console.error(' - 如确需调整,请改为维护对应 modular 版本文件。'); + process.exit(1); + } + const steps = buildSteps(mode); for (const step of steps) {