t-comm
Version:
专业、稳定、纯粹的工具库
46 lines (41 loc) • 1.73 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var child_process = require('child_process');
var husky_config = require('./config.js');
require('path');
function checkJSFiles(options) {
var _a, _b, _c;
if (options === void 0) {
options = {
whiteDir: husky_config.CHECK_JS_WHITE_DIR,
excludeReg: husky_config.SUB_PROJECT_CONFIG_JS_REG,
log: false
};
}
var whiteDir = (_a = options === null || options === void 0 ? void 0 : options.whiteDir) !== null && _a !== void 0 ? _a : husky_config.CHECK_JS_WHITE_DIR;
var excludeReg = (_b = options === null || options === void 0 ? void 0 : options.excludeReg) !== null && _b !== void 0 ? _b : husky_config.SUB_PROJECT_CONFIG_JS_REG;
var log = (_c = options === null || options === void 0 ? void 0 : options.log) !== null && _c !== void 0 ? _c : false;
var stagedFiles = child_process.execSync('git diff --cached --name-only --diff-filter=d', {
encoding: 'utf-8'
}).split('\n').filter(Boolean);
if (log) {
console.log('[stagedFiles]', stagedFiles);
}
var hasJsFiles = stagedFiles.filter(function (item) {
return whiteDir === null || whiteDir === void 0 ? void 0 : whiteDir.find(function (prefix) {
return item.startsWith(prefix);
});
}).filter(function (item) {
return !(excludeReg === null || excludeReg === void 0 ? void 0 : excludeReg.test(item));
}).some(function (file) {
return /\.(js|jsx)$/.test(file);
});
if (hasJsFiles) {
console.error('❌ 错误:禁止提交 .js 文件,请使用 .ts 或 .tsx!');
process.exit(1); // 阻止提交
}
if (log) {
console.log('✅ 允许提交(无 .js 文件)');
}
}
exports.checkJSFiles = checkJSFiles;