"use strict";var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");_Object$defineProperty(exports, "__esModule", { value: true });exports.default = readdir;var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));

/**
 * 递归扫描所有文件
 * @param {String} root 要扫描的根目录
 * @param {Functioin} filter 要过滤的文件， 默认过滤.xxx
 * @param {Array} files 扫描出来的的文件集合
 * @param {String} prefix 用于递归时传递内层的dir
 */
function readdir(root, filter = noDotFiles, files = [], prefix = '') {
  const dir = _path.default.posix.join(root, prefix);
  if (!_fs.default.existsSync(dir)) return files;
  if (_fs.default.statSync(dir).isDirectory()) {
    _fs.default.readdirSync(dir).
    filter(function (name, index) {
      return filter(name, index, dir);
    }).
    forEach(function (name) {
      readdir(root, filter, files, _path.default.posix.join(prefix, name));
    });
  } else {
    files.push(prefix);
  }

  return files;
}

function noDotFiles(x) {
  return x[0] !== '.';
}