'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var nodejs_child_process = require('../nodejs/child_process.js');
var husky_config = require('./config.js');
require('../nodejs/path.js');

function checkJSFiles() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
    whiteDir: husky_config.CHECK_JS_WHITE_DIR,
    excludeReg: husky_config.SUB_PROJECT_CONFIG_JS_REG,
    log: false
  };
  var _a, _b, _c;
  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 = nodejs_child_process.getChildProcess().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;
