Add fileUtils recurseFiles and shouldIgnoreFile tests

This commit is contained in:
advplyr
2025-02-23 16:53:11 -06:00
parent 13c20e0cdd
commit 20f812403f
2 changed files with 138 additions and 13 deletions

View File

@ -138,14 +138,6 @@ module.exports.readTextFile = readTextFile
* @returns {string}
*/
module.exports.shouldIgnoreFile = (path) => {
var extensionIgnores = ['.part', '.tmp', '.crdownload', '.download', '.bak', '.old', '.temp', '.tempfile', '.tempfile~']
// Check extension
if (extensionIgnores.includes(Path.extname(path).toLowerCase())) {
// Return the extension that is ignored
return `${Path.extname(path)} file`
}
// Check if directory or file name starts with "."
if (Path.basename(path).startsWith('.')) {
return 'dotfile'
@ -155,16 +147,23 @@ module.exports.shouldIgnoreFile = (path) => {
}
// If these strings exist anywhere in the filename or directory name, ignore. Vendor specific hidden directories
var includeAnywhereIgnore = ['@eaDir']
var filteredInclude = includeAnywhereIgnore.filter((str) => path.includes(str))
const includeAnywhereIgnore = ['@eaDir']
const filteredInclude = includeAnywhereIgnore.filter((str) => path.includes(str))
if (filteredInclude.length) {
return `${filteredInclude[0]} directory`
}
const extensionIgnores = ['.part', '.tmp', '.crdownload', '.download', '.bak', '.old', '.temp', '.tempfile', '.tempfile~']
// Check extension
if (extensionIgnores.includes(Path.extname(path).toLowerCase())) {
// Return the extension that is ignored
return `${Path.extname(path)} file`
}
// Should not ignore this file or directory
return null
}
module.exports.shouldIgnoreFile = this.shouldIgnoreFile
/**
* @typedef FilePathItem
@ -182,7 +181,7 @@ module.exports.shouldIgnoreFile = this.shouldIgnoreFile
* @param {string} [relPathToReplace]
* @returns {FilePathItem[]}
*/
async function recurseFiles(path, relPathToReplace = null) {
module.exports.recurseFiles = async (path, relPathToReplace = null) => {
path = filePathToPOSIX(path)
if (!path.endsWith('/')) path = path + '/'
@ -266,7 +265,6 @@ async function recurseFiles(path, relPathToReplace = null) {
return list
}
module.exports.recurseFiles = recurseFiles
/**
*