@node-cli/search 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Arno Versini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Node CLI search package
2
+
3
+ ![npm](https://img.shields.io/npm/v/@node-cli/search?label=version&logo=npm)
4
+
5
+ > Search is a command line tool that can:
6
+ >
7
+ > - find files or folders that match a certain pattern
8
+ > - look for string within those files and display them (think shell commands "find" and "grep")
9
+
10
+ ## Installation
11
+
12
+ ```sh
13
+ > npm install --global @node-cli/search
14
+ ```
15
+
16
+ ## Examples
17
+
18
+ Find all files with the extension ".jsx" in the "src" folder
19
+
20
+ ```sh
21
+ > search --type f --pattern ".jsx$" src/
22
+ ```
23
+
24
+ Change the permissions to executable for all the files with the extension ".sh" found under the "bin" folder
25
+
26
+ ```sh
27
+ > search --type f --pattern ".sh$" --command "chmod +x" bin/
28
+ ```
29
+
30
+ Search in all the markdown files under the "src" folder for the keywords "Table of Content"
31
+
32
+ ```sh
33
+ > search --type f --pattern ".md$" --grep "Table of Content"
34
+ ```
35
+
36
+ Get help
37
+
38
+ ```sh
39
+ > search --help
40
+ ```
package/dist/core.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export declare class Search {
2
+ boring?: boolean;
3
+ command?: string;
4
+ displayHiddenFilesAndFolders?: boolean;
5
+ displayLongListing?: boolean;
6
+ displayStats?: boolean;
7
+ foldersBlacklist?: RegExp;
8
+ grep?: RegExp;
9
+ nodesList?: any[];
10
+ path?: string;
11
+ rePattern?: RegExp;
12
+ totalDirFound?: number;
13
+ totalDirScanned?: number;
14
+ totalFileFound?: number;
15
+ totalFileScanned?: number;
16
+ type?: string;
17
+ constructor({ boring, command, dot, foldersBlacklist, grep, ignoreCase, short, path, pattern, stats, type, }: {
18
+ boring?: boolean;
19
+ command?: string;
20
+ dot?: boolean;
21
+ foldersBlacklist?: RegExp;
22
+ grep?: string | RegExp;
23
+ ignoreCase?: boolean;
24
+ short?: boolean;
25
+ path?: string;
26
+ pattern?: string;
27
+ stats?: boolean;
28
+ type?: string;
29
+ });
30
+ ignoreFolders(directory: string): boolean;
31
+ filterHidden(value: string[]): boolean;
32
+ start(): Promise<void>;
33
+ scanFileSystem(nodes: any): Promise<void>;
34
+ postProcessResults(): Promise<void>;
35
+ }
package/dist/core.js ADDED
@@ -0,0 +1,180 @@
1
+ import { STR_TYPE_BOTH, STR_TYPE_DIRECTORY, STR_TYPE_FILE, checkPattern, formatLongListings, printStatistics, runCommandOnNode, runGrepOnNode } from "./utilities.js";
2
+ import { basename, join, relative } from "node:path";
3
+ import { Logger } from "@node-cli/logger";
4
+ import { Performance } from "@node-cli/perf";
5
+ import fs from "fs-extra";
6
+ import kleur from "kleur";
7
+ import plur from "plur";
8
+ import { promisify } from "node:util";
9
+ const lstatAsync = promisify(fs.lstat);
10
+ const readdirAsync = promisify(fs.readdir);
11
+ const perf = new Performance();
12
+ const logger = new Logger({
13
+ boring: process.env.NODE_ENV === "test"
14
+ });
15
+ export class Search {
16
+ boring;
17
+ command;
18
+ displayHiddenFilesAndFolders;
19
+ displayLongListing;
20
+ displayStats;
21
+ foldersBlacklist;
22
+ grep;
23
+ nodesList;
24
+ path;
25
+ rePattern;
26
+ totalDirFound;
27
+ totalDirScanned;
28
+ totalFileFound;
29
+ totalFileScanned;
30
+ type;
31
+ constructor({ boring , command , dot , foldersBlacklist , grep , ignoreCase , short , path , pattern , stats , type }){
32
+ this.path = path;
33
+ this.rePattern = pattern ? new RegExp(pattern, ignoreCase ? "i" : "") : undefined;
34
+ this.type = type || STR_TYPE_BOTH;
35
+ this.boring = boring;
36
+ kleur.enabled = !boring;
37
+ this.displayLongListing = !short;
38
+ this.displayStats = stats;
39
+ this.displayHiddenFilesAndFolders = dot;
40
+ this.nodesList = [];
41
+ this.foldersBlacklist = foldersBlacklist;
42
+ this.totalDirScanned = 0;
43
+ this.totalFileScanned = 0;
44
+ this.totalDirFound = 0;
45
+ this.totalFileFound = 0;
46
+ this.command = command ? command.trim() : undefined;
47
+ try {
48
+ this.grep = grep ? new RegExp(grep, ignoreCase ? "gi" : "g") : undefined;
49
+ } catch (error) {
50
+ logger.error(error);
51
+ // eslint-disable-next-line unicorn/no-process-exit
52
+ process.exit(1);
53
+ }
54
+ }
55
+ ignoreFolders(directory) {
56
+ this.foldersBlacklist.lastIndex = 0;
57
+ return this.foldersBlacklist.test(basename(directory));
58
+ }
59
+ filterHidden(value) {
60
+ if (this.displayHiddenFilesAndFolders) {
61
+ return true;
62
+ }
63
+ return value[0] !== ".";
64
+ }
65
+ async start() {
66
+ if (this.displayStats) {
67
+ perf.start();
68
+ }
69
+ await this.scanFileSystem([
70
+ this.path
71
+ ]);
72
+ await this.postProcessResults();
73
+ if (this.displayStats) {
74
+ perf.stop();
75
+ printStatistics({
76
+ duration: perf.results.duration,
77
+ grep: this.grep,
78
+ pattern: this.rePattern,
79
+ totalDirScanned: this.totalDirScanned,
80
+ totalDirsFound: this.totalDirFound,
81
+ totalFileScanned: this.totalFileScanned,
82
+ totalFilesFound: this.totalFileFound,
83
+ type: this.type
84
+ });
85
+ }
86
+ }
87
+ async scanFileSystem(nodes) {
88
+ for (const node of nodes){
89
+ let result, files, shortname, stat;
90
+ try {
91
+ stat = await lstatAsync(node);
92
+ } catch {
93
+ // ignore read permission denied errors silently...
94
+ }
95
+ if (stat && stat.isDirectory() && !this.ignoreFolders(node)) {
96
+ this.totalDirScanned++;
97
+ if (result = checkPattern(this.rePattern, node)) {
98
+ this.totalDirFound++;
99
+ this.nodesList.push({
100
+ command: this.command,
101
+ match: result,
102
+ name: node,
103
+ stat,
104
+ type: STR_TYPE_DIRECTORY
105
+ });
106
+ }
107
+ try {
108
+ files = await readdirAsync(node);
109
+ await this.scanFileSystem(files.filter((element)=>this.filterHidden(element)).map(function(file) {
110
+ return join(node, file);
111
+ }));
112
+ } catch {
113
+ // nothing to declare
114
+ }
115
+ } else if (stat && stat.isFile()) {
116
+ this.totalFileScanned++;
117
+ shortname = basename(node);
118
+ if (result = checkPattern(this.rePattern, shortname)) {
119
+ this.totalFileFound++;
120
+ this.nodesList.push({
121
+ command: this.command,
122
+ match: result[0],
123
+ name: node,
124
+ stat,
125
+ type: STR_TYPE_FILE
126
+ });
127
+ }
128
+ }
129
+ }
130
+ }
131
+ async postProcessResults() {
132
+ /* istanbul ignore if */ if (!this.boring) {
133
+ logger.log();
134
+ }
135
+ if (this.grep) {
136
+ /**
137
+ * Resetting the number of files found, since we want to
138
+ * show how many matched the grep, not how many matched the
139
+ * pattern (in the file name).
140
+ */ this.totalFileFound = 0;
141
+ }
142
+ for (const node of this.nodesList){
143
+ if (this.type === STR_TYPE_FILE && node.type === STR_TYPE_FILE || this.type === STR_TYPE_DIRECTORY && node.type === STR_TYPE_DIRECTORY || this.type === STR_TYPE_BOTH) {
144
+ let list = {
145
+ group: "",
146
+ mdate: "",
147
+ mode: "",
148
+ owner: "",
149
+ size: ""
150
+ }, name, separator = "";
151
+ /* istanbul ignore if */ if (this.displayLongListing) {
152
+ list = await formatLongListings(node.stat, node.type);
153
+ separator = "\t";
154
+ }
155
+ const color = node.type === STR_TYPE_FILE ? kleur.gray : kleur.blue;
156
+ name = relative(process.cwd(), node.name);
157
+ const match = node.match ? new RegExp(node.match, "g") : node.match;
158
+ name = color(name.replace(match, kleur.black().bgYellow(node.match)));
159
+ if (this.grep && node.type === STR_TYPE_FILE) {
160
+ const { totalMatchingLines , results } = await runGrepOnNode(node.name, this.grep);
161
+ /* istanbul ignore else */ if (totalMatchingLines) {
162
+ this.totalFileFound++;
163
+ const occurrences = plur("occurrence", totalMatchingLines);
164
+ 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})`);
165
+ logger.log(`${results.join("\n")}\n`);
166
+ }
167
+ } else {
168
+ /* istanbul ignore next */ if (!this.grep) {
169
+ logger.log(` %s${separator}%s${separator}%s${separator}%s${separator}%s`, list.mode.trim(), list.owner.trim(), list.size.trim(), list.mdate, name);
170
+ if (node.command) {
171
+ await runCommandOnNode(node.name, node.command);
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ //# sourceMappingURL=core.js.map
@@ -0,0 +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,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B,MAAMtB,iBAAiB+D,KAAKQ,MAAMR,KAAKzC;wBACxC;oBACD;gBACD;YACD;QACD;IACD;AACD"}
@@ -0,0 +1,10 @@
1
+ export declare const defaultFlags: {
2
+ boring: boolean;
3
+ dot: boolean;
4
+ ignoreCase: boolean;
5
+ short: boolean;
6
+ stats: boolean;
7
+ };
8
+ export declare const defaultParameters: {
9
+ "0": string;
10
+ };
@@ -0,0 +1,12 @@
1
+ export const defaultFlags = {
2
+ boring: false,
3
+ dot: false,
4
+ ignoreCase: false,
5
+ short: false,
6
+ stats: false
7
+ };
8
+ export const defaultParameters = {
9
+ "0": process.cwd()
10
+ };
11
+
12
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaultFlags = {\n\tboring: false,\n\tdot: false,\n\tignoreCase: false,\n\tshort: false,\n\tstats: false,\n};\n\nexport const defaultParameters = {\n\t\"0\": process.cwd(),\n};\n"],"names":["defaultFlags","boring","dot","ignoreCase","short","stats","defaultParameters","process","cwd"],"mappings":"AAAA,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,KAAK;IACLC,YAAY;IACZC,OAAO;IACPC,OAAO;AACR,EAAE;AAEF,OAAO,MAAMC,oBAAoB;IAChC,KAAKC,QAAQC;AACd,EAAE"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+
5
+ export * from "./core";
6
+ export * from "./defaults";
7
+ export * from "./parse";
8
+ export * from "./search";
9
+ export * from "./utilities";
@@ -0,0 +1,17 @@
1
+ export type Flags = {
2
+ boring?: boolean;
3
+ dot?: boolean;
4
+ ignoreCase?: boolean;
5
+ short?: boolean;
6
+ stats?: boolean;
7
+ grep?: string;
8
+ type?: string;
9
+ };
10
+ export type Parameters = {
11
+ path?: string;
12
+ };
13
+ export type Configuration = {
14
+ flags?: Flags;
15
+ parameters?: Parameters;
16
+ };
17
+ export declare const config: Configuration;
package/dist/parse.js ADDED
@@ -0,0 +1,90 @@
1
+ import { defaultFlags, defaultParameters } from "./defaults.js";
2
+ import { parser } from "@node-cli/parser";
3
+ /* istanbul ignore next */ export const config = parser({
4
+ examples: [
5
+ {
6
+ command: 'search --type f --pattern ".jsx$" src/',
7
+ comment: '## Find all files with the extension ".jsx" in the "src" folder'
8
+ },
9
+ {
10
+ command: 'search --type f --pattern ".sh$" --command "chmod +x" bin/',
11
+ comment: `## Change the permissions to executable for all the files with\n ## the extension ".sh" found under the "bin" folder`
12
+ },
13
+ {
14
+ command: 'search --type f --pattern ".md$" --grep "Table of Content"',
15
+ comment: `## Search in all the markdown files under the "src" folder for\n ## the keywords "Table of Content"`
16
+ }
17
+ ],
18
+ flags: {
19
+ boring: {
20
+ shortFlag: "b",
21
+ default: defaultFlags.boring,
22
+ description: "Do not use color output",
23
+ type: "boolean"
24
+ },
25
+ command: {
26
+ shortFlag: "c",
27
+ description: "Command to execute over each node (ex: chmod +x)",
28
+ type: "string"
29
+ },
30
+ dot: {
31
+ default: defaultFlags.dot,
32
+ description: "Show hidden files and directories",
33
+ type: "boolean"
34
+ },
35
+ grep: {
36
+ shortFlag: "g",
37
+ description: "A RegExp to match the content of the files found",
38
+ type: "string"
39
+ },
40
+ help: {
41
+ shortFlag: "h",
42
+ description: "Display help instructions",
43
+ type: "boolean"
44
+ },
45
+ ignoreCase: {
46
+ shortFlag: "i",
47
+ default: defaultFlags.ignoreCase,
48
+ description: "Ignore case when searching",
49
+ type: "boolean"
50
+ },
51
+ pattern: {
52
+ shortFlag: "p",
53
+ description: "A regular expression to match file or folder names",
54
+ type: "string"
55
+ },
56
+ short: {
57
+ default: defaultFlags.short,
58
+ description: "Short listing format (equivalent to ls)",
59
+ type: "boolean"
60
+ },
61
+ stats: {
62
+ shortFlag: "s",
63
+ default: defaultFlags.stats,
64
+ description: "Display some statistics",
65
+ type: "boolean"
66
+ },
67
+ type: {
68
+ shortFlag: "t",
69
+ default: "both",
70
+ description: "Search for files (f) or directories (d)",
71
+ type: "string"
72
+ },
73
+ version: {
74
+ shortFlag: "v",
75
+ description: "Output the current version",
76
+ type: "boolean"
77
+ }
78
+ },
79
+ parameters: {
80
+ path: {
81
+ default: "current folder",
82
+ description: "the path where to start the search"
83
+ }
84
+ },
85
+ usage: "search [options] [path]",
86
+ defaultFlags,
87
+ defaultParameters
88
+ });
89
+
90
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/search.js ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ /* istanbul ignore file */ import { Logger } from "@node-cli/logger";
3
+ import { STR_TYPE_FILE } from "./utilities.js";
4
+ import { Search } from "./core.js";
5
+ import { config } from "./parse.js";
6
+ import fs from "fs-extra";
7
+ import path from "node:path";
8
+ const logger = new Logger({
9
+ boring: process.env.NODE_ENV === "test"
10
+ });
11
+ let customPath = config.parameters[0];
12
+ if (fs.pathExistsSync(customPath)) {
13
+ customPath = path.resolve(customPath);
14
+ } else {
15
+ logger.printErrorsAndExit([
16
+ `Folder ${customPath} does not exist!`
17
+ ], 0);
18
+ }
19
+ if (config.flags.grep) {
20
+ // forcing simplified display if grep is true.
21
+ config.flags.short = true;
22
+ // And forcing type to files
23
+ config.flags.type = STR_TYPE_FILE;
24
+ }
25
+ const search = new Search({
26
+ ...config.flags,
27
+ path: customPath,
28
+ foldersBlacklist: /node_modules/gi
29
+ });
30
+ await search.start();
31
+
32
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/search.ts"],"sourcesContent":["#!/usr/bin/env node\n/* istanbul ignore file */\n\nimport { Logger } from \"@node-cli/logger\";\nimport { STR_TYPE_FILE } from \"./utilities.js\";\nimport { Search } from \"./core.js\";\nimport { config } from \"./parse.js\";\nimport fs from \"fs-extra\";\nimport path from \"node:path\";\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\tfoldersBlacklist: /node_modules/gi,\n});\n\nawait search.start();\n"],"names":["Logger","STR_TYPE_FILE","Search","config","fs","path","logger","boring","process","env","NODE_ENV","customPath","parameters","pathExistsSync","resolve","printErrorsAndExit","flags","grep","short","type","search","foldersBlacklist","start"],"mappings":";AACA,wBAAwB,GAExB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,UAAU,YAAY;AAE7B,MAAMC,SAAS,IAAIN,OAAO;IACzBO,QAAQC,QAAQC,IAAIC,aAAa;AAClC;AAEA,IAAIC,aAAaR,OAAOS,UAAU,CAAC,EAAE;AACrC,IAAIR,GAAGS,eAAeF,aAAa;IAClCA,aAAaN,KAAKS,QAAQH;AAC3B,OAAO;IACNL,OAAOS,mBAAmB;QAAC,CAAC,OAAO,EAAEJ,WAAW,gBAAgB,CAAC;KAAC,EAAE;AACrE;AAEA,IAAIR,OAAOa,MAAMC,MAAM;IACtB,8CAA8C;IAC9Cd,OAAOa,MAAME,QAAQ;IACrB,4BAA4B;IAC5Bf,OAAOa,MAAMG,OAAOlB;AACrB;AAEA,MAAMmB,SAAS,IAAIlB,OAAO;IACzB,GAAGC,OAAOa,KAAK;IACfX,MAAMM;IACNU,kBAAkB;AACnB;AAEA,MAAMD,OAAOE"}
@@ -0,0 +1,36 @@
1
+ export declare const STR_TYPE_DIRECTORY = "d";
2
+ export declare const STR_TYPE_FILE = "f";
3
+ export declare const STR_TYPE_BOTH = "both";
4
+ export declare const extractMode: (mode: number) => string;
5
+ export declare const convertSize: (bytes: number) => string;
6
+ export declare const convertDate: (mtime: Date) => string;
7
+ export declare const getOwnerNameFromId: (uid: string | number) => Promise<string | number>;
8
+ export declare const formatLongListings: (stat: {
9
+ mtime: Date;
10
+ mode: number;
11
+ uid: string | number;
12
+ size: number;
13
+ }, type: string) => Promise<{
14
+ mdate: string;
15
+ mode: string;
16
+ owner: string;
17
+ size: string;
18
+ }>;
19
+ export type Statistics = {
20
+ duration?: number;
21
+ totalDirScanned?: number;
22
+ totalDirsFound?: number;
23
+ totalFileScanned?: number;
24
+ totalFilesFound?: number;
25
+ type?: string;
26
+ pattern?: boolean | RegExp;
27
+ grep?: boolean | RegExp | string;
28
+ };
29
+ export declare const printStatistics: ({ duration, totalDirScanned, totalDirsFound, totalFileScanned, totalFilesFound, type, pattern, grep, }: Statistics) => void;
30
+ export declare const checkPattern: (rePattern: RegExp | undefined, string_: string) => boolean | RegExpExecArray;
31
+ export declare const runCommandOnNode: (node: string, command: string) => Promise<void>;
32
+ export type RunGrepOnNode = {
33
+ results: (string | number)[];
34
+ totalMatchingLines: number;
35
+ };
36
+ export declare const runGrepOnNode: (node?: string, rePattern?: RegExp) => Promise<RunGrepOnNode>;
@@ -0,0 +1,176 @@
1
+ import { run } from "@node-cli/run";
2
+ import { Logger } from "@node-cli/logger";
3
+ import fs from "node:fs";
4
+ import kleur from "kleur";
5
+ import prettyMilliseconds from "pretty-ms";
6
+ const BYTE_CHUNKS = 1000;
7
+ const DECIMAL = 10;
8
+ const LAST_THREE_ENTRIES = -3;
9
+ const MODE_GROUP_POS = 1;
10
+ const MODE_OWNER_POS = 0;
11
+ const MODE_WORD_POS = 2;
12
+ const OCTAL = 8;
13
+ export const STR_TYPE_DIRECTORY = "d";
14
+ export const STR_TYPE_FILE = "f";
15
+ export const STR_TYPE_BOTH = "both";
16
+ const PERMISSIONS_PREFIX = {
17
+ [STR_TYPE_DIRECTORY]: "d",
18
+ [STR_TYPE_FILE]: "-"
19
+ };
20
+ const ownerNames = {
21
+ 0: "root"
22
+ };
23
+ const MONTHS = {
24
+ 0: "Jan",
25
+ 1: "Feb",
26
+ 2: "Mar",
27
+ 3: "Apr",
28
+ 4: "May",
29
+ 5: "Jun",
30
+ 6: "Jul",
31
+ 7: "Aug",
32
+ 8: "Sep",
33
+ 9: "Oct",
34
+ 10: "Nov",
35
+ 11: "Dec"
36
+ };
37
+ const logger = new Logger({
38
+ boring: process.env.NODE_ENV === "test"
39
+ });
40
+ export const extractMode = (mode)=>{
41
+ const modeDec = Number.parseInt(mode.toString(OCTAL), DECIMAL).toString().slice(LAST_THREE_ENTRIES);
42
+ const modeOwner = modeDec.charAt(MODE_OWNER_POS);
43
+ const modeGroup = modeDec.charAt(MODE_GROUP_POS);
44
+ const modeWorld = modeDec.charAt(MODE_WORD_POS);
45
+ const modes = {
46
+ 0: "---",
47
+ 1: "--x",
48
+ 2: "-w-",
49
+ 3: "-wx",
50
+ 4: "r--",
51
+ 5: "r-x",
52
+ 6: "rw-",
53
+ 7: "rwx"
54
+ };
55
+ return modes[modeOwner] + modes[modeGroup] + modes[modeWorld];
56
+ };
57
+ export const convertSize = (bytes)=>{
58
+ const sizes = [
59
+ "B",
60
+ "K",
61
+ "M",
62
+ "G",
63
+ "T"
64
+ ];
65
+ const length = 5;
66
+ let posttxt = 0;
67
+ while(bytes >= BYTE_CHUNKS){
68
+ posttxt = posttxt + 1;
69
+ bytes = bytes / BYTE_CHUNKS;
70
+ }
71
+ const string_ = Number.parseInt(bytes.toString(), DECIMAL).toFixed(0) + sizes[posttxt];
72
+ return Array.from({
73
+ length: length + 1 - string_.length
74
+ }).join(" ") + string_;
75
+ };
76
+ export const convertDate = (mtime)=>{
77
+ const month = MONTHS[mtime.getMonth()];
78
+ const date = `${mtime.getDate()}`.padStart(2, "0");
79
+ const hours = `${mtime.getHours()}`.padStart(2, "0");
80
+ const minutes = `${mtime.getMinutes()}`.padStart(2, "0");
81
+ return `${month} ${date} ${hours}:${minutes}`;
82
+ };
83
+ export const getOwnerNameFromId = async (uid)=>{
84
+ let result;
85
+ /* istanbul ignore else */ if (ownerNames[uid]) {
86
+ return ownerNames[uid];
87
+ } else {
88
+ try {
89
+ result = await run(`id -nu ${uid}`);
90
+ ownerNames[uid] = result.stdout;
91
+ return result.stdout;
92
+ } catch {
93
+ // nothing to declare officer
94
+ return `${uid}`;
95
+ }
96
+ }
97
+ };
98
+ export const formatLongListings = async (stat, type)=>({
99
+ mdate: `${convertDate(stat.mtime)}`,
100
+ mode: PERMISSIONS_PREFIX[type] + extractMode(stat.mode),
101
+ owner: `${await getOwnerNameFromId(stat.uid)}`,
102
+ size: `${convertSize(stat.size)}`
103
+ });
104
+ export const printStatistics = ({ duration , totalDirScanned , totalDirsFound , totalFileScanned , totalFilesFound , type , pattern , grep })=>{
105
+ let message = `Total folders scanned: ${kleur.yellow(totalDirScanned)}\n`;
106
+ message += `Total files scanned: ${kleur.yellow(totalFileScanned)}\n`;
107
+ switch(type){
108
+ case STR_TYPE_DIRECTORY:
109
+ {
110
+ message += `Total folders matching: ${kleur.green(totalDirsFound)}\n`;
111
+ break;
112
+ }
113
+ case STR_TYPE_FILE:
114
+ {
115
+ message += `Total files matching: ${kleur.green(totalFilesFound)}\n`;
116
+ break;
117
+ }
118
+ default:
119
+ {
120
+ if (pattern) {
121
+ message += `Total folders matching: ${kleur.green(totalDirsFound)}\n`;
122
+ message += `Total files matching: ${kleur.green(totalFilesFound)}\n`;
123
+ }
124
+ break;
125
+ }
126
+ }
127
+ message += `Duration: ${kleur.yellow(`${prettyMilliseconds(duration)}`)}`;
128
+ if (!grep) {
129
+ logger.log();
130
+ }
131
+ logger.printBox(message);
132
+ };
133
+ export const checkPattern = (rePattern, string_)=>{
134
+ if (rePattern) {
135
+ rePattern.lastIndex = 0;
136
+ return rePattern.exec(string_);
137
+ }
138
+ return true;
139
+ };
140
+ export const runCommandOnNode = async (node, command)=>{
141
+ try {
142
+ const { stdout } = await run(`${command} ${node}`);
143
+ if (stdout) {
144
+ logger.log(stdout);
145
+ }
146
+ } catch {
147
+ // nothing to declare officer
148
+ }
149
+ };
150
+ export const runGrepOnNode = async (node, rePattern)=>{
151
+ try {
152
+ const lines = [];
153
+ let totalMatchingLines = 0;
154
+ const buffer = fs.readFileSync(node, "utf8").split("\n");
155
+ for (const [lineNumber, line] of buffer.entries()){
156
+ let result;
157
+ rePattern.lastIndex = 0;
158
+ if (!(result = rePattern.exec(line))) {
159
+ continue;
160
+ }
161
+ totalMatchingLines++;
162
+ if (lineNumber > 0) {
163
+ lines.push(`${lineNumber}: ${kleur.grey(buffer[lineNumber - 1])}`);
164
+ }
165
+ lines.push(`${lineNumber + 1}: ${kleur.grey(line.replace(rePattern, kleur.black().bgYellow(result[0])))}`, `${lineNumber + 2}: ${kleur.grey(buffer[lineNumber + 1])}`, "");
166
+ }
167
+ return {
168
+ results: lines.length > 0 ? lines : [],
169
+ totalMatchingLines
170
+ };
171
+ } catch (error) {
172
+ /* istanbul ignore next */ logger.error(error);
173
+ }
174
+ };
175
+
176
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { RunResult, run } from \"@node-cli/run\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"node:fs\";\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};\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 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\tlet result: (string | number)[];\n\t\t\trePattern.lastIndex = 0;\n\t\t\tif (!(result = rePattern.exec(line))) {\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"],"names":["run","Logger","fs","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","ownerNames","MONTHS","logger","boring","process","env","NODE_ENV","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","replace","black","bgYellow","results","error"],"mappings":"AAAA,SAAoBA,GAAG,QAAQ,gBAAgB;AAE/C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,UAAU;AACzB,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;AAEA,MAAMG,aAAa;IAClB,GAAG;AACJ;AAEA,MAAMC,SAAS;IACd,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,IAAI;IACJ,IAAI;AACL;AAEA,MAAMC,SAAS,IAAIjB,OAAO;IACzBkB,QAAQC,QAAQC,IAAIC,aAAa;AAClC;AAEA,OAAO,MAAMC,cAAc,CAACC;IAC3B,MAAMC,UAAUC,OAAOC,SAASH,KAAKI,SAASjB,QAAQL,SACpDsB,WACAC,M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AC,EAAE,IACvD,CAAC,EACH,CAAC,EAAEkC,aAAa,EAAE,EAAE,EAAEzF,MAAM6F,KAAKP,MAAM,CAACG,aAAa,EAAE,EAAE,CAAC,EAC1D;QAEF;QACA,OAAO;YACNQ,SAASb,MAAMjD,SAAS,IAAIiD,QAAQ,EAAE;YACtCC;QACD;IACD,EAAE,OAAOa,OAAO;QACf,wBAAwB,GACxBnF,OAAOmF,MAAMA;IACd;AACD,EAAE"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@node-cli/search",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "author": "Arno Versini",
6
+ "description": "Search for files in a directory",
7
+ "type": "module",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": "./dist/search.js",
10
+ "bin": {
11
+ "search": "dist/search.js"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "node": ">=16",
17
+ "scripts": {
18
+ "build": "yarn run clean && yarn run build:types && yarn run build:js && yarn run build:barrel",
19
+ "build:barrel": "barrelsby --delete --directory dist --pattern \"**/*.d.ts\" --name \"index.d\"",
20
+ "build:js": "swc --source-maps --out-dir dist src",
21
+ "build:types": "tsc",
22
+ "clean": "rimraf dist types coverage",
23
+ "lint": "prettier --write \"src/*.ts\" && eslint --fix \"src/*.ts\"",
24
+ "test": "cross-env-shell NODE_OPTIONS=--experimental-vm-modules TZ=UTC jest",
25
+ "test:coverage": "npm run test -- --coverage",
26
+ "watch": "swc --watch --out-dir dist src"
27
+ },
28
+ "dependencies": {
29
+ "@node-cli/logger": ">=1.0.0",
30
+ "@node-cli/parser": ">=1.0.0",
31
+ "@node-cli/perf": ">=1.0.0",
32
+ "@node-cli/run": ">=1.0.0",
33
+ "fs-extra": "11.1.1",
34
+ "kleur": "4.1.5",
35
+ "plur": "5.1.0",
36
+ "pretty-ms": "8.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "gitHead": "2e74543c37e77ca482acc9fda6d8716bc634e722"
42
+ }