[英]Matching JavaScript files, but excluding mocha test files
I want to find all javascript files in dir.我想在目录中找到所有 javascript 文件。 Ie file must end with .js, but I want to exclude the ones that ends with test.js即文件必须以 .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',;
I have tried adding !(*test.js) but test files are still included, I assume because the match the first我试过添加 !(*test.js) 但测试文件仍然包含在内,我假设因为匹配第一个
What about :关于什么 :
glob('../**/*.js', {
ignore: '../**/*test.js',
}, function (err, files) {
console.log(files);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.