renovate/lib/workers/repository/extract/file-match.js
2018-07-22 09:37:10 +02:00

45 lines
1.1 KiB
JavaScript

const minimatch = require('minimatch');
module.exports = {
getIncludedFiles,
filterIgnoredFiles,
getMatchingFiles,
};
function getIncludedFiles(fileList, includePaths) {
if (!(includePaths && includePaths.length)) {
return fileList;
}
return fileList.filter(file =>
includePaths.some(
includePath => file === includePath || minimatch(file, includePath)
)
);
}
function filterIgnoredFiles(fileList, ignorePaths) {
if (!(ignorePaths && ignorePaths.length)) {
return fileList;
}
return fileList.filter(
file =>
!ignorePaths.some(
ignorePath => file.includes(ignorePath) || minimatch(file, ignorePath)
)
);
}
function getMatchingFiles(fileList, manager, fileMatch) {
let matchedFiles = [];
for (const match of fileMatch) {
logger.debug(`Using file match: ${match} for manager ${manager}`);
matchedFiles = matchedFiles.concat(
fileList.filter(file => file.match(new RegExp(match)))
);
}
// filter out duplicates
matchedFiles = matchedFiles.filter(
(item, pos) => matchedFiles.indexOf(item) === pos
);
return matchedFiles;
}