@node-cli/search 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +6 -6
- package/dist/core.js.map +1 -1
- package/dist/gitIgnoreHandler.js +2 -2
- package/dist/gitIgnoreHandler.js.map +1 -1
- package/dist/minifiers.js +2 -2
- package/dist/minifiers.js.map +1 -1
- package/dist/parse.js +3 -3
- package/dist/parse.js.map +1 -1
- package/dist/search.js +2 -2
- package/dist/search.js.map +1 -1
- package/dist/utilities.js +2 -2
- package/dist/utilities.js.map +1 -1
- package/package.json +12 -8
package/dist/core.js
CHANGED
|
@@ -193,13 +193,13 @@ export class Search {
|
|
|
193
193
|
async readFileContent(filePath) {
|
|
194
194
|
try {
|
|
195
195
|
// Check if it's a known binary extension
|
|
196
|
-
/*
|
|
196
|
+
/* v8 ignore next */ if (isBinaryFileExtension(filePath)) {
|
|
197
197
|
return null;
|
|
198
198
|
}
|
|
199
199
|
const content = await readFileAsync(filePath, "utf8");
|
|
200
200
|
return this.minifyForLLM ? await minifyFileContent(filePath, content) : content;
|
|
201
201
|
} catch (_error) {
|
|
202
|
-
/*
|
|
202
|
+
/* v8 ignore next */ return null;
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
async printFilesContent(returnResults) {
|
|
@@ -286,7 +286,7 @@ export class Search {
|
|
|
286
286
|
].includes(this.printMode)) {
|
|
287
287
|
return await this.printFilesContent(returnResults);
|
|
288
288
|
}
|
|
289
|
-
/*
|
|
289
|
+
/* v8 ignore next */ if (!this.boring) {
|
|
290
290
|
logger.log();
|
|
291
291
|
}
|
|
292
292
|
for (const node of this.nodesList){
|
|
@@ -298,7 +298,7 @@ export class Search {
|
|
|
298
298
|
owner: "",
|
|
299
299
|
size: ""
|
|
300
300
|
}, name, separator = "";
|
|
301
|
-
/*
|
|
301
|
+
/* v8 ignore next */ if (this.displayLongListing) {
|
|
302
302
|
list = await formatLongListings(node.stat, node.type);
|
|
303
303
|
separator = "\t";
|
|
304
304
|
}
|
|
@@ -314,14 +314,14 @@ export class Search {
|
|
|
314
314
|
}
|
|
315
315
|
if (this.grep && node.type === STR_TYPE_FILE) {
|
|
316
316
|
const { totalMatchingLines, results } = await runGrepOnNode(node.name, this.grep);
|
|
317
|
-
/*
|
|
317
|
+
/* v8 ignore next */ if (totalMatchingLines) {
|
|
318
318
|
this.totalFileFound++;
|
|
319
319
|
const occurrences = plur("occurrence", totalMatchingLines);
|
|
320
320
|
logger.log(` %s${separator}%s${separator}%s${separator}%s${separator}%s`, list.mode.trim(), list.owner.trim(), list.size.trim(), list.mdate, name, `(${kleur.white(totalMatchingLines)} ${occurrences})`);
|
|
321
321
|
logger.log(`${results.join("\n")}\n`);
|
|
322
322
|
}
|
|
323
323
|
} else {
|
|
324
|
-
/*
|
|
324
|
+
/* v8 ignore next */ if (!this.grep) {
|
|
325
325
|
logger.log(` %s${separator}%s${separator}%s${separator}%s${separator}%s`, list.mode.trim(), list.owner.trim(), list.size.trim(), list.mdate, name);
|
|
326
326
|
if (node.command) {
|
|
327
327
|
await runCommandOnNode(node.name, node.command);
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core.ts"],"sourcesContent":["import { basename, extname, join, relative } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { Logger } from \"@node-cli/logger\";\nimport { Performance } from \"@node-cli/perf\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport plur from \"plur\";\n\nimport { GitIgnoreHandler } from \"./gitIgnoreHandler.js\";\nimport { minifyCss, minifyFileContent, minifyJs } from \"./minifiers.js\";\nimport {\n\tSTR_TYPE_BOTH,\n\tSTR_TYPE_DIRECTORY,\n\tSTR_TYPE_FILE,\n\tcheckPattern,\n\tformatLongListings,\n\tgetFileExtension,\n\tisBinaryFileExtension,\n\tprintStatistics,\n\trunCommandOnNode,\n\trunGrepOnNode,\n} from \"./utilities.js\";\n\nconst lstatAsync = promisify(fs.lstat);\nconst readdirAsync = promisify(fs.readdir);\nconst readFileAsync = promisify(fs.readFile);\nconst perf = new Performance();\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\nconst loggerInMemory = new Logger({\n\tinMemory: true,\n});\n\nexport class Search {\n\tboring?: boolean;\n\tcommand?: string;\n\tdisplayHiddenFilesAndFolders?: boolean;\n\tdisplayLongListing?: boolean;\n\tdisplayStats?: boolean;\n\tgrep?: RegExp;\n\tnodesList?: any[];\n\tpath?: string;\n\trePattern?: RegExp;\n\ttotalDirFound?: number;\n\ttotalDirScanned?: number;\n\ttotalFileFound?: number;\n\ttotalFileScanned?: number;\n\ttype?: string;\n\tignoreExtensions?: string[];\n\tignoreFiles?: string[];\n\tignoreFolders?: string[];\n\tprintMode?: string;\n\tgitIgnoreHandler: GitIgnoreHandler;\n\tignoreGitIgnore?: boolean;\n\tminifyForLLM?: boolean;\n\n\tconstructor({\n\t\tboring,\n\t\tcommand,\n\t\tdot,\n\t\tgrep,\n\t\tignoreCase,\n\t\tshort,\n\t\tpath,\n\t\tpattern,\n\t\tstats,\n\t\ttype,\n\t\tignoreExtension,\n\t\tignoreFile,\n\t\tignoreFolder,\n\t\tprintMode,\n\t\tignoreGitIgnore,\n\t\tminifyForLLM,\n\t}: {\n\t\tboring?: boolean;\n\t\tcommand?: string;\n\t\tdot?: boolean;\n\t\tgrep?: string | RegExp;\n\t\tignoreCase?: boolean;\n\t\tshort?: boolean;\n\t\tpath?: string;\n\t\tpattern?: string;\n\t\tstats?: boolean;\n\t\ttype?: string;\n\t\tignoreExtension?: string[];\n\t\tignoreFile?: string[];\n\t\tignoreFolder?: string[];\n\t\tprintMode?: string;\n\t\tignoreGitIgnore?: boolean;\n\t\tminifyForLLM?: boolean;\n\t}) {\n\t\tthis.path = path;\n\t\tthis.rePattern = pattern\n\t\t\t? new RegExp(pattern, ignoreCase ? \"i\" : \"\")\n\t\t\t: undefined;\n\t\tthis.type = type || STR_TYPE_BOTH;\n\t\tthis.boring = boring;\n\t\tkleur.enabled = !boring;\n\t\tthis.displayLongListing = !short;\n\t\tthis.displayStats = stats;\n\t\tthis.displayHiddenFilesAndFolders = dot;\n\t\tthis.nodesList = [];\n\t\tthis.totalDirScanned = 0;\n\t\tthis.totalFileScanned = 0;\n\t\tthis.totalDirFound = 0;\n\t\tthis.totalFileFound = 0;\n\t\tthis.command = command ? command.trim() : undefined;\n\t\tthis.ignoreExtensions =\n\t\t\t(ignoreExtension && ignoreExtension.map((ext) => ext.toLowerCase())) ||\n\t\t\t[];\n\t\tthis.ignoreFiles = ignoreFile || [];\n\t\tthis.ignoreFolders = ignoreFolder || [];\n\t\tthis.printMode = printMode;\n\t\tthis.ignoreGitIgnore = ignoreGitIgnore;\n\t\tthis.minifyForLLM = minifyForLLM;\n\t\tthis.gitIgnoreHandler = new GitIgnoreHandler();\n\t\ttry {\n\t\t\tthis.grep = grep ? new RegExp(grep, ignoreCase ? \"gi\" : \"g\") : undefined;\n\t\t} catch (error) {\n\t\t\tlogger.error(error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tshouldIgnoreFolder(directory: string) {\n\t\tconst folderName = basename(directory);\n\t\t// Check for exact folder name match\n\t\tif (this.ignoreFolders && this.ignoreFolders.includes(folderName)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tshouldIgnoreFile(filePath: string) {\n\t\t// First check if the file is in the ignoreFiles list\n\t\tconst filename = basename(filePath);\n\t\tif (this.ignoreFiles && this.ignoreFiles.includes(filename)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Then check if the extension should be ignored\n\t\tif (!this.ignoreExtensions || this.ignoreExtensions.length === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst extension = getFileExtension(filePath);\n\n\t\t// Check for exact extension match\n\t\tif (this.ignoreExtensions.includes(extension)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Check for complex patterns like \"min.js\"\n\t\tfor (const pattern of this.ignoreExtensions) {\n\t\t\t// Skip patterns that don't contain a dot\n\t\t\tif (!pattern.includes(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if the filename ends with the pattern\n\t\t\tif (filename.toLowerCase().endsWith(`.${pattern}`)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tfilterHidden(value: string[] | string) {\n\t\tif (this.displayHiddenFilesAndFolders) {\n\t\t\treturn true;\n\t\t}\n\t\treturn value[0] !== \".\";\n\t}\n\n\tasync start(returnResults = false) {\n\t\tif (this.displayStats) {\n\t\t\tperf.start();\n\t\t}\n\t\tawait this.scanFileSystem([this.path]);\n\t\tconst results = await this.postProcessResults(returnResults);\n\n\t\tif (this.displayStats) {\n\t\t\tperf.stop();\n\t\t\tprintStatistics({\n\t\t\t\tduration: perf.results.duration,\n\t\t\t\tgrep: this.grep,\n\t\t\t\tpattern: this.rePattern,\n\t\t\t\ttotalDirScanned: this.totalDirScanned,\n\t\t\t\ttotalDirsFound: this.totalDirFound,\n\t\t\t\ttotalFileScanned: this.totalFileScanned,\n\t\t\t\ttotalFilesFound: this.totalFileFound,\n\t\t\t\ttype: this.type,\n\t\t\t});\n\t\t}\n\t\treturn returnResults ? results : undefined;\n\t}\n\n\tasync scanFileSystem(nodes: string[]) {\n\t\tfor (const node of nodes) {\n\t\t\tlet result: boolean | RegExpExecArray,\n\t\t\t\tfiles: string[],\n\t\t\t\tshortname: string,\n\t\t\t\tstat: fs.Stats;\n\t\t\ttry {\n\t\t\t\tstat = await lstatAsync(node);\n\t\t\t} catch {\n\t\t\t\t// ignore read permission denied errors silently...\n\t\t\t}\n\n\t\t\tconst isDirectory = stat && stat.isDirectory();\n\t\t\tconst isFile = stat && stat.isFile();\n\n\t\t\t// Add this check to respect .gitignore patterns\n\t\t\tif (await this.shouldIgnoreByGitIgnore(node, isDirectory)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isDirectory && !this.shouldIgnoreFolder(node)) {\n\t\t\t\tthis.totalDirScanned++;\n\n\t\t\t\tresult = checkPattern(this.rePattern, node);\n\t\t\t\tif (result) {\n\t\t\t\t\tthis.totalDirFound++;\n\t\t\t\t\tthis.nodesList.push({\n\t\t\t\t\t\tcommand: this.command,\n\t\t\t\t\t\tmatch: result,\n\t\t\t\t\t\tname: node,\n\t\t\t\t\t\tstat,\n\t\t\t\t\t\ttype: STR_TYPE_DIRECTORY,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tfiles = await readdirAsync(node);\n\t\t\t\t\tawait this.scanFileSystem(\n\t\t\t\t\t\tfiles\n\t\t\t\t\t\t\t.filter((element) => this.filterHidden(element))\n\t\t\t\t\t\t\t.map(function (file) {\n\t\t\t\t\t\t\t\treturn join(node, file);\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t} catch {\n\t\t\t\t\t// nothing to declare\n\t\t\t\t}\n\t\t\t} else if (isFile) {\n\t\t\t\t// Skip files with ignored extensions\n\t\t\t\tif (this.shouldIgnoreFile(node)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis.totalFileScanned++;\n\t\t\t\tshortname = basename(node);\n\t\t\t\tconst patternResult = checkPattern(this.rePattern, shortname);\n\t\t\t\tif (patternResult) {\n\t\t\t\t\tthis.totalFileFound++;\n\t\t\t\t\tthis.nodesList.push({\n\t\t\t\t\t\tcommand: this.command,\n\t\t\t\t\t\tmatch: patternResult[0],\n\t\t\t\t\t\tname: node,\n\t\t\t\t\t\tstat,\n\t\t\t\t\t\ttype: STR_TYPE_FILE,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tasync readFileContent(filePath: string): Promise<string> {\n\t\ttry {\n\t\t\t// Check if it's a known binary extension\n\t\t\t/* istanbul ignore if */\n\t\t\tif (isBinaryFileExtension(filePath)) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst content = await readFileAsync(filePath, \"utf8\");\n\t\t\treturn this.minifyForLLM\n\t\t\t\t? await minifyFileContent(filePath, content)\n\t\t\t\t: content;\n\t\t} catch (_error) {\n\t\t\t/* istanbul ignore next */\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tasync printFilesContent(returnResults: boolean) {\n\t\tconst fileNodes = this.nodesList.filter(\n\t\t\t(node) => node.type === STR_TYPE_FILE,\n\t\t);\n\n\t\tif (this.printMode === \"simple\") {\n\t\t\tfor (const node of fileNodes) {\n\t\t\t\tconst relativePath = relative(this.path, node.name);\n\t\t\t\tif (returnResults) {\n\t\t\t\t\tloggerInMemory.log(`---\\n./${relativePath}\\n---`);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.log(`---\\n./${relativePath}\\n---`);\n\t\t\t\t}\n\t\t\t\tconst content = await this.readFileContent(node.name);\n\t\t\t\tif (returnResults) {\n\t\t\t\t\tloggerInMemory.log(content);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.log(content);\n\t\t\t\t}\n\t\t\t\t// adding a new line after each file content except the last one\n\t\t\t\tif (node !== fileNodes[fileNodes.length - 1]) {\n\t\t\t\t\tif (returnResults) {\n\t\t\t\t\t\tloggerInMemory.log(\"\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.log(\"\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.printMode === \"xml\") {\n\t\t\tif (returnResults) {\n\t\t\t\tloggerInMemory.log(\"<documents>\");\n\t\t\t} else {\n\t\t\t\tlogger.log(\"<documents>\");\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < fileNodes.length; i++) {\n\t\t\t\tconst node = fileNodes[i];\n\t\t\t\tconst relativePath = relative(this.path, node.name);\n\t\t\t\tconst content = await this.readFileContent(node.name);\n\n\t\t\t\tif (returnResults) {\n\t\t\t\t\tif (content) {\n\t\t\t\t\t\tloggerInMemory.log(`<document index=\"${i + 1}\">`);\n\t\t\t\t\t\tloggerInMemory.log(`<source>./${relativePath}</source>`);\n\t\t\t\t\t\tloggerInMemory.log(\"<document_content>\");\n\t\t\t\t\t\tloggerInMemory.log(content);\n\t\t\t\t\t\tloggerInMemory.log(\"</document_content>\");\n\t\t\t\t\t\tloggerInMemory.log(\"</document>\");\n\t\t\t\t\t}\n\t\t\t\t} else if (content) {\n\t\t\t\t\tlogger.log(`<document index=\"${i + 1}\">`);\n\t\t\t\t\tlogger.log(`<source>./${relativePath}</source>`);\n\t\t\t\t\tlogger.log(\"<document_content>\");\n\t\t\t\t\tlogger.log(content);\n\t\t\t\t\tlogger.log(\"</document_content>\");\n\t\t\t\t\tlogger.log(\"</document>\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (returnResults) {\n\t\t\t\tloggerInMemory.log(\"</documents>\");\n\t\t\t} else {\n\t\t\t\tlogger.log(\"</documents>\");\n\t\t\t}\n\t\t}\n\t\tconst results = returnResults ? loggerInMemory.getMemoryLogs() : undefined;\n\t\tloggerInMemory.clearMemoryLogs();\n\t\treturn results;\n\t}\n\n\tasync shouldIgnoreByGitIgnore(\n\t\tnodePath: string,\n\t\tisDirectory: boolean,\n\t): Promise<boolean> {\n\t\tif (this.ignoreGitIgnore) {\n\t\t\treturn false;\n\t\t}\n\t\treturn this.gitIgnoreHandler.isIgnored(nodePath, isDirectory);\n\t}\n\n\tasync postProcessResults(returnResults: boolean) {\n\t\tif (this.grep) {\n\t\t\t/**\n\t\t\t * Resetting the number of files found, since we want to\n\t\t\t * show how many matched the grep, not how many matched the\n\t\t\t * pattern (in the file name).\n\t\t\t */\n\t\t\tthis.totalFileFound = 0;\n\t\t}\n\n\t\t// If printMode is enabled, handle file content printing and return\n\t\tif (this.printMode && [\"simple\", \"xml\"].includes(this.printMode)) {\n\t\t\treturn await this.printFilesContent(returnResults);\n\t\t}\n\n\t\t/* istanbul ignore if */\n\t\tif (!this.boring) {\n\t\t\tlogger.log();\n\t\t}\n\n\t\tfor (const node of this.nodesList) {\n\t\t\tif (\n\t\t\t\t(this.type === STR_TYPE_FILE && node.type === STR_TYPE_FILE) ||\n\t\t\t\t(this.type === STR_TYPE_DIRECTORY &&\n\t\t\t\t\tnode.type === STR_TYPE_DIRECTORY) ||\n\t\t\t\tthis.type === STR_TYPE_BOTH\n\t\t\t) {\n\t\t\t\tlet list: {\n\t\t\t\t\t\tgroup?: string;\n\t\t\t\t\t\tmdate?: string;\n\t\t\t\t\t\tmode?: string;\n\t\t\t\t\t\towner?: string;\n\t\t\t\t\t\tsize?: string;\n\t\t\t\t\t} = {\n\t\t\t\t\t\tgroup: \"\",\n\t\t\t\t\t\tmdate: \"\",\n\t\t\t\t\t\tmode: \"\",\n\t\t\t\t\t\towner: \"\",\n\t\t\t\t\t\tsize: \"\",\n\t\t\t\t\t},\n\t\t\t\t\tname: string,\n\t\t\t\t\tseparator: string = \"\";\n\n\t\t\t\t/* istanbul ignore if */\n\t\t\t\tif (this.displayLongListing) {\n\t\t\t\t\tlist = await formatLongListings(node.stat, node.type);\n\t\t\t\t\tseparator = \"\\t\";\n\t\t\t\t}\n\n\t\t\t\tconst color = node.type === STR_TYPE_FILE ? kleur.gray : kleur.blue;\n\t\t\t\tname = relative(this.path, node.name);\n\n\t\t\t\tif (node.match) {\n\t\t\t\t\tconst matchStr = String(node.match); // Ensure match is a string\n\t\t\t\t\tconst match = new RegExp(matchStr, \"g\");\n\t\t\t\t\tconst highlightedMatch = kleur.black().bgYellow(matchStr);\n\t\t\t\t\tname = color(name.replace(match, highlightedMatch));\n\t\t\t\t} else {\n\t\t\t\t\tname = color(name);\n\t\t\t\t}\n\n\t\t\t\tif (this.grep && node.type === STR_TYPE_FILE) {\n\t\t\t\t\tconst { totalMatchingLines, results } = await runGrepOnNode(\n\t\t\t\t\t\tnode.name,\n\t\t\t\t\t\tthis.grep,\n\t\t\t\t\t);\n\t\t\t\t\t/* istanbul ignore else */\n\t\t\t\t\tif (totalMatchingLines) {\n\t\t\t\t\t\tthis.totalFileFound++;\n\t\t\t\t\t\tconst occurrences = plur(\"occurrence\", totalMatchingLines);\n\n\t\t\t\t\t\tlogger.log(\n\t\t\t\t\t\t\t` %s${separator}%s${separator}%s${separator}%s${separator}%s`,\n\t\t\t\t\t\t\tlist.mode.trim(),\n\t\t\t\t\t\t\tlist.owner.trim(),\n\t\t\t\t\t\t\tlist.size.trim(),\n\t\t\t\t\t\t\tlist.mdate,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t`(${kleur.white(totalMatchingLines)} ${occurrences})`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlogger.log(`${results.join(\"\\n\")}\\n`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (!this.grep) {\n\t\t\t\t\t\tlogger.log(\n\t\t\t\t\t\t\t` %s${separator}%s${separator}%s${separator}%s${separator}%s`,\n\t\t\t\t\t\t\tlist.mode.trim(),\n\t\t\t\t\t\t\tlist.owner.trim(),\n\t\t\t\t\t\t\tlist.size.trim(),\n\t\t\t\t\t\t\tlist.mdate,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (node.command) {\n\t\t\t\t\t\t\tawait runCommandOnNode(node.name, node.command);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["basename","join","relative","promisify","Logger","Performance","fs","kleur","plur","GitIgnoreHandler","minifyFileContent","STR_TYPE_BOTH","STR_TYPE_DIRECTORY","STR_TYPE_FILE","checkPattern","formatLongListings","getFileExtension","isBinaryFileExtension","printStatistics","runCommandOnNode","runGrepOnNode","lstatAsync","lstat","readdirAsync","readdir","readFileAsync","readFile","perf","logger","boring","process","env","NODE_ENV","loggerInMemory","inMemory","Search","command","displayHiddenFilesAndFolders","displayLongListing","displayStats","grep","nodesList","path","rePattern","totalDirFound","totalDirScanned","totalFileFound","totalFileScanned","type","ignoreExtensions","ignoreFiles","ignoreFolders","printMode","gitIgnoreHandler","ignoreGitIgnore","minifyForLLM","constructor","dot","ignoreCase","short","pattern","stats","ignoreExtension","ignoreFile","ignoreFolder","RegExp","undefined","enabled","trim","map","ext","toLowerCase","error","exit","shouldIgnoreFolder","directory","folderName","includes","shouldIgnoreFile","filePath","filename","length","extension","endsWith","filterHidden","value","start","returnResults","scanFileSystem","results","postProcessResults","stop","duration","totalDirsFound","totalFilesFound","nodes","node","result","files","shortname","stat","isDirectory","isFile","shouldIgnoreByGitIgnore","push","match","name","filter","element","file","patternResult","readFileContent","content","_error","printFilesContent","fileNodes","relativePath","log","i","getMemoryLogs","clearMemoryLogs","nodePath","isIgnored","list","group","mdate","mode","owner","size","separator","color","gray","blue","matchStr","String","highlightedMatch","black","bgYellow","replace","totalMatchingLines","occurrences","white"],"mappings":"AAAA,SAASA,QAAQ,EAAWC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAC9D,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,OAAO;AAExB,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SAAoBC,iBAAiB,QAAkB,iBAAiB;AACxE,SACCC,aAAa,EACbC,kBAAkB,EAClBC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,qBAAqB,EACrBC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,QACP,iBAAiB;AAExB,MAAMC,aAAalB,UAAUG,GAAGgB,KAAK;AACrC,MAAMC,eAAepB,UAAUG,GAAGkB,OAAO;AACzC,MAAMC,gBAAgBtB,UAAUG,GAAGoB,QAAQ;AAC3C,MAAMC,OAAO,IAAItB;AACjB,MAAMuB,SAAS,IAAIxB,OAAO;IACzByB,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAClC;AACA,MAAMC,i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E8H,kBAAkB,EAAElD,OAAO,EAAE,GAAG,MAAMrE,cAC7C4E,KAAKU,IAAI,EACT,IAAI,CAAClE,IAAI;oBAEV,wBAAwB,GACxB,IAAImG,oBAAoB;wBACvB,IAAI,CAAC7F,cAAc;wBACnB,MAAM8F,cAAcpI,KAAK,cAAcmI;wBAEvC/G,OAAOyF,GAAG,CACT,CAAC,GAAG,EAAEY,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,CAAC,EAC7DN,KAAKG,IAAI,CAAC1D,IAAI,IACduD,KAAKI,KAAK,CAAC3D,IAAI,IACfuD,KAAKK,IAAI,CAAC5D,IAAI,IACduD,KAAKE,KAAK,EACVnB,MACA,CAAC,CAAC,EAAEnG,MAAMsI,KAAK,CAACF,oBAAoB,CAAC,EAAEC,YAAY,CAAC,CAAC;wBAEtDhH,OAAOyF,GAAG,CAAC,GAAG5B,QAAQxF,IAAI,CAAC,MAAM,EAAE,CAAC;oBACrC;gBACD,OAAO;oBACN,wBAAwB,GACxB,IAAI,CAAC,IAAI,CAACuC,IAAI,EAAE;wBACfZ,OAAOyF,GAAG,CACT,CAAC,GAAG,EAAEY,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,CAAC,EAC7DN,KAAKG,IAAI,CAAC1D,IAAI,IACduD,KAAKI,KAAK,CAAC3D,IAAI,IACfuD,KAAKK,IAAI,CAAC5D,IAAI,IACduD,KAAKE,KAAK,EACVnB;wBAED,IAAIV,KAAK5D,OAAO,EAAE;4BACjB,MAAMjB,iBAAiB6E,KAAKU,IAAI,EAAEV,KAAK5D,OAAO;wBAC/C;oBACD;gBACD;YACD;QACD;IACD;AACD"}
|
|
1
|
+
{"version":3,"sources":["../src/core.ts"],"sourcesContent":["import { basename, extname, join, relative } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { Logger } from \"@node-cli/logger\";\nimport { Performance } from \"@node-cli/perf\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport plur from \"plur\";\n\nimport { GitIgnoreHandler } from \"./gitIgnoreHandler.js\";\nimport { minifyCss, minifyFileContent, minifyJs } from \"./minifiers.js\";\nimport {\n\tSTR_TYPE_BOTH,\n\tSTR_TYPE_DIRECTORY,\n\tSTR_TYPE_FILE,\n\tcheckPattern,\n\tformatLongListings,\n\tgetFileExtension,\n\tisBinaryFileExtension,\n\tprintStatistics,\n\trunCommandOnNode,\n\trunGrepOnNode,\n} from \"./utilities.js\";\n\nconst lstatAsync = promisify(fs.lstat);\nconst readdirAsync = promisify(fs.readdir);\nconst readFileAsync = promisify(fs.readFile);\nconst perf = new Performance();\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\nconst loggerInMemory = new Logger({\n\tinMemory: true,\n});\n\nexport class Search {\n\tboring?: boolean;\n\tcommand?: string;\n\tdisplayHiddenFilesAndFolders?: boolean;\n\tdisplayLongListing?: boolean;\n\tdisplayStats?: boolean;\n\tgrep?: RegExp;\n\tnodesList?: any[];\n\tpath?: string;\n\trePattern?: RegExp;\n\ttotalDirFound?: number;\n\ttotalDirScanned?: number;\n\ttotalFileFound?: number;\n\ttotalFileScanned?: number;\n\ttype?: string;\n\tignoreExtensions?: string[];\n\tignoreFiles?: string[];\n\tignoreFolders?: string[];\n\tprintMode?: string;\n\tgitIgnoreHandler: GitIgnoreHandler;\n\tignoreGitIgnore?: boolean;\n\tminifyForLLM?: boolean;\n\n\tconstructor({\n\t\tboring,\n\t\tcommand,\n\t\tdot,\n\t\tgrep,\n\t\tignoreCase,\n\t\tshort,\n\t\tpath,\n\t\tpattern,\n\t\tstats,\n\t\ttype,\n\t\tignoreExtension,\n\t\tignoreFile,\n\t\tignoreFolder,\n\t\tprintMode,\n\t\tignoreGitIgnore,\n\t\tminifyForLLM,\n\t}: {\n\t\tboring?: boolean;\n\t\tcommand?: string;\n\t\tdot?: boolean;\n\t\tgrep?: string | RegExp;\n\t\tignoreCase?: boolean;\n\t\tshort?: boolean;\n\t\tpath?: string;\n\t\tpattern?: string;\n\t\tstats?: boolean;\n\t\ttype?: string;\n\t\tignoreExtension?: string[];\n\t\tignoreFile?: string[];\n\t\tignoreFolder?: string[];\n\t\tprintMode?: string;\n\t\tignoreGitIgnore?: boolean;\n\t\tminifyForLLM?: boolean;\n\t}) {\n\t\tthis.path = path;\n\t\tthis.rePattern = pattern\n\t\t\t? new RegExp(pattern, ignoreCase ? \"i\" : \"\")\n\t\t\t: undefined;\n\t\tthis.type = type || STR_TYPE_BOTH;\n\t\tthis.boring = boring;\n\t\tkleur.enabled = !boring;\n\t\tthis.displayLongListing = !short;\n\t\tthis.displayStats = stats;\n\t\tthis.displayHiddenFilesAndFolders = dot;\n\t\tthis.nodesList = [];\n\t\tthis.totalDirScanned = 0;\n\t\tthis.totalFileScanned = 0;\n\t\tthis.totalDirFound = 0;\n\t\tthis.totalFileFound = 0;\n\t\tthis.command = command ? command.trim() : undefined;\n\t\tthis.ignoreExtensions =\n\t\t\t(ignoreExtension && ignoreExtension.map((ext) => ext.toLowerCase())) ||\n\t\t\t[];\n\t\tthis.ignoreFiles = ignoreFile || [];\n\t\tthis.ignoreFolders = ignoreFolder || [];\n\t\tthis.printMode = printMode;\n\t\tthis.ignoreGitIgnore = ignoreGitIgnore;\n\t\tthis.minifyForLLM = minifyForLLM;\n\t\tthis.gitIgnoreHandler = new GitIgnoreHandler();\n\t\ttry {\n\t\t\tthis.grep = grep ? new RegExp(grep, ignoreCase ? \"gi\" : \"g\") : undefined;\n\t\t} catch (error) {\n\t\t\tlogger.error(error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tshouldIgnoreFolder(directory: string) {\n\t\tconst folderName = basename(directory);\n\t\t// Check for exact folder name match\n\t\tif (this.ignoreFolders && this.ignoreFolders.includes(folderName)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tshouldIgnoreFile(filePath: string) {\n\t\t// First check if the file is in the ignoreFiles list\n\t\tconst filename = basename(filePath);\n\t\tif (this.ignoreFiles && this.ignoreFiles.includes(filename)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Then check if the extension should be ignored\n\t\tif (!this.ignoreExtensions || this.ignoreExtensions.length === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst extension = getFileExtension(filePath);\n\n\t\t// Check for exact extension match\n\t\tif (this.ignoreExtensions.includes(extension)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Check for complex patterns like \"min.js\"\n\t\tfor (const pattern of this.ignoreExtensions) {\n\t\t\t// Skip patterns that don't contain a dot\n\t\t\tif (!pattern.includes(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if the filename ends with the pattern\n\t\t\tif (filename.toLowerCase().endsWith(`.${pattern}`)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tfilterHidden(value: string[] | string) {\n\t\tif (this.displayHiddenFilesAndFolders) {\n\t\t\treturn true;\n\t\t}\n\t\treturn value[0] !== \".\";\n\t}\n\n\tasync start(returnResults = false) {\n\t\tif (this.displayStats) {\n\t\t\tperf.start();\n\t\t}\n\t\tawait this.scanFileSystem([this.path]);\n\t\tconst results = await this.postProcessResults(returnResults);\n\n\t\tif (this.displayStats) {\n\t\t\tperf.stop();\n\t\t\tprintStatistics({\n\t\t\t\tduration: perf.results.duration,\n\t\t\t\tgrep: this.grep,\n\t\t\t\tpattern: this.rePattern,\n\t\t\t\ttotalDirScanned: this.totalDirScanned,\n\t\t\t\ttotalDirsFound: this.totalDirFound,\n\t\t\t\ttotalFileScanned: this.totalFileScanned,\n\t\t\t\ttotalFilesFound: this.totalFileFound,\n\t\t\t\ttype: this.type,\n\t\t\t});\n\t\t}\n\t\treturn returnResults ? results : undefined;\n\t}\n\n\tasync scanFileSystem(nodes: string[]) {\n\t\tfor (const node of nodes) {\n\t\t\tlet result: boolean | RegExpExecArray,\n\t\t\t\tfiles: string[],\n\t\t\t\tshortname: string,\n\t\t\t\tstat: fs.Stats;\n\t\t\ttry {\n\t\t\t\tstat = await lstatAsync(node);\n\t\t\t} catch {\n\t\t\t\t// ignore read permission denied errors silently...\n\t\t\t}\n\n\t\t\tconst isDirectory = stat && stat.isDirectory();\n\t\t\tconst isFile = stat && stat.isFile();\n\n\t\t\t// Add this check to respect .gitignore patterns\n\t\t\tif (await this.shouldIgnoreByGitIgnore(node, isDirectory)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isDirectory && !this.shouldIgnoreFolder(node)) {\n\t\t\t\tthis.totalDirScanned++;\n\n\t\t\t\tresult = checkPattern(this.rePattern, node);\n\t\t\t\tif (result) {\n\t\t\t\t\tthis.totalDirFound++;\n\t\t\t\t\tthis.nodesList.push({\n\t\t\t\t\t\tcommand: this.command,\n\t\t\t\t\t\tmatch: result,\n\t\t\t\t\t\tname: node,\n\t\t\t\t\t\tstat,\n\t\t\t\t\t\ttype: STR_TYPE_DIRECTORY,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tfiles = await readdirAsync(node);\n\t\t\t\t\tawait this.scanFileSystem(\n\t\t\t\t\t\tfiles\n\t\t\t\t\t\t\t.filter((element) => this.filterHidden(element))\n\t\t\t\t\t\t\t.map(function (file) {\n\t\t\t\t\t\t\t\treturn join(node, file);\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t} catch {\n\t\t\t\t\t// nothing to declare\n\t\t\t\t}\n\t\t\t} else if (isFile) {\n\t\t\t\t// Skip files with ignored extensions\n\t\t\t\tif (this.shouldIgnoreFile(node)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis.totalFileScanned++;\n\t\t\t\tshortname = basename(node);\n\t\t\t\tconst patternResult = checkPattern(this.rePattern, shortname);\n\t\t\t\tif (patternResult) {\n\t\t\t\t\tthis.totalFileFound++;\n\t\t\t\t\tthis.nodesList.push({\n\t\t\t\t\t\tcommand: this.command,\n\t\t\t\t\t\tmatch: patternResult[0],\n\t\t\t\t\t\tname: node,\n\t\t\t\t\t\tstat,\n\t\t\t\t\t\ttype: STR_TYPE_FILE,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tasync readFileContent(filePath: string): Promise<string> {\n\t\ttry {\n\t\t\t// Check if it's a known binary extension\n\t\t\t/* v8 ignore next */\n\t\t\tif (isBinaryFileExtension(filePath)) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst content = await readFileAsync(filePath, \"utf8\");\n\t\t\treturn this.minifyForLLM\n\t\t\t\t? await minifyFileContent(filePath, content)\n\t\t\t\t: content;\n\t\t} catch (_error) {\n\t\t\t/* v8 ignore next */\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tasync printFilesContent(returnResults: boolean) {\n\t\tconst fileNodes = this.nodesList.filter(\n\t\t\t(node) => node.type === STR_TYPE_FILE,\n\t\t);\n\n\t\tif (this.printMode === \"simple\") {\n\t\t\tfor (const node of fileNodes) {\n\t\t\t\tconst relativePath = relative(this.path, node.name);\n\t\t\t\tif (returnResults) {\n\t\t\t\t\tloggerInMemory.log(`---\\n./${relativePath}\\n---`);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.log(`---\\n./${relativePath}\\n---`);\n\t\t\t\t}\n\t\t\t\tconst content = await this.readFileContent(node.name);\n\t\t\t\tif (returnResults) {\n\t\t\t\t\tloggerInMemory.log(content);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.log(content);\n\t\t\t\t}\n\t\t\t\t// adding a new line after each file content except the last one\n\t\t\t\tif (node !== fileNodes[fileNodes.length - 1]) {\n\t\t\t\t\tif (returnResults) {\n\t\t\t\t\t\tloggerInMemory.log(\"\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.log(\"\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.printMode === \"xml\") {\n\t\t\tif (returnResults) {\n\t\t\t\tloggerInMemory.log(\"<documents>\");\n\t\t\t} else {\n\t\t\t\tlogger.log(\"<documents>\");\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < fileNodes.length; i++) {\n\t\t\t\tconst node = fileNodes[i];\n\t\t\t\tconst relativePath = relative(this.path, node.name);\n\t\t\t\tconst content = await this.readFileContent(node.name);\n\n\t\t\t\tif (returnResults) {\n\t\t\t\t\tif (content) {\n\t\t\t\t\t\tloggerInMemory.log(`<document index=\"${i + 1}\">`);\n\t\t\t\t\t\tloggerInMemory.log(`<source>./${relativePath}</source>`);\n\t\t\t\t\t\tloggerInMemory.log(\"<document_content>\");\n\t\t\t\t\t\tloggerInMemory.log(content);\n\t\t\t\t\t\tloggerInMemory.log(\"</document_content>\");\n\t\t\t\t\t\tloggerInMemory.log(\"</document>\");\n\t\t\t\t\t}\n\t\t\t\t} else if (content) {\n\t\t\t\t\tlogger.log(`<document index=\"${i + 1}\">`);\n\t\t\t\t\tlogger.log(`<source>./${relativePath}</source>`);\n\t\t\t\t\tlogger.log(\"<document_content>\");\n\t\t\t\t\tlogger.log(content);\n\t\t\t\t\tlogger.log(\"</document_content>\");\n\t\t\t\t\tlogger.log(\"</document>\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (returnResults) {\n\t\t\t\tloggerInMemory.log(\"</documents>\");\n\t\t\t} else {\n\t\t\t\tlogger.log(\"</documents>\");\n\t\t\t}\n\t\t}\n\t\tconst results = returnResults ? loggerInMemory.getMemoryLogs() : undefined;\n\t\tloggerInMemory.clearMemoryLogs();\n\t\treturn results;\n\t}\n\n\tasync shouldIgnoreByGitIgnore(\n\t\tnodePath: string,\n\t\tisDirectory: boolean,\n\t): Promise<boolean> {\n\t\tif (this.ignoreGitIgnore) {\n\t\t\treturn false;\n\t\t}\n\t\treturn this.gitIgnoreHandler.isIgnored(nodePath, isDirectory);\n\t}\n\n\tasync postProcessResults(returnResults: boolean) {\n\t\tif (this.grep) {\n\t\t\t/**\n\t\t\t * Resetting the number of files found, since we want to\n\t\t\t * show how many matched the grep, not how many matched the\n\t\t\t * pattern (in the file name).\n\t\t\t */\n\t\t\tthis.totalFileFound = 0;\n\t\t}\n\n\t\t// If printMode is enabled, handle file content printing and return\n\t\tif (this.printMode && [\"simple\", \"xml\"].includes(this.printMode)) {\n\t\t\treturn await this.printFilesContent(returnResults);\n\t\t}\n\n\t\t/* v8 ignore next */\n\t\tif (!this.boring) {\n\t\t\tlogger.log();\n\t\t}\n\n\t\tfor (const node of this.nodesList) {\n\t\t\tif (\n\t\t\t\t(this.type === STR_TYPE_FILE && node.type === STR_TYPE_FILE) ||\n\t\t\t\t(this.type === STR_TYPE_DIRECTORY &&\n\t\t\t\t\tnode.type === STR_TYPE_DIRECTORY) ||\n\t\t\t\tthis.type === STR_TYPE_BOTH\n\t\t\t) {\n\t\t\t\tlet list: {\n\t\t\t\t\t\tgroup?: string;\n\t\t\t\t\t\tmdate?: string;\n\t\t\t\t\t\tmode?: string;\n\t\t\t\t\t\towner?: string;\n\t\t\t\t\t\tsize?: string;\n\t\t\t\t\t} = {\n\t\t\t\t\t\tgroup: \"\",\n\t\t\t\t\t\tmdate: \"\",\n\t\t\t\t\t\tmode: \"\",\n\t\t\t\t\t\towner: \"\",\n\t\t\t\t\t\tsize: \"\",\n\t\t\t\t\t},\n\t\t\t\t\tname: string,\n\t\t\t\t\tseparator: string = \"\";\n\n\t\t\t\t/* v8 ignore next */\n\t\t\t\tif (this.displayLongListing) {\n\t\t\t\t\tlist = await formatLongListings(node.stat, node.type);\n\t\t\t\t\tseparator = \"\\t\";\n\t\t\t\t}\n\n\t\t\t\tconst color = node.type === STR_TYPE_FILE ? kleur.gray : kleur.blue;\n\t\t\t\tname = relative(this.path, node.name);\n\n\t\t\t\tif (node.match) {\n\t\t\t\t\tconst matchStr = String(node.match); // Ensure match is a string\n\t\t\t\t\tconst match = new RegExp(matchStr, \"g\");\n\t\t\t\t\tconst highlightedMatch = kleur.black().bgYellow(matchStr);\n\t\t\t\t\tname = color(name.replace(match, highlightedMatch));\n\t\t\t\t} else {\n\t\t\t\t\tname = color(name);\n\t\t\t\t}\n\n\t\t\t\tif (this.grep && node.type === STR_TYPE_FILE) {\n\t\t\t\t\tconst { totalMatchingLines, results } = await runGrepOnNode(\n\t\t\t\t\t\tnode.name,\n\t\t\t\t\t\tthis.grep,\n\t\t\t\t\t);\n\t\t\t\t\t/* v8 ignore next */\n\t\t\t\t\tif (totalMatchingLines) {\n\t\t\t\t\t\tthis.totalFileFound++;\n\t\t\t\t\t\tconst occurrences = plur(\"occurrence\", totalMatchingLines);\n\n\t\t\t\t\t\tlogger.log(\n\t\t\t\t\t\t\t` %s${separator}%s${separator}%s${separator}%s${separator}%s`,\n\t\t\t\t\t\t\tlist.mode.trim(),\n\t\t\t\t\t\t\tlist.owner.trim(),\n\t\t\t\t\t\t\tlist.size.trim(),\n\t\t\t\t\t\t\tlist.mdate,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t`(${kleur.white(totalMatchingLines)} ${occurrences})`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlogger.log(`${results.join(\"\\n\")}\\n`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t/* v8 ignore next */\n\t\t\t\t\tif (!this.grep) {\n\t\t\t\t\t\tlogger.log(\n\t\t\t\t\t\t\t` %s${separator}%s${separator}%s${separator}%s${separator}%s`,\n\t\t\t\t\t\t\tlist.mode.trim(),\n\t\t\t\t\t\t\tlist.owner.trim(),\n\t\t\t\t\t\t\tlist.size.trim(),\n\t\t\t\t\t\t\tlist.mdate,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (node.command) {\n\t\t\t\t\t\t\tawait runCommandOnNode(node.name, node.command);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["basename","join","relative","promisify","Logger","Performance","fs","kleur","plur","GitIgnoreHandler","minifyFileContent","STR_TYPE_BOTH","STR_TYPE_DIRECTORY","STR_TYPE_FILE","checkPattern","formatLongListings","getFileExtension","isBinaryFileExtension","printStatistics","runCommandOnNode","runGrepOnNode","lstatAsync","lstat","readdirAsync","readdir","readFileAsync","readFile","perf","logger","boring","process","env","NODE_ENV","loggerInMemory","inMemory","Search","command","displayHiddenFilesAndFolders","displayLongListing","displayStats","grep","nodesList","path","rePattern","totalDirFound","totalDirScanned","totalFileFound","totalFileScanned","type","ignoreExtensions","ignoreFiles","ignoreFolders","printMode","gitIgnoreHandler","ignoreGitIgnore","minifyForLLM","constructor","dot","ignoreCase","short","pattern","stats","ignoreExtension","ignoreFile","ignoreFolder","RegExp","undefined","enabled","trim","map","ext","toLowerCase","error","exit","shouldIgnoreFolder","directory","folderName","includes","shouldIgnoreFile","filePath","filename","length","extension","endsWith","filterHidden","value","start","returnResults","scanFileSystem","results","postProcessResults","stop","duration","totalDirsFound","totalFilesFound","nodes","node","result","files","shortname","stat","isDirectory","isFile","shouldIgnoreByGitIgnore","push","match","name","filter","element","file","patternResult","readFileContent","content","_error","printFilesContent","fileNodes","relativePath","log","i","getMemoryLogs","clearMemoryLogs","nodePath","isIgnored","list","group","mdate","mode","owner","size","separator","color","gray","blue","matchStr","String","highlightedMatch","black","bgYellow","replace","totalMatchingLines","occurrences","white"],"mappings":"AAAA,SAASA,QAAQ,EAAWC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAC9D,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,OAAO;AAExB,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SAAoBC,iBAAiB,QAAkB,iBAAiB;AACxE,SACCC,aAAa,EACbC,kBAAkB,EAClBC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,gBAA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K,IAAI,CAAC5D,IAAI,IACduD,KAAKE,KAAK,EACVnB;wBAED,IAAIV,KAAK5D,OAAO,EAAE;4BACjB,MAAMjB,iBAAiB6E,KAAKU,IAAI,EAAEV,KAAK5D,OAAO;wBAC/C;oBACD;gBACD;YACD;QACD;IACD;AACD"}
|
package/dist/gitIgnoreHandler.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* v8 ignore start */ import { basename, dirname, join, relative } from "node:path";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import micromatch from "micromatch";
|
|
@@ -114,6 +114,6 @@ const readFileAsync = promisify(fs.readFile);
|
|
|
114
114
|
*/ clearCache() {
|
|
115
115
|
this.ignoredPathsCache.clear();
|
|
116
116
|
}
|
|
117
|
-
}
|
|
117
|
+
} /* v8 ignore stop */
|
|
118
118
|
|
|
119
119
|
//# sourceMappingURL=gitIgnoreHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gitIgnoreHandler.ts"],"sourcesContent":["/*
|
|
1
|
+
{"version":3,"sources":["../src/gitIgnoreHandler.ts"],"sourcesContent":["/* v8 ignore start */\nimport { basename, dirname, join, relative } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport fs from \"fs-extra\";\nimport micromatch from \"micromatch\";\n\nconst readFileAsync = promisify(fs.readFile);\n\n/**\n * Represents a pattern from a .gitignore file\n */\ninterface GitIgnorePattern {\n\t/** The actual pattern string */\n\tpattern: string;\n\t/** Whether this is a negated pattern (starts with !) */\n\tisNegated: boolean;\n\t/** Whether this pattern is specific to directories (ends with /) */\n\tisDirectory: boolean;\n}\n\n/**\n * Handles parsing and matching of .gitignore patterns\n */\nexport class GitIgnoreHandler {\n\t/** Map to store ignore patterns by directory */\n\tprivate ignorePatterns: Map<string, GitIgnorePattern[]>;\n\t/** Cache to store already processed paths */\n\tprivate ignoredPathsCache: Map<string, boolean>;\n\n\tconstructor() {\n\t\tthis.ignorePatterns = new Map<string, GitIgnorePattern[]>();\n\t\tthis.ignoredPathsCache = new Map<string, boolean>();\n\t}\n\n\t/**\n\t * Parse a .gitignore file and return the patterns\n\t * @param filePath Path to the .gitignore file\n\t * @returns Array of parsed patterns\n\t */\n\tasync parseGitIgnoreFile(filePath: string): Promise<GitIgnorePattern[]> {\n\t\ttry {\n\t\t\tconst content = await readFileAsync(filePath, \"utf8\");\n\t\t\treturn content\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.filter((line) => {\n\t\t\t\t\t// Remove comments and empty lines\n\t\t\t\t\tconst trimmedLine = line.trim();\n\t\t\t\t\treturn trimmedLine && !trimmedLine.startsWith(\"#\");\n\t\t\t\t})\n\t\t\t\t.map((pattern) => {\n\t\t\t\t\t// Handle negated patterns (those starting with !)\n\t\t\t\t\tconst isNegated = pattern.startsWith(\"!\");\n\t\t\t\t\t// Remove leading ! for negated patterns\n\t\t\t\t\tconst cleanPattern = isNegated ? pattern.slice(1) : pattern;\n\t\t\t\t\t// Handle directory-specific patterns (those ending with /)\n\t\t\t\t\tconst isDirectory = cleanPattern.endsWith(\"/\");\n\t\t\t\t\t// Remove trailing / for directory patterns\n\t\t\t\t\tconst finalPattern = isDirectory\n\t\t\t\t\t\t? cleanPattern.slice(0, -1)\n\t\t\t\t\t\t: cleanPattern;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpattern: finalPattern,\n\t\t\t\t\t\tisNegated,\n\t\t\t\t\t\tisDirectory,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t} catch (_error) {\n\t\t\t// If file doesn't exist or can't be read, return empty array\n\t\t\treturn [];\n\t\t}\n\t}\n\n\t/**\n\t * Load .gitignore files from a directory and its parents\n\t * @param directory Directory to load .gitignore from\n\t */\n\tasync loadGitIgnorePatterns(directory: string): Promise<void> {\n\t\t// If we've already loaded patterns for this directory, return\n\t\tif (this.ignorePatterns.has(directory)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Load .gitignore from current directory\n\t\tconst gitIgnorePath = join(directory, \".gitignore\");\n\t\tconst patterns = await this.parseGitIgnoreFile(gitIgnorePath);\n\t\tthis.ignorePatterns.set(directory, patterns);\n\n\t\t// Load patterns from parent directories (if not at root)\n\t\tconst parentDir = dirname(directory);\n\t\tif (parentDir !== directory) {\n\t\t\tawait this.loadGitIgnorePatterns(parentDir);\n\t\t}\n\t}\n\n\t/**\n\t * Check if a path should be ignored based on .gitignore rules\n\t * @param path Path to check\n\t * @param isDirectory Whether the path is a directory\n\t * @returns True if the path should be ignored, false otherwise\n\t */\n\tasync isIgnored(\n\t\tpath: string,\n\t\tisDirectory: boolean = false,\n\t): Promise<boolean> {\n\t\t// Check cache first\n\t\tconst cacheKey = `${path}:${isDirectory}`;\n\t\tif (this.ignoredPathsCache.has(cacheKey)) {\n\t\t\treturn this.ignoredPathsCache.get(cacheKey)!;\n\t\t}\n\n\t\t// Get the directory containing the path\n\t\tconst directory = isDirectory ? path : dirname(path);\n\n\t\t// Load .gitignore patterns if not already loaded\n\t\tawait this.loadGitIgnorePatterns(directory);\n\n\t\t// Get the relative path from the containing directory\n\t\tconst filename = basename(path);\n\n\t\t// Start with not ignored\n\t\tlet ignored = false;\n\n\t\t// Check patterns from current directory up to root\n\t\tlet currentDir = directory;\n\t\twhile (true) {\n\t\t\tconst patterns = this.ignorePatterns.get(currentDir) || [];\n\n\t\t\t// Calculate relative path from this directory to the file\n\t\t\tconst relPath = relative(currentDir, path);\n\n\t\t\tfor (const {\n\t\t\t\tpattern,\n\t\t\t\tisNegated,\n\t\t\t\tisDirectory: isPatternForDir,\n\t\t\t} of patterns) {\n\t\t\t\t// Skip directory-specific patterns if checking a file\n\t\t\t\tif (isPatternForDir && !isDirectory) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Check if pattern matches\n\t\t\t\tconst matches =\n\t\t\t\t\tmicromatch.isMatch(relPath, pattern) ||\n\t\t\t\t\tmicromatch.isMatch(filename, pattern);\n\n\t\t\t\tif (matches) {\n\t\t\t\t\t// Negated patterns override previous ignores\n\t\t\t\t\tignored = !isNegated;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Move to parent directory\n\t\t\tconst parentDir = dirname(currentDir);\n\t\t\tif (parentDir === currentDir) {\n\t\t\t\tbreak; // We've reached the root\n\t\t\t}\n\t\t\tcurrentDir = parentDir;\n\t\t}\n\n\t\t// Cache the result\n\t\tthis.ignoredPathsCache.set(cacheKey, ignored);\n\t\treturn ignored;\n\t}\n\n\t/**\n\t * Clear the cache of ignored paths\n\t */\n\tclearCache(): void {\n\t\tthis.ignoredPathsCache.clear();\n\t}\n}\n/* v8 ignore stop */\n"],"names":["basename","dirname","join","relative","promisify","fs","micromatch","readFileAsync","readFile","GitIgnoreHandler","ignorePatterns","ignoredPathsCache","constructor","Map","parseGitIgnoreFile","filePath","content","split","filter","line","trimmedLine","trim","startsWith","map","pattern","isNegated","cleanPattern","slice","isDirectory","endsWith","finalPattern","_error","loadGitIgnorePatterns","directory","has","gitIgnorePath","patterns","set","parentDir","isIgnored","path","cacheKey","get","filename","ignored","currentDir","relPath","isPatternForDir","matches","isMatch","clearCache","clear"],"mappings":"AAAA,mBAAmB,GACnB,SAASA,QAAQ,EAAEC,OAAO,EAAEC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAC9D,SAASC,SAAS,QAAQ,YAAY;AACtC,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,gBAAgB,aAAa;AAEpC,MAAMC,gBAAgBH,UAAUC,GAAGG,QAAQ;AAc3C;;CAEC,GACD,OAAO,MAAMC;IACZ,8CAA8C,GAC9C,AAAQC,eAAgD;IACxD,2CAA2C,GAC3C,AAAQC,kBAAwC;IAEhDC,aAAc;QACb,IAAI,CAACF,cAAc,GAAG,IAAIG;QAC1B,IAAI,CAACF,iBAAiB,GAAG,IAAIE;IAC9B;IAEA;;;;EAIC,GACD,MAAMC,mBAAmBC,QAAgB,EAA+B;QACvE,IAAI;YACH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O,IAAI,CAAC9B,iBAAiB,CAAC+B,GAAG,CAACD;QACnC;QAEA,wCAAwC;QACxC,MAAMR,YAAYL,cAAcY,OAAOvC,QAAQuC;QAE/C,iDAAiD;QACjD,MAAM,IAAI,CAACR,qBAAqB,CAACC;QAEjC,sDAAsD;QACtD,MAAMU,WAAW3C,SAASwC;QAE1B,yBAAyB;QACzB,IAAII,UAAU;QAEd,mDAAmD;QACnD,IAAIC,aAAaZ;QACjB,MAAO,KAAM;YACZ,MAAMG,WAAW,IAAI,CAAC1B,cAAc,CAACgC,GAAG,CAACG,eAAe,EAAE;YAE1D,0DAA0D;YAC1D,MAAMC,UAAU3C,SAAS0C,YAAYL;YAErC,KAAK,MAAM,EACVhB,OAAO,EACPC,SAAS,EACTG,aAAamB,eAAe,EAC5B,IAAIX,SAAU;gBACd,sDAAsD;gBACtD,IAAIW,mBAAmB,CAACnB,aAAa;oBACpC;gBACD;gBAEA,2BAA2B;gBAC3B,MAAMoB,UACL1C,WAAW2C,OAAO,CAACH,SAAStB,YAC5BlB,WAAW2C,OAAO,CAACN,UAAUnB;gBAE9B,IAAIwB,SAAS;oBACZ,6CAA6C;oBAC7CJ,UAAU,CAACnB;gBACZ;YACD;YAEA,2BAA2B;YAC3B,MAAMa,YAAYrC,QAAQ4C;YAC1B,IAAIP,cAAcO,YAAY;gBAC7B,OAAO,yBAAyB;YACjC;YACAA,aAAaP;QACd;QAEA,mBAAmB;QACnB,IAAI,CAAC3B,iBAAiB,CAAC0B,GAAG,CAACI,UAAUG;QACrC,OAAOA;IACR;IAEA;;EAEC,GACDM,aAAmB;QAClB,IAAI,CAACvC,iBAAiB,CAACwC,KAAK;IAC7B;AACD,EACA,kBAAkB"}
|
package/dist/minifiers.js
CHANGED
|
@@ -98,10 +98,10 @@ export async function minifyFileContent(filePath, content) {
|
|
|
98
98
|
return content;
|
|
99
99
|
}
|
|
100
100
|
const fileExtension = getFileExtension(filePath);
|
|
101
|
-
if (content && content.length > 0 && (fileExtension.endsWith("js") || fileExtension.endsWith("ts") || /*
|
|
101
|
+
if (content && content.length > 0 && (fileExtension.endsWith("js") || fileExtension.endsWith("ts") || /* v8 ignore next */ fileExtension.endsWith("jsx") || /* v8 ignore next */ fileExtension.endsWith("tsx"))) {
|
|
102
102
|
return minifyJs(content);
|
|
103
103
|
}
|
|
104
|
-
/*
|
|
104
|
+
/* v8 ignore next */ if (content && content.length > 0 && fileExtension.endsWith("css")) {
|
|
105
105
|
return minifyCss(content);
|
|
106
106
|
}
|
|
107
107
|
return content;
|
package/dist/minifiers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/minifiers.ts"],"sourcesContent":["import { v4 as uuidv4 } from \"uuid\";\nimport { getFileExtension } from \"./utilities.js\";\n\nexport function minifyImports(content: string): string {\n\treturn content.replace(\n\t\t/(import\\s*\\{)([^}]*?)(\\}\\s*from)/g,\n\t\t(_match, _importStart, importItems, _importEnd) => {\n\t\t\t// Process the items being imported\n\t\t\tconst cleanedItems = importItems\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((item) => {\n\t\t\t\t\t// Handle 'type' keyword specifically\n\t\t\t\t\treturn item.trim().replace(/(\\btype\\b)\\s+/, \"$1\");\n\t\t\t\t})\n\t\t\t\t.join(\",\");\n\n\t\t\treturn `import {${cleanedItems}} from`;\n\t\t},\n\t);\n}\n\nexport function minifyJs(content: string): string {\n\t// Store template literals and regular expressions to protect them from minification\n\tconst tokenPrefix = `__PROTECTED_${uuidv4()}_`;\n\tconst protectedSegments: string[] = [];\n\n\t// Function to create a unique token for each protected segment\n\tconst createToken = (index: number) => `${tokenPrefix}${index}__`;\n\n\t// Function to protect a segment of code with a custom handler\n\tconst protect = (pattern: RegExp, handler?: (match: string) => boolean) => {\n\t\tcontent = content.replace(pattern, (match) => {\n\t\t\t// If a handler is provided, use it to determine if we should protect this match\n\t\t\tif (handler && !handler(match)) {\n\t\t\t\treturn \"\"; // Return empty string for JSDoc comments we don't want to keep\n\t\t\t}\n\t\t\tconst index = protectedSegments.length;\n\t\t\tprotectedSegments.push(match);\n\t\t\treturn createToken(index);\n\t\t});\n\t};\n\n\t// Protect template literals\n\tprotect(/`[\\s\\S]*?`/g);\n\n\t// Protect regular expressions\n\t// This regex pattern matches JavaScript regular expressions while avoiding division operators\n\tprotect(\n\t\t/(?<![a-zA-Z0-9_$])\\/(?![*+?\\/])(?:[^\\r\\n\\[/\\\\]|\\\\.|\\[(?:[^\\r\\n\\]\\\\]|\\\\.)*\\])+\\/[gimyus]*/g,\n\t);\n\n\t// Protect important JSDoc comments\n\tprotect(/\\/\\*\\*[\\s\\S]*?\\*\\//g, (match) => {\n\t\treturn (\n\t\t\tmatch.includes(\"@param\") ||\n\t\t\tmatch.includes(\"@returns\") ||\n\t\t\tmatch.includes(\"@description\")\n\t\t);\n\t});\n\n\t// Remove comments (both single-line and multi-line)\n\tcontent = content.replace(/\\/\\/.*$/gm, \"\"); // Remove single-line comments\n\tcontent = content.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\"); // Remove multi-line comments\n\n\t// Compact import statements\n\tcontent = minifyImports(content);\n\n\t// Remove extra whitespace\n\tcontent = content.replace(/^\\s+/gm, \"\"); // Remove leading whitespace\n\tcontent = content.replace(/\\s+$/gm, \"\"); // Remove trailing whitespace\n\tcontent = content.replace(/\\s{2,}/g, \" \"); // Replace multiple spaces with a single space\n\n\t// Compact newlines ( we protected template literals before)\n\tcontent = content.replace(/\\n+/g, \" \");\n\n\t// Replace semicolon + space with just semicolon\n\tcontent = content.replace(/;\\s+/g, \";\");\n\n\t// Replace colon + space with just colon\n\tcontent = content.replace(/,\\s+/g, \",\");\n\n\t// Remove spaces around operators (we protected regex operators before)\n\tcontent = content.replace(/\\s+([+\\-*/%=&|<>!?:;,])\\s+/g, \"$1\");\n\n\t// Handle spaces around parentheses and brackets\n\tcontent = content.replace(/\\(\\s+/g, \"(\");\n\tcontent = content.replace(/\\s+\\)/g, \")\");\n\tcontent = content.replace(/\\[\\s+/g, \"[\");\n\tcontent = content.replace(/\\s+\\]/g, \"]\");\n\n\t// Handle spaces in all curly braces (for object literals, destructuring, etc.)\n\tcontent = content.replace(/\\{\\s+/g, \"{\");\n\tcontent = content.replace(/\\s+\\}/g, \"}\");\n\n\t// Restore protected segments\n\t// We need to handle nested tokens, so we'll iterate until all tokens are replaced\n\tlet previousContent = \"\";\n\twhile (previousContent !== content) {\n\t\tpreviousContent = content;\n\t\t// Sort indices in descending order to handle nested tokens correctly\n\t\tconst indices = Array.from(\n\t\t\t{ length: protectedSegments.length },\n\t\t\t(_, i) => i,\n\t\t).sort((a, b) => b - a);\n\t\tfor (const index of indices) {\n\t\t\tconst token = createToken(index);\n\t\t\tconst segment = protectedSegments[index];\n\t\t\t// Use global replacement to catch all instances\n\t\t\tconst tokenRegex = new RegExp(\n\t\t\t\ttoken.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"),\n\t\t\t\t\"g\",\n\t\t\t);\n\t\t\tcontent = content.replace(tokenRegex, () => segment);\n\t\t}\n\t}\n\treturn content;\n}\n\nexport function minifyCss(content: string): string {\n\t// Remove CSS comments\n\tcontent = content.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n\n\t// Remove extra whitespace\n\tcontent = content.replace(/\\s+/g, \" \");\n\tcontent = content.replace(/\\s*{\\s*/g, \"{\");\n\tcontent = content.replace(/\\s*}\\s*/g, \"}\");\n\tcontent = content.replace(/\\s*:\\s*/g, \":\");\n\tcontent = content.replace(/\\s*;\\s*/g, \";\");\n\tcontent = content.replace(/\\s*,\\s*/g, \",\");\n\n\treturn content;\n}\n\nexport async function minifyFileContent(\n\tfilePath: string,\n\tcontent: string,\n): Promise<string> {\n\tif (!content || content.length < 100) {\n\t\treturn content;\n\t}\n\n\tconst fileExtension = getFileExtension(filePath);\n\n\tif (\n\t\tcontent &&\n\t\tcontent.length > 0 &&\n\t\t(fileExtension.endsWith(\"js\") ||\n\t\t\tfileExtension.endsWith(\"ts\") ||\n\t\t\t/*
|
|
1
|
+
{"version":3,"sources":["../src/minifiers.ts"],"sourcesContent":["import { v4 as uuidv4 } from \"uuid\";\nimport { getFileExtension } from \"./utilities.js\";\n\nexport function minifyImports(content: string): string {\n\treturn content.replace(\n\t\t/(import\\s*\\{)([^}]*?)(\\}\\s*from)/g,\n\t\t(_match, _importStart, importItems, _importEnd) => {\n\t\t\t// Process the items being imported\n\t\t\tconst cleanedItems = importItems\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((item) => {\n\t\t\t\t\t// Handle 'type' keyword specifically\n\t\t\t\t\treturn item.trim().replace(/(\\btype\\b)\\s+/, \"$1\");\n\t\t\t\t})\n\t\t\t\t.join(\",\");\n\n\t\t\treturn `import {${cleanedItems}} from`;\n\t\t},\n\t);\n}\n\nexport function minifyJs(content: string): string {\n\t// Store template literals and regular expressions to protect them from minification\n\tconst tokenPrefix = `__PROTECTED_${uuidv4()}_`;\n\tconst protectedSegments: string[] = [];\n\n\t// Function to create a unique token for each protected segment\n\tconst createToken = (index: number) => `${tokenPrefix}${index}__`;\n\n\t// Function to protect a segment of code with a custom handler\n\tconst protect = (pattern: RegExp, handler?: (match: string) => boolean) => {\n\t\tcontent = content.replace(pattern, (match) => {\n\t\t\t// If a handler is provided, use it to determine if we should protect this match\n\t\t\tif (handler && !handler(match)) {\n\t\t\t\treturn \"\"; // Return empty string for JSDoc comments we don't want to keep\n\t\t\t}\n\t\t\tconst index = protectedSegments.length;\n\t\t\tprotectedSegments.push(match);\n\t\t\treturn createToken(index);\n\t\t});\n\t};\n\n\t// Protect template literals\n\tprotect(/`[\\s\\S]*?`/g);\n\n\t// Protect regular expressions\n\t// This regex pattern matches JavaScript regular expressions while avoiding division operators\n\tprotect(\n\t\t/(?<![a-zA-Z0-9_$])\\/(?![*+?\\/])(?:[^\\r\\n\\[/\\\\]|\\\\.|\\[(?:[^\\r\\n\\]\\\\]|\\\\.)*\\])+\\/[gimyus]*/g,\n\t);\n\n\t// Protect important JSDoc comments\n\tprotect(/\\/\\*\\*[\\s\\S]*?\\*\\//g, (match) => {\n\t\treturn (\n\t\t\tmatch.includes(\"@param\") ||\n\t\t\tmatch.includes(\"@returns\") ||\n\t\t\tmatch.includes(\"@description\")\n\t\t);\n\t});\n\n\t// Remove comments (both single-line and multi-line)\n\tcontent = content.replace(/\\/\\/.*$/gm, \"\"); // Remove single-line comments\n\tcontent = content.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\"); // Remove multi-line comments\n\n\t// Compact import statements\n\tcontent = minifyImports(content);\n\n\t// Remove extra whitespace\n\tcontent = content.replace(/^\\s+/gm, \"\"); // Remove leading whitespace\n\tcontent = content.replace(/\\s+$/gm, \"\"); // Remove trailing whitespace\n\tcontent = content.replace(/\\s{2,}/g, \" \"); // Replace multiple spaces with a single space\n\n\t// Compact newlines ( we protected template literals before)\n\tcontent = content.replace(/\\n+/g, \" \");\n\n\t// Replace semicolon + space with just semicolon\n\tcontent = content.replace(/;\\s+/g, \";\");\n\n\t// Replace colon + space with just colon\n\tcontent = content.replace(/,\\s+/g, \",\");\n\n\t// Remove spaces around operators (we protected regex operators before)\n\tcontent = content.replace(/\\s+([+\\-*/%=&|<>!?:;,])\\s+/g, \"$1\");\n\n\t// Handle spaces around parentheses and brackets\n\tcontent = content.replace(/\\(\\s+/g, \"(\");\n\tcontent = content.replace(/\\s+\\)/g, \")\");\n\tcontent = content.replace(/\\[\\s+/g, \"[\");\n\tcontent = content.replace(/\\s+\\]/g, \"]\");\n\n\t// Handle spaces in all curly braces (for object literals, destructuring, etc.)\n\tcontent = content.replace(/\\{\\s+/g, \"{\");\n\tcontent = content.replace(/\\s+\\}/g, \"}\");\n\n\t// Restore protected segments\n\t// We need to handle nested tokens, so we'll iterate until all tokens are replaced\n\tlet previousContent = \"\";\n\twhile (previousContent !== content) {\n\t\tpreviousContent = content;\n\t\t// Sort indices in descending order to handle nested tokens correctly\n\t\tconst indices = Array.from(\n\t\t\t{ length: protectedSegments.length },\n\t\t\t(_, i) => i,\n\t\t).sort((a, b) => b - a);\n\t\tfor (const index of indices) {\n\t\t\tconst token = createToken(index);\n\t\t\tconst segment = protectedSegments[index];\n\t\t\t// Use global replacement to catch all instances\n\t\t\tconst tokenRegex = new RegExp(\n\t\t\t\ttoken.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"),\n\t\t\t\t\"g\",\n\t\t\t);\n\t\t\tcontent = content.replace(tokenRegex, () => segment);\n\t\t}\n\t}\n\treturn content;\n}\n\nexport function minifyCss(content: string): string {\n\t// Remove CSS comments\n\tcontent = content.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n\n\t// Remove extra whitespace\n\tcontent = content.replace(/\\s+/g, \" \");\n\tcontent = content.replace(/\\s*{\\s*/g, \"{\");\n\tcontent = content.replace(/\\s*}\\s*/g, \"}\");\n\tcontent = content.replace(/\\s*:\\s*/g, \":\");\n\tcontent = content.replace(/\\s*;\\s*/g, \";\");\n\tcontent = content.replace(/\\s*,\\s*/g, \",\");\n\n\treturn content;\n}\n\nexport async function minifyFileContent(\n\tfilePath: string,\n\tcontent: string,\n): Promise<string> {\n\tif (!content || content.length < 100) {\n\t\treturn content;\n\t}\n\n\tconst fileExtension = getFileExtension(filePath);\n\n\tif (\n\t\tcontent &&\n\t\tcontent.length > 0 &&\n\t\t(fileExtension.endsWith(\"js\") ||\n\t\t\tfileExtension.endsWith(\"ts\") ||\n\t\t\t/* v8 ignore next */\n\t\t\tfileExtension.endsWith(\"jsx\") ||\n\t\t\t/* v8 ignore next */\n\t\t\tfileExtension.endsWith(\"tsx\"))\n\t) {\n\t\treturn minifyJs(content);\n\t}\n\n\t/* v8 ignore next */\n\tif (content && content.length > 0 && fileExtension.endsWith(\"css\")) {\n\t\treturn minifyCss(content);\n\t}\n\n\treturn content;\n}\n"],"names":["v4","uuidv4","getFileExtension","minifyImports","content","replace","_match","_importStart","importItems","_importEnd","cleanedItems","split","map","item","trim","join","minifyJs","tokenPrefix","protectedSegments","createToken","index","protect","pattern","handler","match","length","push","includes","previousContent","indices","Array","from","_","i","sort","a","b","token","segment","tokenRegex","RegExp","minifyCss","minifyFileContent","filePath","fileExtension","endsWith"],"mappings":"AAAA,SAASA,MAAMC,MAAM,QAAQ,OAAO;AACpC,SAASC,gBAAgB,QAAQ,iBAAiB;AAElD,OAAO,SAASC,cAAcC,OAAe;IAC5C,OAAOA,QAAQC,OAAO,CACrB,qCACA,CAACC,QAAQC,cAAcC,aAAaC;QACnC,mCAAmC;QACnC,MAAMC,eAAeF,YACnBG,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC;YACL,qCAAqC;YACrC,OAAOA,KAAKC,IAAI,GAAGT,OAAO,CAAC,iBAAiB;QAC7C,GACCU,IAAI,CAAC;QAEP,OAAO,CAAC,QAAQ,EAAEL,aAAa,MAAM,CAAC;IACvC;AAEF;AAEA,OAAO,SAASM,SAASZ,OAAe;IACvC,oFAAoF;IACpF,MAAMa,cAAc,CAAC,YAAY,EAAEhB,SAAS,CAAC,CAAC;IAC9C,MAAMiB,oBAA8B,EAAE;IAEtC,+DAA+D;IAC/D,MAAMC,cAAc,CAACC,QAAkB,GAAGH,cAAcG,MAAM,EAAE,CAAC;IAEjE,8DAA8D;IAC9D,MAAMC,UAAU,CAACC,SAAiBC;QACjCnB,UAAUA,QAAQC,OAAO,CAACiB,SAAS,CAACE;YACnC,gFAAgF;YAChF,IAAID,WAAW,CAACA,QAAQC,QAAQ;gBAC/B,OAAO,IAAI,+DAA+D;YAC3E;YACA,MAAMJ,QAAQF,kBAAkBO,MAAM;YACtCP,kBAAkBQ,IAAI,CAACF;YACvB,OAAOL,YAAYC;QACpB;IACD;IAEA,4BAA4B;IAC5BC,QAAQ;IAER,8BAA8B;IAC9B,8FAA8F;IAC9FA,QACC;IAGD,mCAAmC;IACnCA,QAAQ,uBAAuB,CAACG;QAC/B,OACCA,MAAMG,QAAQ,CAAC,aACfH,MAAMG,QAAQ,CAAC,eACfH,MAAMG,QAAQ,CAAC;IAEjB;IAEA,oDA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a,IAAIC,OACtBH,MAAMhC,OAAO,CAAC,uBAAuB,SACrC;YAEDD,UAAUA,QAAQC,OAAO,CAACkC,YAAY,IAAMD;QAC7C;IACD;IACA,OAAOlC;AACR;AAEA,OAAO,SAASqC,UAAUrC,OAAe;IACxC,sBAAsB;IACtBA,UAAUA,QAAQC,OAAO,CAAC,qBAAqB;IAE/C,0BAA0B;IAC1BD,UAAUA,QAAQC,OAAO,CAAC,QAAQ;IAClCD,UAAUA,QAAQC,OAAO,CAAC,YAAY;IACtCD,UAAUA,QAAQC,OAAO,CAAC,YAAY;IACtCD,UAAUA,QAAQC,OAAO,CAAC,YAAY;IACtCD,UAAUA,QAAQC,OAAO,CAAC,YAAY;IACtCD,UAAUA,QAAQC,OAAO,CAAC,YAAY;IAEtC,OAAOD;AACR;AAEA,OAAO,eAAesC,kBACrBC,QAAgB,EAChBvC,OAAe;IAEf,IAAI,CAACA,WAAWA,QAAQqB,MAAM,GAAG,KAAK;QACrC,OAAOrB;IACR;IAEA,MAAMwC,gBAAgB1C,iBAAiByC;IAEvC,IACCvC,WACAA,QAAQqB,MAAM,GAAG,KAChBmB,CAAAA,cAAcC,QAAQ,CAAC,SACvBD,cAAcC,QAAQ,CAAC,SACvB,kBAAkB,GAClBD,cAAcC,QAAQ,CAAC,UACvB,kBAAkB,GAClBD,cAAcC,QAAQ,CAAC,MAAK,GAC5B;QACD,OAAO7B,SAASZ;IACjB;IAEA,kBAAkB,GAClB,IAAIA,WAAWA,QAAQqB,MAAM,GAAG,KAAKmB,cAAcC,QAAQ,CAAC,QAAQ;QACnE,OAAOJ,UAAUrC;IAClB;IAEA,OAAOA;AACR"}
|
package/dist/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defaultFlags, defaultParameters } from "./defaults.js";
|
|
1
|
+
/* v8 ignore start */ import { defaultFlags, defaultParameters } from "./defaults.js";
|
|
2
2
|
import { parser } from "@node-cli/parser";
|
|
3
|
-
/*
|
|
3
|
+
/* v8 ignore start */ export const config = parser({
|
|
4
4
|
meta: import.meta,
|
|
5
5
|
examples: [
|
|
6
6
|
{
|
|
@@ -114,6 +114,6 @@ import { parser } from "@node-cli/parser";
|
|
|
114
114
|
usage: "search [options] [path]",
|
|
115
115
|
defaultFlags,
|
|
116
116
|
defaultParameters
|
|
117
|
-
});
|
|
117
|
+
}); /* v8 ignore stop */
|
|
118
118
|
|
|
119
119
|
//# sourceMappingURL=parse.js.map
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* v8 ignore start */\nimport { defaultFlags, defaultParameters } from \"./defaults.js\";\n\nimport { parser } from \"@node-cli/parser\";\n\nexport type Flags = {\n\tboring?: boolean;\n\tdot?: boolean;\n\tignoreCase?: boolean;\n\tshort?: boolean;\n\tstats?: boolean;\n\tgrep?: string;\n\ttype?: string;\n\tignore?: string[];\n\tprintMode?: string;\n};\n\nexport type Parameters = {\n\tpath?: string;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n};\n\n/* v8 ignore start */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [\n\t\t{\n\t\t\tcommand: 'search --type f --pattern \".jsx$\" src/',\n\t\t\tcomment:\n\t\t\t\t'## Find all files with the extension \".jsx\" in the \"src\" folder',\n\t\t},\n\t\t{\n\t\t\tcommand: 'search --type f --pattern \".sh$\" --command \"chmod +x\" bin/',\n\t\t\tcomment: `## Change the permissions to executable for all the files with\\n ## the extension \".sh\" found under the \"bin\" folder`,\n\t\t},\n\t\t{\n\t\t\tcommand: 'search --type f --pattern \".md$\" --grep \"Table of Content\"',\n\t\t\tcomment: `## Search in all the markdown files under the \"src\" folder for\\n ## the keywords \"Table of Content\"`,\n\t\t},\n\t],\n\tflags: {\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tcommand: {\n\t\t\tshortFlag: \"c\",\n\t\t\tdescription: \"Command to execute over each node (ex: chmod +x)\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tdot: {\n\t\t\tdefault: defaultFlags.dot,\n\t\t\tdescription: \"Show hidden files and directories\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tgrep: {\n\t\t\tshortFlag: \"g\",\n\t\t\tdescription: \"A RegExp to match the content of the files found\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tignoreCase: {\n\t\t\tshortFlag: \"i\",\n\t\t\tdefault: defaultFlags.ignoreCase,\n\t\t\tdescription: \"Ignore case when searching\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tpattern: {\n\t\t\tshortFlag: \"p\",\n\t\t\tdescription: \"A regular expression to match file or folder names\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tshort: {\n\t\t\tdefault: defaultFlags.short,\n\t\t\tdescription: \"Short listing format (equivalent to ls)\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tstats: {\n\t\t\tshortFlag: \"s\",\n\t\t\tdefault: defaultFlags.stats,\n\t\t\tdescription: \"Display some statistics\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\ttype: {\n\t\t\tshortFlag: \"t\",\n\t\t\tdefault: \"both\",\n\t\t\tdescription: \"Search for files (f) or directories (d)\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tignoreExtension: {\n\t\t\tshortFlag: \"I\",\n\t\t\tdescription: \"Ignore files extension, can be used multiple times\",\n\t\t\ttype: \"string\",\n\t\t\tisMultiple: true,\n\t\t},\n\t\tignoreFile: {\n\t\t\tshortFlag: \"F\",\n\t\t\tdescription: \"Ignore files name, can be used multiple times\",\n\t\t\ttype: \"string\",\n\t\t\tisMultiple: true,\n\t\t},\n\t\tignoreFolder: {\n\t\t\tshortFlag: \"D\",\n\t\t\tdescription: \"Ignore folders name, can be used multiple times\",\n\t\t\ttype: \"string\",\n\t\t\tisMultiple: true,\n\t\t},\n\t\tprintMode: {\n\t\t\tshortFlag: \"P\",\n\t\t\tdescription: \"Print mode (simple or xml)\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tignoreGitIgnore: {\n\t\t\tdescription: \"Ignore .gitignore files\",\n\t\t\tdefault: defaultFlags.ignoreGitIgnore,\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tpath: {\n\t\t\tdefault: \"current folder\",\n\t\t\tdescription: \"the path where to start the search\",\n\t\t},\n\t},\n\tusage: \"search [options] [path]\",\n\tdefaultFlags,\n\tdefaultParameters,\n});\n/* v8 ignore stop */\n"],"names":["defaultFlags","defaultParameters","parser","config","meta","examples","command","comment","flags","boring","shortFlag","default","description","type","dot","grep","help","ignoreCase","pattern","short","stats","version","ignoreExtension","isMultiple","ignoreFile","ignoreFolder","printMode","ignoreGitIgnore","parameters","path","usage"],"mappings":"AAAA,mBAAmB,GACnB,SAASA,YAAY,EAAEC,iBAAiB,QAAQ,gBAAgB;AAEhE,SAASC,MAAM,QAAQ,mBAAmB;AAuB1C,mBAAmB,GACnB,OAAO,MAAMC,SAAwBD,OAAO;IAC3CE,MAAM;IACNC,UAAU;QACT;YACCC,SAAS;YACTC,SACC;QACF;QACA;YACCD,SAAS;YACTC,SAAS,CAAC,uHAAuH,CAAC;QACnI;QACA;YACCD,SAAS;YACTC,SAAS,CAAC,sGAAsG,CAAC;QAClH;KACA;IACDC,OAAO;QACNC,QAAQ;YACPC,WAAW;YACXC,SAASX,aAAaS,MAAM;YAC5BG,aAAa;YACbC,MAAM;QACP;QACAP,SAAS;YACRI,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAC,KAAK;YACJH,SAASX,aAAac,GAAG;YACzBF,aAAa;YACbC,MAAM;QACP;QACAE,MAAM;YACLL,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAG,MAAM;YACLN,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAI,YAAY;YACXP,WAAW;YACXC,SAASX,aAAaiB,UAAU;YAChCL,aAAa;YACbC,MAAM;QACP;QACAK,SAAS;YACRR,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAM,OAAO;YACNR,SAASX,aAAamB,KAAK;YAC3BP,aAAa;YACbC,MAAM;QACP;QACAO,OAAO;YACNV,WAAW;YACXC,SAASX,aAAaoB,KAAK;YAC3BR,aAAa;YACbC,MAAM;QACP;QACAA,MAAM;YACLH,WAAW;YACXC,SAAS;YACTC,aAAa;YACbC,MAAM;QACP;QACAQ,SAAS;YACRX,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAS,iBAAiB;YAChBZ,WAAW;YACXE,aAAa;YACbC,MAAM;YACNU,YAAY;QACb;QACAC,YAAY;YACXd,WAAW;YACXE,aAAa;YACbC,MAAM;YACNU,YAAY;QACb;QACAE,cAAc;YACbf,WAAW;YACXE,aAAa;YACbC,MAAM;YACNU,YAAY;QACb;QACAG,WAAW;YACVhB,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAc,iBAAiB;YAChBf,aAAa;YACbD,SAASX,aAAa2B,eAAe;YACrCd,MAAM;QACP;IACD;IACAe,YAAY;QACXC,MAAM;YACLlB,SAAS;YACTC,aAAa;QACd;IACD;IACAkB,OAAO;IACP9B;IACAC;AACD,GAAG,CACH,kBAAkB"}
|
package/dist/search.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/*
|
|
2
|
+
/* v8 ignore start */ import path from "node:path";
|
|
3
3
|
import { Logger } from "@node-cli/logger";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
import { Search } from "./core.js";
|
|
@@ -26,6 +26,6 @@ const search = new Search({
|
|
|
26
26
|
...config.flags,
|
|
27
27
|
path: customPath
|
|
28
28
|
});
|
|
29
|
-
await search.start();
|
|
29
|
+
await search.start(); /* v8 ignore stop */
|
|
30
30
|
|
|
31
31
|
//# sourceMappingURL=search.js.map
|
package/dist/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/search.ts"],"sourcesContent":["#!/usr/bin/env node\n/*
|
|
1
|
+
{"version":3,"sources":["../src/search.ts"],"sourcesContent":["#!/usr/bin/env node\n/* v8 ignore start */\n\nimport path from \"node:path\";\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport { Search } from \"./core.js\";\nimport { config } from \"./parse.js\";\nimport { STR_TYPE_FILE } from \"./utilities.js\";\n\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nlet customPath = config.parameters[0];\nif (fs.pathExistsSync(customPath)) {\n\tcustomPath = path.resolve(customPath);\n} else {\n\tlogger.printErrorsAndExit([`Folder ${customPath} does not exist!`], 0);\n}\n\nif (config.flags.grep) {\n\t// forcing simplified display if grep is true.\n\tconfig.flags.short = true;\n\t// And forcing type to files\n\tconfig.flags.type = STR_TYPE_FILE;\n}\n\nconst search = new Search({\n\t...config.flags,\n\tpath: customPath,\n});\n\nawait search.start();\n/* v8 ignore stop */\n"],"names":["path","Logger","fs","Search","config","STR_TYPE_FILE","logger","boring","process","env","NODE_ENV","customPath","parameters","pathExistsSync","resolve","printErrorsAndExit","flags","grep","short","type","search","start"],"mappings":";AACA,mBAAmB,GAEnB,OAAOA,UAAU,YAAY;AAC7B,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,MAAMC,SAAS,IAAIL,OAAO;IACzBM,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAClC;AAEA,IAAIC,aAAaP,OAAOQ,UAAU,CAAC,EAAE;AACrC,IAAIV,GAAGW,cAAc,CAACF,aAAa;IAClCA,aAAaX,KAAKc,OAAO,CAACH;AAC3B,OAAO;IACNL,OAAOS,kBAAkB,CAAC;QAAC,CAAC,OAAO,EAAEJ,WAAW,gBAAgB,CAAC;KAAC,EAAE;AACrE;AAEA,IAAIP,OAAOY,KAAK,CAACC,IAAI,EAAE;IACtB,8CAA8C;IAC9Cb,OAAOY,KAAK,CAACE,KAAK,GAAG;IACrB,4BAA4B;IAC5Bd,OAAOY,KAAK,CAACG,IAAI,GAAGd;AACrB;AAEA,MAAMe,SAAS,IAAIjB,OAAO;IACzB,GAAGC,OAAOY,KAAK;IACfhB,MAAMW;AACP;AAEA,MAAMS,OAAOC,KAAK,IAClB,kBAAkB"}
|
package/dist/utilities.js
CHANGED
|
@@ -142,7 +142,7 @@ export const convertDate = (mtime)=>{
|
|
|
142
142
|
};
|
|
143
143
|
export const getOwnerNameFromId = async (uid)=>{
|
|
144
144
|
let result;
|
|
145
|
-
/*
|
|
145
|
+
/* v8 ignore next */ if (ownerNames[uid]) {
|
|
146
146
|
return ownerNames[uid];
|
|
147
147
|
} else {
|
|
148
148
|
try {
|
|
@@ -229,7 +229,7 @@ export const runGrepOnNode = async (node, rePattern)=>{
|
|
|
229
229
|
totalMatchingLines
|
|
230
230
|
};
|
|
231
231
|
} catch (error) {
|
|
232
|
-
/*
|
|
232
|
+
/* v8 ignore next */ logger.error(error);
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
export function isBinaryFileExtension(filePath) {
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { Logger } from \"@node-cli/logger\";\nimport { RunResult, run } from \"@node-cli/run\";\nimport kleur from \"kleur\";\nimport prettyMilliseconds from \"pretty-ms\";\n\nconst BYTE_CHUNKS = 1000;\nconst DECIMAL = 10;\nconst LAST_THREE_ENTRIES = -3;\nconst MODE_GROUP_POS = 1;\nconst MODE_OWNER_POS = 0;\nconst MODE_WORD_POS = 2;\nconst OCTAL = 8;\nexport const STR_TYPE_DIRECTORY = \"d\";\nexport const STR_TYPE_FILE = \"f\";\nexport const STR_TYPE_BOTH = \"both\";\nconst PERMISSIONS_PREFIX = {\n\t[STR_TYPE_DIRECTORY]: \"d\",\n\t[STR_TYPE_FILE]: \"-\",\n};\nconst BINARY_EXTENSIONS = [\n\t// Executables and compiled code\n\t\"exe\",\n\t\"dll\",\n\t\"so\",\n\t\"dylib\",\n\t\"bin\",\n\t\"obj\",\n\t\"o\",\n\t// Compressed files\n\t\"zip\",\n\t\"tar\",\n\t\"gz\",\n\t\"rar\",\n\t\"7z\",\n\t\"jar\",\n\t\"war\",\n\t// Media files\n\t\"jpg\",\n\t\"jpeg\",\n\t\"png\",\n\t\"gif\",\n\t\"bmp\",\n\t\"ico\",\n\t\"tif\",\n\t\"tiff\",\n\t\"mp3\",\n\t\"mp4\",\n\t\"avi\",\n\t\"mov\",\n\t\"wmv\",\n\t\"flv\",\n\t\"wav\",\n\t\"ogg\",\n\t// Document formats\n\t\"pdf\",\n\t\"doc\",\n\t\"docx\",\n\t\"xls\",\n\t\"xlsx\",\n\t\"ppt\",\n\t\"pptx\",\n\t// Database files\n\t\"db\",\n\t\"sqlite\",\n\t\"mdb\",\n\t// Other binary formats\n\t\"class\",\n\t\"pyc\",\n\t\"pyd\",\n\t\"pyo\",\n\t\"woff\",\n\t\"woff2\",\n\t\"ttf\",\n\t\"otf\",\n];\n\nconst ownerNames = {\n\t0: \"root\",\n};\n\nconst MONTHS = {\n\t0: \"Jan\",\n\t1: \"Feb\",\n\t2: \"Mar\",\n\t3: \"Apr\",\n\t4: \"May\",\n\t5: \"Jun\",\n\t6: \"Jul\",\n\t7: \"Aug\",\n\t8: \"Sep\",\n\t9: \"Oct\",\n\t10: \"Nov\",\n\t11: \"Dec\",\n};\n\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nexport const getFileExtension = (filename: string): string => {\n\treturn extname(filename).toLowerCase().replace(/^\\./, \"\");\n};\n\nexport const extractMode = (mode: number): string => {\n\tconst modeDec = Number.parseInt(mode.toString(OCTAL), DECIMAL)\n\t\t.toString()\n\t\t.slice(LAST_THREE_ENTRIES);\n\tconst modeOwner = modeDec.charAt(MODE_OWNER_POS);\n\tconst modeGroup = modeDec.charAt(MODE_GROUP_POS);\n\tconst modeWorld = modeDec.charAt(MODE_WORD_POS);\n\tconst modes = {\n\t\t0: \"---\",\n\t\t1: \"--x\",\n\t\t2: \"-w-\",\n\t\t3: \"-wx\",\n\t\t4: \"r--\",\n\t\t5: \"r-x\",\n\t\t6: \"rw-\",\n\t\t7: \"rwx\",\n\t};\n\treturn modes[modeOwner] + modes[modeGroup] + modes[modeWorld];\n};\n\nexport const convertSize = (bytes: number): string => {\n\tconst sizes = [\"B\", \"K\", \"M\", \"G\", \"T\"];\n\tconst length = 5;\n\tlet posttxt = 0;\n\n\twhile (bytes >= BYTE_CHUNKS) {\n\t\tposttxt = posttxt + 1;\n\t\tbytes = bytes / BYTE_CHUNKS;\n\t}\n\tconst string_ =\n\t\tNumber.parseInt(bytes.toString(), DECIMAL).toFixed(0) + sizes[posttxt];\n\treturn (\n\t\tArray.from({ length: length + 1 - string_.length }).join(\" \") + string_\n\t);\n};\n\nexport const convertDate = (mtime: Date): string => {\n\tconst month = MONTHS[mtime.getMonth()];\n\tconst date = `${mtime.getDate()}`.padStart(2, \"0\");\n\tconst hours = `${mtime.getHours()}`.padStart(2, \"0\");\n\tconst minutes = `${mtime.getMinutes()}`.padStart(2, \"0\");\n\treturn `${month} ${date} ${hours}:${minutes}`;\n};\n\nexport const getOwnerNameFromId = async (\n\tuid: string | number,\n): Promise<string | number> => {\n\tlet result: RunResult;\n\n\t/* istanbul ignore else */\n\tif (ownerNames[uid]) {\n\t\treturn ownerNames[uid];\n\t} else {\n\t\ttry {\n\t\t\tresult = await run(`id -nu ${uid}`);\n\t\t\townerNames[uid] = result.stdout;\n\t\t\treturn result.stdout;\n\t\t} catch {\n\t\t\t// nothing to declare officer\n\t\t\treturn `${uid}`;\n\t\t}\n\t}\n};\n\nexport const formatLongListings = async (\n\tstat: { mtime: Date; mode: number; uid: string | number; size: number },\n\ttype: string,\n): Promise<{\n\tmdate: string;\n\tmode: string;\n\towner: string;\n\tsize: string;\n}> => ({\n\tmdate: `${convertDate(stat.mtime)}`,\n\tmode: PERMISSIONS_PREFIX[type] + extractMode(stat.mode),\n\towner: `${await getOwnerNameFromId(stat.uid)}`,\n\tsize: `${convertSize(stat.size)}`,\n});\n\nexport type Statistics = {\n\tduration?: number;\n\ttotalDirScanned?: number;\n\ttotalDirsFound?: number;\n\ttotalFileScanned?: number;\n\ttotalFilesFound?: number;\n\ttype?: string;\n\tpattern?: boolean | RegExp;\n\tgrep?: boolean | RegExp | string;\n};\nexport const printStatistics = ({\n\tduration,\n\ttotalDirScanned,\n\ttotalDirsFound,\n\ttotalFileScanned,\n\ttotalFilesFound,\n\ttype,\n\tpattern,\n\tgrep,\n}: Statistics) => {\n\tlet message = `Total folders scanned: ${kleur.yellow(totalDirScanned)}\\n`;\n\tmessage += `Total files scanned: ${kleur.yellow(totalFileScanned)}\\n`;\n\tswitch (type) {\n\t\tcase STR_TYPE_DIRECTORY: {\n\t\t\tmessage += `Total folders matching: ${kleur.green(totalDirsFound)}\\n`;\n\t\t\tbreak;\n\t\t}\n\n\t\tcase STR_TYPE_FILE: {\n\t\t\tmessage += `Total files matching: ${kleur.green(totalFilesFound)}\\n`;\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tif (pattern) {\n\t\t\t\tmessage += `Total folders matching: ${kleur.green(totalDirsFound)}\\n`;\n\t\t\t\tmessage += `Total files matching: ${kleur.green(totalFilesFound)}\\n`;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tmessage += `Duration: ${kleur.yellow(`${prettyMilliseconds(duration)}`)}`;\n\tif (!grep) {\n\t\tlogger.log();\n\t}\n\tlogger.printBox(message);\n};\n\nexport const checkPattern = (\n\trePattern: RegExp | undefined,\n\tstring_: string,\n): boolean | RegExpExecArray => {\n\tif (rePattern) {\n\t\trePattern.lastIndex = 0;\n\t\treturn rePattern.exec(string_);\n\t}\n\treturn true;\n};\n\nexport const runCommandOnNode = async (node: string, command: string) => {\n\ttry {\n\t\tconst { stdout } = await run(`${command} ${node}`);\n\t\tif (stdout) {\n\t\t\tlogger.log(stdout);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n};\n\nexport type RunGrepOnNode = {\n\tresults: (string | number)[];\n\ttotalMatchingLines: number;\n};\nexport const runGrepOnNode = async (\n\tnode?: string,\n\trePattern?: RegExp,\n): Promise<RunGrepOnNode> => {\n\ttry {\n\t\tconst lines = [];\n\t\tlet totalMatchingLines = 0;\n\t\tconst buffer = fs.readFileSync(node, \"utf8\").split(\"\\n\");\n\n\t\tfor (const [lineNumber, line] of buffer.entries()) {\n\t\t\trePattern.lastIndex = 0;\n\t\t\tconst result: (string | number)[] = rePattern.exec(line);\n\t\t\tif (!result) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttotalMatchingLines++;\n\t\t\tif (lineNumber > 0) {\n\t\t\t\tlines.push(`${lineNumber}: ${kleur.grey(buffer[lineNumber - 1])}`);\n\t\t\t}\n\t\t\tlines.push(\n\t\t\t\t`${lineNumber + 1}: ${kleur.grey(\n\t\t\t\t\tline.replace(rePattern, kleur.black().bgYellow(result[0])),\n\t\t\t\t)}`,\n\t\t\t\t`${lineNumber + 2}: ${kleur.grey(buffer[lineNumber + 1])}`,\n\t\t\t\t\"\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tresults: lines.length > 0 ? lines : [],\n\t\t\ttotalMatchingLines,\n\t\t};\n\t} catch (error) {\n\t\t/* istanbul ignore next */\n\t\tlogger.error(error);\n\t}\n};\n\nexport function isBinaryFileExtension(filePath: string): boolean {\n\tconst ext = getFileExtension(filePath);\n\t// If there's no extension, assume it's binary\n\tif (!ext) {\n\t\treturn true;\n\t}\n\treturn BINARY_EXTENSIONS.includes(ext);\n}\n"],"names":["fs","extname","Logger","run","kleur","prettyMilliseconds","BYTE_CHUNKS","DECIMAL","LAST_THREE_ENTRIES","MODE_GROUP_POS","MODE_OWNER_POS","MODE_WORD_POS","OCTAL","STR_TYPE_DIRECTORY","STR_TYPE_FILE","STR_TYPE_BOTH","PERMISSIONS_PREFIX","BINARY_EXTENSIONS","ownerNames","MONTHS","logger","boring","process","env","NODE_ENV","getFileExtension","filename","toLowerCase","replace","extractMode","mode","modeDec","Number","parseInt","toString","slice","modeOwner","charAt","modeGroup","modeWorld","modes","convertSize","bytes","sizes","length","posttxt","string_","toFixed","Array","from","join","convertDate","mtime","month","getMonth","date","getDate","padStart","hours","getHours","minutes","getMinutes","getOwnerNameFromId","uid","result","stdout","formatLongListings","stat","type","mdate","owner","size","printStatistics","duration","totalDirScanned","totalDirsFound","totalFileScanned","totalFilesFound","pattern","grep","message","yellow","green","log","printBox","checkPattern","rePattern","lastIndex","exec","runCommandOnNode","node","command","runGrepOnNode","lines","totalMatchingLines","buffer","readFileSync","split","lineNumber","line","entries","push","grey","black","bgYellow","results","error","isBinaryFileExtension","filePath","ext","includes"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAAoBC,GAAG,QAAQ,gBAAgB;AAC/C,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,wBAAwB,YAAY;AAE3C,MAAMC,cAAc;AACpB,MAAMC,UAAU;AAChB,MAAMC,qBAAqB,CAAC;AAC5B,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AACvB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,EAAE,EAAE9F,MAAMkG,IAAI,CAACP,MAAM,CAACG,aAAa,EAAE,GAAG,EAC1D;QAEF;QACA,OAAO;YACNO,SAASZ,MAAMjD,MAAM,GAAG,IAAIiD,QAAQ,EAAE;YACtCC;QACD;IACD,EAAE,OAAOY,OAAO;QACf,wBAAwB,GACxBtF,OAAOsF,KAAK,CAACA;IACd;AACD,EAAE;AAEF,OAAO,SAASC,sBAAsBC,QAAgB;IACrD,MAAMC,MAAMpF,iBAAiBmF;IAC7B,8CAA8C;IAC9C,IAAI,CAACC,KAAK;QACT,OAAO;IACR;IACA,OAAO5F,kBAAkB6F,QAAQ,CAACD;AACnC"}
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { Logger } from \"@node-cli/logger\";\nimport { RunResult, run } from \"@node-cli/run\";\nimport kleur from \"kleur\";\nimport prettyMilliseconds from \"pretty-ms\";\n\nconst BYTE_CHUNKS = 1000;\nconst DECIMAL = 10;\nconst LAST_THREE_ENTRIES = -3;\nconst MODE_GROUP_POS = 1;\nconst MODE_OWNER_POS = 0;\nconst MODE_WORD_POS = 2;\nconst OCTAL = 8;\nexport const STR_TYPE_DIRECTORY = \"d\";\nexport const STR_TYPE_FILE = \"f\";\nexport const STR_TYPE_BOTH = \"both\";\nconst PERMISSIONS_PREFIX = {\n\t[STR_TYPE_DIRECTORY]: \"d\",\n\t[STR_TYPE_FILE]: \"-\",\n};\nconst BINARY_EXTENSIONS = [\n\t// Executables and compiled code\n\t\"exe\",\n\t\"dll\",\n\t\"so\",\n\t\"dylib\",\n\t\"bin\",\n\t\"obj\",\n\t\"o\",\n\t// Compressed files\n\t\"zip\",\n\t\"tar\",\n\t\"gz\",\n\t\"rar\",\n\t\"7z\",\n\t\"jar\",\n\t\"war\",\n\t// Media files\n\t\"jpg\",\n\t\"jpeg\",\n\t\"png\",\n\t\"gif\",\n\t\"bmp\",\n\t\"ico\",\n\t\"tif\",\n\t\"tiff\",\n\t\"mp3\",\n\t\"mp4\",\n\t\"avi\",\n\t\"mov\",\n\t\"wmv\",\n\t\"flv\",\n\t\"wav\",\n\t\"ogg\",\n\t// Document formats\n\t\"pdf\",\n\t\"doc\",\n\t\"docx\",\n\t\"xls\",\n\t\"xlsx\",\n\t\"ppt\",\n\t\"pptx\",\n\t// Database files\n\t\"db\",\n\t\"sqlite\",\n\t\"mdb\",\n\t// Other binary formats\n\t\"class\",\n\t\"pyc\",\n\t\"pyd\",\n\t\"pyo\",\n\t\"woff\",\n\t\"woff2\",\n\t\"ttf\",\n\t\"otf\",\n];\n\nconst ownerNames = {\n\t0: \"root\",\n};\n\nconst MONTHS = {\n\t0: \"Jan\",\n\t1: \"Feb\",\n\t2: \"Mar\",\n\t3: \"Apr\",\n\t4: \"May\",\n\t5: \"Jun\",\n\t6: \"Jul\",\n\t7: \"Aug\",\n\t8: \"Sep\",\n\t9: \"Oct\",\n\t10: \"Nov\",\n\t11: \"Dec\",\n};\n\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nexport const getFileExtension = (filename: string): string => {\n\treturn extname(filename).toLowerCase().replace(/^\\./, \"\");\n};\n\nexport const extractMode = (mode: number): string => {\n\tconst modeDec = Number.parseInt(mode.toString(OCTAL), DECIMAL)\n\t\t.toString()\n\t\t.slice(LAST_THREE_ENTRIES);\n\tconst modeOwner = modeDec.charAt(MODE_OWNER_POS);\n\tconst modeGroup = modeDec.charAt(MODE_GROUP_POS);\n\tconst modeWorld = modeDec.charAt(MODE_WORD_POS);\n\tconst modes = {\n\t\t0: \"---\",\n\t\t1: \"--x\",\n\t\t2: \"-w-\",\n\t\t3: \"-wx\",\n\t\t4: \"r--\",\n\t\t5: \"r-x\",\n\t\t6: \"rw-\",\n\t\t7: \"rwx\",\n\t};\n\treturn modes[modeOwner] + modes[modeGroup] + modes[modeWorld];\n};\n\nexport const convertSize = (bytes: number): string => {\n\tconst sizes = [\"B\", \"K\", \"M\", \"G\", \"T\"];\n\tconst length = 5;\n\tlet posttxt = 0;\n\n\twhile (bytes >= BYTE_CHUNKS) {\n\t\tposttxt = posttxt + 1;\n\t\tbytes = bytes / BYTE_CHUNKS;\n\t}\n\tconst string_ =\n\t\tNumber.parseInt(bytes.toString(), DECIMAL).toFixed(0) + sizes[posttxt];\n\treturn (\n\t\tArray.from({ length: length + 1 - string_.length }).join(\" \") + string_\n\t);\n};\n\nexport const convertDate = (mtime: Date): string => {\n\tconst month = MONTHS[mtime.getMonth()];\n\tconst date = `${mtime.getDate()}`.padStart(2, \"0\");\n\tconst hours = `${mtime.getHours()}`.padStart(2, \"0\");\n\tconst minutes = `${mtime.getMinutes()}`.padStart(2, \"0\");\n\treturn `${month} ${date} ${hours}:${minutes}`;\n};\n\nexport const getOwnerNameFromId = async (\n\tuid: string | number,\n): Promise<string | number> => {\n\tlet result: RunResult;\n\n\t/* v8 ignore next */\n\tif (ownerNames[uid]) {\n\t\treturn ownerNames[uid];\n\t} else {\n\t\ttry {\n\t\t\tresult = await run(`id -nu ${uid}`);\n\t\t\townerNames[uid] = result.stdout;\n\t\t\treturn result.stdout;\n\t\t} catch {\n\t\t\t// nothing to declare officer\n\t\t\treturn `${uid}`;\n\t\t}\n\t}\n};\n\nexport const formatLongListings = async (\n\tstat: { mtime: Date; mode: number; uid: string | number; size: number },\n\ttype: string,\n): Promise<{\n\tmdate: string;\n\tmode: string;\n\towner: string;\n\tsize: string;\n}> => ({\n\tmdate: `${convertDate(stat.mtime)}`,\n\tmode: PERMISSIONS_PREFIX[type] + extractMode(stat.mode),\n\towner: `${await getOwnerNameFromId(stat.uid)}`,\n\tsize: `${convertSize(stat.size)}`,\n});\n\nexport type Statistics = {\n\tduration?: number;\n\ttotalDirScanned?: number;\n\ttotalDirsFound?: number;\n\ttotalFileScanned?: number;\n\ttotalFilesFound?: number;\n\ttype?: string;\n\tpattern?: boolean | RegExp;\n\tgrep?: boolean | RegExp | string;\n};\nexport const printStatistics = ({\n\tduration,\n\ttotalDirScanned,\n\ttotalDirsFound,\n\ttotalFileScanned,\n\ttotalFilesFound,\n\ttype,\n\tpattern,\n\tgrep,\n}: Statistics) => {\n\tlet message = `Total folders scanned: ${kleur.yellow(totalDirScanned)}\\n`;\n\tmessage += `Total files scanned: ${kleur.yellow(totalFileScanned)}\\n`;\n\tswitch (type) {\n\t\tcase STR_TYPE_DIRECTORY: {\n\t\t\tmessage += `Total folders matching: ${kleur.green(totalDirsFound)}\\n`;\n\t\t\tbreak;\n\t\t}\n\n\t\tcase STR_TYPE_FILE: {\n\t\t\tmessage += `Total files matching: ${kleur.green(totalFilesFound)}\\n`;\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tif (pattern) {\n\t\t\t\tmessage += `Total folders matching: ${kleur.green(totalDirsFound)}\\n`;\n\t\t\t\tmessage += `Total files matching: ${kleur.green(totalFilesFound)}\\n`;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tmessage += `Duration: ${kleur.yellow(`${prettyMilliseconds(duration)}`)}`;\n\tif (!grep) {\n\t\tlogger.log();\n\t}\n\tlogger.printBox(message);\n};\n\nexport const checkPattern = (\n\trePattern: RegExp | undefined,\n\tstring_: string,\n): boolean | RegExpExecArray => {\n\tif (rePattern) {\n\t\trePattern.lastIndex = 0;\n\t\treturn rePattern.exec(string_);\n\t}\n\treturn true;\n};\n\nexport const runCommandOnNode = async (node: string, command: string) => {\n\ttry {\n\t\tconst { stdout } = await run(`${command} ${node}`);\n\t\tif (stdout) {\n\t\t\tlogger.log(stdout);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n};\n\nexport type RunGrepOnNode = {\n\tresults: (string | number)[];\n\ttotalMatchingLines: number;\n};\nexport const runGrepOnNode = async (\n\tnode?: string,\n\trePattern?: RegExp,\n): Promise<RunGrepOnNode> => {\n\ttry {\n\t\tconst lines = [];\n\t\tlet totalMatchingLines = 0;\n\t\tconst buffer = fs.readFileSync(node, \"utf8\").split(\"\\n\");\n\n\t\tfor (const [lineNumber, line] of buffer.entries()) {\n\t\t\trePattern.lastIndex = 0;\n\t\t\tconst result: (string | number)[] = rePattern.exec(line);\n\t\t\tif (!result) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttotalMatchingLines++;\n\t\t\tif (lineNumber > 0) {\n\t\t\t\tlines.push(`${lineNumber}: ${kleur.grey(buffer[lineNumber - 1])}`);\n\t\t\t}\n\t\t\tlines.push(\n\t\t\t\t`${lineNumber + 1}: ${kleur.grey(\n\t\t\t\t\tline.replace(rePattern, kleur.black().bgYellow(result[0])),\n\t\t\t\t)}`,\n\t\t\t\t`${lineNumber + 2}: ${kleur.grey(buffer[lineNumber + 1])}`,\n\t\t\t\t\"\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tresults: lines.length > 0 ? lines : [],\n\t\t\ttotalMatchingLines,\n\t\t};\n\t} catch (error) {\n\t\t/* v8 ignore next */\n\t\tlogger.error(error);\n\t}\n};\n\nexport function isBinaryFileExtension(filePath: string): boolean {\n\tconst ext = getFileExtension(filePath);\n\t// If there's no extension, assume it's binary\n\tif (!ext) {\n\t\treturn true;\n\t}\n\treturn BINARY_EXTENSIONS.includes(ext);\n}\n"],"names":["fs","extname","Logger","run","kleur","prettyMilliseconds","BYTE_CHUNKS","DECIMAL","LAST_THREE_ENTRIES","MODE_GROUP_POS","MODE_OWNER_POS","MODE_WORD_POS","OCTAL","STR_TYPE_DIRECTORY","STR_TYPE_FILE","STR_TYPE_BOTH","PERMISSIONS_PREFIX","BINARY_EXTENSIONS","ownerNames","MONTHS","logger","boring","process","env","NODE_ENV","getFileExtension","filename","toLowerCase","replace","extractMode","mode","modeDec","Number","parseInt","toString","slice","modeOwner","charAt","modeGroup","modeWorld","modes","convertSize","bytes","sizes","length","posttxt","string_","toFixed","Array","from","join","convertDate","mtime","month","getMonth","date","getDate","padStart","hours","getHours","minutes","getMinutes","getOwnerNameFromId","uid","result","stdout","formatLongListings","stat","type","mdate","owner","size","printStatistics","duration","totalDirScanned","totalDirsFound","totalFileScanned","totalFilesFound","pattern","grep","message","yellow","green","log","printBox","checkPattern","rePattern","lastIndex","exec","runCommandOnNode","node","command","runGrepOnNode","lines","totalMatchingLines","buffer","readFileSync","split","lineNumber","line","entries","push","grey","black","bgYellow","results","error","isBinaryFileExtension","filePath","ext","includes"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAAoBC,GAAG,QAAQ,gBAAgB;AAC/C,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,wBAAwB,YAAY;AAE3C,MAAMC,cAAc;AACpB,MAAMC,UAAU;AAChB,MAAMC,qBAAqB,CAAC;AAC5B,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AACvB,MAAMC,gBAAgB;AACtB,MAAMC,QAAQ;AACd,OAAO,MAAMC,qBAAqB,IAAI;AACtC,OAAO,MAAMC,gBAAgB,IAAI;AACjC,OAAO,MAAMC,gBAAgB,OAAO;AACpC,MAAMC,qBAAqB;IAC1B,CAACH,mBAAmB,EAAE;IACtB,CAACC,cAAc,EAAE;AAClB;AACA,MAAMG,oBAAoB;IACzB,gCAAgC;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,mBAAmB;IACnB;IACA;IACA;IACA;IACA;IACA;IACA;IACA,cAAc;IACd;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,mBAAmB;IACnB;IACA;IACA;IACA;IACA;IACA;IACA;IACA,iBAAiB;IACjB;IACA;IACA;IACA,uBAAuB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACA;AAED,MAAMC,aAAa;IAClB,GAAG;AACJ;AAEA,MAAMC,SAAS;IACd,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,G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KAAK,CAAC;QAEnD,KAAK,MAAM,CAACC,YAAYC,KAAK,IAAIJ,OAAOK,OAAO,GAAI;YAClDd,UAAUC,SAAS,GAAG;YACtB,MAAMvB,SAA8BsB,UAAUE,IAAI,CAACW;YACnD,IAAI,CAACnC,QAAQ;gBACZ;YACD;YACA8B;YACA,IAAII,aAAa,GAAG;gBACnBL,MAAMQ,IAAI,CAAC,GAAGH,WAAW,EAAE,EAAE9F,MAAMkG,IAAI,CAACP,MAAM,CAACG,aAAa,EAAE,GAAG;YAClE;YACAL,MAAMQ,IAAI,CACT,GAAGH,aAAa,EAAE,EAAE,EAAE9F,MAAMkG,IAAI,CAC/BH,KAAKvE,OAAO,CAAC0D,WAAWlF,MAAMmG,KAAK,GAAGC,QAAQ,CAACxC,MAAM,CAAC,EAAE,KACtD,EACH,GAAGkC,aAAa,EAAE,EAAE,EAAE9F,MAAMkG,IAAI,CAACP,MAAM,CAACG,aAAa,EAAE,GAAG,EAC1D;QAEF;QACA,OAAO;YACNO,SAASZ,MAAMjD,MAAM,GAAG,IAAIiD,QAAQ,EAAE;YACtCC;QACD;IACD,EAAE,OAAOY,OAAO;QACf,kBAAkB,GAClBtF,OAAOsF,KAAK,CAACA;IACd;AACD,EAAE;AAEF,OAAO,SAASC,sBAAsBC,QAAgB;IACrD,MAAMC,MAAMpF,iBAAiBmF;IAC7B,8CAA8C;IAC9C,IAAI,CAACC,KAAK;QACT,OAAO;IACR;IACA,OAAO5F,kBAAkB6F,QAAQ,CAACD;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/search",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Search for files in a directory",
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"build:types": "tsc",
|
|
20
20
|
"clean": "rimraf dist types coverage",
|
|
21
21
|
"lint": "biome lint src",
|
|
22
|
-
"test": "
|
|
23
|
-
"test:coverage": "
|
|
22
|
+
"test": "vitest run --globals",
|
|
23
|
+
"test:coverage": "vitest run --coverage --globals",
|
|
24
24
|
"test:watch": "npm run test -- --watch",
|
|
25
25
|
"watch": "swc --strip-leading-paths --watch --out-dir dist src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@node-cli/logger": "1.3.
|
|
29
|
-
"@node-cli/parser": "2.4.
|
|
30
|
-
"@node-cli/perf": "1.0.
|
|
31
|
-
"@node-cli/run": "1.1.
|
|
28
|
+
"@node-cli/logger": "1.3.1",
|
|
29
|
+
"@node-cli/parser": "2.4.1",
|
|
30
|
+
"@node-cli/perf": "1.0.7",
|
|
31
|
+
"@node-cli/run": "1.1.3",
|
|
32
32
|
"fs-extra": "11.3.0",
|
|
33
33
|
"kleur": "4.1.5",
|
|
34
34
|
"micromatch": "4.0.8",
|
|
@@ -39,5 +39,9 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
44
|
+
"vitest": "3.2.4"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "2cef8f88aa5316a1789caad2bd7327ca908ccb9f"
|
|
43
47
|
}
|