【问题标题】:Matching JavaScript files, but excluding mocha test files匹配 JavaScript 文件,但不包括 mocha 测试文件
【发布时间】:2018-10-18 12:07:06
【问题描述】:

我想在 dir 中查找所有 javascript 文件。即文件必须以 .js 结尾,但我想排除以 test.js 结尾的文件

const glob = require('glob');

function globbing (pattern) {
  return new Promise(function (resolve, reject) {
    glob(pattern, function (err, files) {
      if (err) {
        reject(err);
      } else {
        resolve(files);
      }
    });
  });
}


(async () => {
  const jsFiles = await globbing('../**/*.js');
  console.log(jsFiles);
})()

outputs:
'../component/admin/userDashboard.js',
'../component/admin/userDashboard.test.js',
'../component/admin/waitingPage.js',
'../component/app.js',
'../component/app.test.js',;

我已尝试添加 !(*test.js) 但仍包含测试文件,我认为是因为匹配第一个

【问题讨论】:

标签: javascript node.js pattern-matching


【解决方案1】:

怎么样:

glob('../**/*.js', {
  ignore: '../**/*test.js', 
}, function (err, files) {
  console.log(files);
});

【讨论】:

  • 非常感谢,正在尝试一次性完成。但是传递额外的选项是我没有想到的一个很好的选择。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-24
  • 2021-08-21
  • 1970-01-01
  • 2014-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多