From 77673f2a6ee2fcb5dfd798d7200d08be91e92aad Mon Sep 17 00:00:00 2001 From: Abner <22141172+Silentely@users.noreply.github.com> Date: Sat, 11 Apr 2026 23:12:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(hooks):=20=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E6=8F=90=E4=BA=A4=E4=B8=8E=E6=8E=A8=E9=80=81=20legacy?= =?UTF-8?q?=20complete=20=E9=A1=B5=E9=9D=A2=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/pre-commit-check.js | 29 ++++++++++++++++++++++++++++- scripts/pre-push-check.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) 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) {