@node-cli/search 1.0.0 → 1.0.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.d.ts CHANGED
@@ -28,8 +28,8 @@ export declare class Search {
28
28
  type?: string;
29
29
  });
30
30
  ignoreFolders(directory: string): boolean;
31
- filterHidden(value: string[]): boolean;
31
+ filterHidden(value: string[] | string): boolean;
32
32
  start(): Promise<void>;
33
- scanFileSystem(nodes: any): Promise<void>;
33
+ scanFileSystem(nodes: string[]): Promise<void>;
34
34
  postProcessResults(): Promise<void>;
35
35
  }
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core.ts"],"sourcesContent":["import {\n\tSTR_TYPE_BOTH,\n\tSTR_TYPE_DIRECTORY,\n\tSTR_TYPE_FILE,\n\tcheckPattern,\n\tformatLongListings,\n\tprintStatistics,\n\trunCommandOnNode,\n\trunGrepOnNode,\n} from \"./utilities.js\";\nimport { basename, join, relative } from \"node:path\";\n\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\";\nimport { promisify } from \"node:util\";\n\nconst lstatAsync = promisify(fs.lstat);\nconst readdirAsync = promisify(fs.readdir);\nconst perf = new Performance();\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nexport class Search {\n\tboring?: boolean;\n\tcommand?: string;\n\tdisplayHiddenFilesAndFolders?: boolean;\n\tdisplayLongListing?: boolean;\n\tdisplayStats?: boolean;\n\tfoldersBlacklist?: RegExp;\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\n\tconstructor({\n\t\tboring,\n\t\tcommand,\n\t\tdot,\n\t\tfoldersBlacklist,\n\t\tgrep,\n\t\tignoreCase,\n\t\tshort,\n\t\tpath,\n\t\tpattern,\n\t\tstats,\n\t\ttype,\n\t}: {\n\t\tboring?: boolean;\n\t\tcommand?: string;\n\t\tdot?: boolean;\n\t\tfoldersBlacklist?: RegExp;\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}) {\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.foldersBlacklist = foldersBlacklist;\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\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\t// eslint-disable-next-line unicorn/no-process-exit\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tignoreFolders(directory: string) {\n\t\tthis.foldersBlacklist.lastIndex = 0;\n\t\treturn this.foldersBlacklist.test(basename(directory));\n\t}\n\n\tfilterHidden(value: 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() {\n\t\tif (this.displayStats) {\n\t\t\tperf.start();\n\t\t}\n\t\tawait this.scanFileSystem([this.path]);\n\t\tawait this.postProcessResults();\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}\n\n\tasync scanFileSystem(nodes) {\n\t\tfor (const node of nodes) {\n\t\t\tlet result, files, shortname, stat;\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\tif (stat && stat.isDirectory() && !this.ignoreFolders(node)) {\n\t\t\t\tthis.totalDirScanned++;\n\n\t\t\t\tif ((result = checkPattern(this.rePattern, node))) {\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 (stat && stat.isFile()) {\n\t\t\t\tthis.totalFileScanned++;\n\t\t\t\tshortname = basename(node);\n\t\t\t\tif ((result = checkPattern(this.rePattern, shortname))) {\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: result[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 postProcessResults() {\n\t\t/* istanbul ignore if */\n\t\tif (!this.boring) {\n\t\t\tlogger.log();\n\t\t}\n\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\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(process.cwd(), node.name);\n\t\t\t\tconst match = node.match ? new RegExp(node.match, \"g\") : node.match;\n\t\t\t\tname = color(name.replace(match, kleur.black().bgYellow(node.match)));\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\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":["STR_TYPE_BOTH","STR_TYPE_DIRECTORY","STR_TYPE_FILE","checkPattern","formatLongListings","printStatistics","runCommandOnNode","runGrepOnNode","basename","join","relative","Logger","Performance","fs","kleur","plur","promisify","lstatAsync","lstat","readdirAsync","readdir","perf","logger","boring","process","env","NODE_ENV","Search","command","displayHiddenFilesAndFolders","displayLongListing","displayStats","foldersBlacklist","grep","nodesList","path","rePattern","totalDirFound","totalDirScanned","totalFileFound","totalFileScanned","type","constructor","dot","ignoreCase","short","pattern","stats","RegExp","undefined","enabled","trim","error","exit","ignoreFolders","directory","lastIndex","test","filterHidden","value","start","scanFileSystem","postProcessResults","stop","duration","results","totalDirsFound","totalFilesFound","nodes","node","result","files","shortname","stat","isDirectory","push","match","name","filter","element","map","file","isFile","log","list","group","mdate","mode","owner","size","separator","color","gray","blue","cwd","replace","black","bgYellow","totalMatchingLines","occurrences","white"],"mappings":"AAAA,SACCA,aAAa,EACbC,kBAAkB,EAClBC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,QACP,iBAAiB;AACxB,SAASC,QAAQ,EAAEC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAErD,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,OAAO;AACxB,SAASC,SAAS,QAAQ,YAAY;AAEtC,MAAMC,aAAaD,UAAUH,GAAGK;AAChC,MAAMC,eAAeH,UAAUH,GAAGO;AAClC,MAAMC,OAAO,IAAIT;AACjB,MAAMU,SAAS,IAAIX,OAAO;IACzBY,QAAQC,QAAQC,IAAIC,aAAa;AAClC;AAEA,OAAO,MAAMC;IACZJ,OAAiB;IACjBK,QAAiB;IACjBC,6BAAuC;IACvCC,mBAA6B;IAC7BC,aAAuB;IACvBC,iBAA0B;IAC1BC,KAAc;IACdC,UAAkB;IAClBC,KAAc;IACdC,UAAmB;IACnBC,cAAuB;IACvBC,gBAAyB;IACzBC,eAAwB;I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IAAI,CAAC3D;wBACL,MAAM4D,cAAcpF,KAAK,cAAcmF;wBACvC5E,OAAO6D,IACN,CAAC,GAAG,EAAEO,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,CAAC,EAC7DN,KAAKG,KAAKpC,QACViC,KAAKI,MAAMrC,QACXiC,KAAKK,KAAKtC,QACViC,KAAKE,OACLT,MACA,CAAC,CAAC,EAAE/D,MAAMsF,MAAMF,oBAAoB,CAAC,EAAEC,YAAY,CAAC,CAAC;wBAEtD7E,OAAO6D,IAAI,CAAC,EAAElB,QAAQxD,KAAK,MAAM,EAAE,CAAC;oBACrC;gBACD,OAAO;oBACN,wBAAwB,GACxB,IAAI,CAAC,IAAI,CAACwB,MAAM;wBACfX,OAAO6D,IACN,CAAC,GAAG,EAAEO,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,CAAC,EAC7DN,KAAKG,KAAKpC,QACViC,KAAKI,MAAMrC,QACXiC,KAAKK,KAAKtC,QACViC,KAAKE,OACLT;wBAED,IAAIR,KAAKzC,SAAS;4BACjB,MAAMtB,iBAAiB+D,KAAKQ,MAAMR,KAAKzC;wBACxC;oBACD;gBACD;YACD;QACD;IACD;AACD"}
1
+ {"version":3,"sources":["../src/core.ts"],"sourcesContent":["import {\n\tSTR_TYPE_BOTH,\n\tSTR_TYPE_DIRECTORY,\n\tSTR_TYPE_FILE,\n\tcheckPattern,\n\tformatLongListings,\n\tprintStatistics,\n\trunCommandOnNode,\n\trunGrepOnNode,\n} from \"./utilities.js\";\nimport { basename, join, relative } from \"node:path\";\n\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\";\nimport { promisify } from \"node:util\";\n\nconst lstatAsync = promisify(fs.lstat);\nconst readdirAsync = promisify(fs.readdir);\nconst perf = new Performance();\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nexport class Search {\n\tboring?: boolean;\n\tcommand?: string;\n\tdisplayHiddenFilesAndFolders?: boolean;\n\tdisplayLongListing?: boolean;\n\tdisplayStats?: boolean;\n\tfoldersBlacklist?: RegExp;\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\n\tconstructor({\n\t\tboring,\n\t\tcommand,\n\t\tdot,\n\t\tfoldersBlacklist,\n\t\tgrep,\n\t\tignoreCase,\n\t\tshort,\n\t\tpath,\n\t\tpattern,\n\t\tstats,\n\t\ttype,\n\t}: {\n\t\tboring?: boolean;\n\t\tcommand?: string;\n\t\tdot?: boolean;\n\t\tfoldersBlacklist?: RegExp;\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}) {\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.foldersBlacklist = foldersBlacklist;\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\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\t// eslint-disable-next-line unicorn/no-process-exit\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tignoreFolders(directory: string) {\n\t\tthis.foldersBlacklist.lastIndex = 0;\n\t\treturn this.foldersBlacklist.test(basename(directory));\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() {\n\t\tif (this.displayStats) {\n\t\t\tperf.start();\n\t\t}\n\t\tawait this.scanFileSystem([this.path]);\n\t\tawait this.postProcessResults();\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}\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\tif (stat && stat.isDirectory() && !this.ignoreFolders(node)) {\n\t\t\t\tthis.totalDirScanned++;\n\n\t\t\t\tif ((result = checkPattern(this.rePattern, node))) {\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 (stat && stat.isFile()) {\n\t\t\t\tthis.totalFileScanned++;\n\t\t\t\tshortname = basename(node);\n\t\t\t\tif ((result = checkPattern(this.rePattern, shortname))) {\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: result[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 postProcessResults() {\n\t\t/* istanbul ignore if */\n\t\tif (!this.boring) {\n\t\t\tlogger.log();\n\t\t}\n\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\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(process.cwd(), node.name);\n\t\t\t\tconst match = node.match ? new RegExp(node.match, \"g\") : node.match;\n\t\t\t\tname = color(name.replace(match, kleur.black().bgYellow(node.match)));\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\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":["STR_TYPE_BOTH","STR_TYPE_DIRECTORY","STR_TYPE_FILE","checkPattern","formatLongListings","printStatistics","runCommandOnNode","runGrepOnNode","basename","join","relative","Logger","Performance","fs","kleur","plur","promisify","lstatAsync","lstat","readdirAsync","readdir","perf","logger","boring","process","env","NODE_ENV","Search","command","displayHiddenFilesAndFolders","displayLongListing","displayStats","foldersBlacklist","grep","nodesList","path","rePattern","totalDirFound","totalDirScanned","totalFileFound","totalFileScanned","type","constructor","dot","ignoreCase","short","pattern","stats","RegExp","undefined","enabled","trim","error","exit","ignoreFolders","directory","lastIndex","test","filterHidden","value","start","scanFileSystem","postProcessResults","stop","duration","results","totalDirsFound","totalFilesFound","nodes","node","result","files","shortname","stat","isDirectory","push","match","name","filter","element","map","file","isFile","log","list","group","mdate","mode","owner","size","separator","color","gray","blue","cwd","replace","black","bgYellow","totalMatchingLines","occurrences","white"],"mappings":"AAAA,SACCA,aAAa,EACbC,kBAAkB,EAClBC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,QACP,iBAAiB;AACxB,SAASC,QAAQ,EAAEC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAErD,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,WAA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BACD;gBACD;YACD;QACD;IACD;AACD"}
package/dist/parse.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { defaultFlags, defaultParameters } from "./defaults.js";
2
2
  import { parser } from "@node-cli/parser";
3
3
  /* istanbul ignore next */ export const config = parser({
4
+ meta: import.meta,
4
5
  examples: [
5
6
  {
6
7
  command: 'search --type f --pattern ".jsx$" src/',
package/dist/parse.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { 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};\n\nexport type Parameters = {\n\tpath?: string;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n};\n\n/* istanbul ignore next */\nexport const config: Configuration = parser({\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},\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"],"names":["defaultFlags","defaultParameters","parser","config","examples","command","comment","flags","boring","shortFlag","default","description","type","dot","grep","help","ignoreCase","pattern","short","stats","version","parameters","path","usage"],"mappings":"AAAA,SAASA,YAAY,EAAEC,iBAAiB,QAAQ,gBAAgB;AAEhE,SAASC,MAAM,QAAQ,mBAAmB;AAqB1C,wBAAwB,GACxB,OAAO,MAAMC,SAAwBD,OAAO;IAC3CE,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,SAASV,aAAaQ;YACtBG,aAAa;YACbC,MAAM;QACP;QACAP,SAAS;YACRI,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAC,KAAK;YACJH,SAASV,aAAaa;YACtBF,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,SAASV,aAAagB;YACtBL,aAAa;YACbC,MAAM;QACP;QACAK,SAAS;YACRR,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAM,OAAO;YACNR,SAASV,aAAakB;YACtBP,aAAa;YACbC,MAAM;QACP;QACAO,OAAO;YACNV,WAAW;YACXC,SAASV,aAAamB;YACtBR,aAAa;YACbC,MAAM;QACP;QACAA,MAAM;YACLH,WAAW;YACXC,SAAS;YACTC,aAAa;YACbC,MAAM;QACP;QACAQ,SAAS;YACRX,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;IACD;IACAS,YAAY;QACXC,MAAM;YACLZ,SAAS;YACTC,aAAa;QACd;IACD;IACAY,OAAO;IACPvB;IACAC;AACD,GAAG"}
1
+ {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { 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};\n\nexport type Parameters = {\n\tpath?: string;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n};\n\n/* istanbul ignore next */\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},\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"],"names":["defaultFlags","defaultParameters","parser","config","meta","examples","command","comment","flags","boring","shortFlag","default","description","type","dot","grep","help","ignoreCase","pattern","short","stats","version","parameters","path","usage"],"mappings":"AAAA,SAASA,YAAY,EAAEC,iBAAiB,QAAQ,gBAAgB;AAEhE,SAASC,MAAM,QAAQ,mBAAmB;AAqB1C,wBAAwB,GACxB,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;YACtBG,aAAa;YACbC,MAAM;QACP;QACAP,SAAS;YACRI,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAC,KAAK;YACJH,SAASX,aAAac;YACtBF,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;YACtBL,aAAa;YACbC,MAAM;QACP;QACAK,SAAS;YACRR,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAM,OAAO;YACNR,SAASX,aAAamB;YACtBP,aAAa;YACbC,MAAM;QACP;QACAO,OAAO;YACNV,WAAW;YACXC,SAASX,aAAaoB;YACtBR,aAAa;YACbC,MAAM;QACP;QACAA,MAAM;YACLH,WAAW;YACXC,SAAS;YACTC,aAAa;YACbC,MAAM;QACP;QACAQ,SAAS;YACRX,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;IACD;IACAS,YAAY;QACXC,MAAM;YACLZ,SAAS;YACTC,aAAa;QACd;IACD;IACAY,OAAO;IACPxB;IACAC;AACD,GAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/search",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "Search for files in a directory",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@node-cli/logger": ">=1.0.0",
30
- "@node-cli/parser": ">=1.0.0",
30
+ "@node-cli/parser": ">=2.0.0",
31
31
  "@node-cli/perf": ">=1.0.0",
32
32
  "@node-cli/run": ">=1.0.0",
33
33
  "fs-extra": "11.1.1",
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "2e74543c37e77ca482acc9fda6d8716bc634e722"
41
+ "gitHead": "fd3f9b10e925e7a7803c4eb982f25709a140096d"
42
42
  }