@node-cli/search 3.0.1 → 3.1.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/dist/core.d.ts +3 -2
- package/dist/core.js +23 -82
- package/dist/core.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/minifiers.d.ts +4 -0
- package/dist/minifiers.js +110 -0
- package/dist/minifiers.js.map +1 -0
- package/dist/utilities.d.ts +2 -0
- package/dist/utilities.js +69 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +4 -3
package/dist/core.d.ts
CHANGED
|
@@ -20,7 +20,8 @@ export declare class Search {
|
|
|
20
20
|
printMode?: string;
|
|
21
21
|
gitIgnoreHandler: GitIgnoreHandler;
|
|
22
22
|
ignoreGitIgnore?: boolean;
|
|
23
|
-
|
|
23
|
+
minifyForLLM?: boolean;
|
|
24
|
+
constructor({ boring, command, dot, grep, ignoreCase, short, path, pattern, stats, type, ignoreExtension, ignoreFile, ignoreFolder, printMode, ignoreGitIgnore, minifyForLLM, }: {
|
|
24
25
|
boring?: boolean;
|
|
25
26
|
command?: string;
|
|
26
27
|
dot?: boolean;
|
|
@@ -36,11 +37,11 @@ export declare class Search {
|
|
|
36
37
|
ignoreFolder?: string[];
|
|
37
38
|
printMode?: string;
|
|
38
39
|
ignoreGitIgnore?: boolean;
|
|
40
|
+
minifyForLLM?: boolean;
|
|
39
41
|
});
|
|
40
42
|
shouldIgnoreFolder(directory: string): boolean;
|
|
41
43
|
shouldIgnoreFile(filePath: string): boolean;
|
|
42
44
|
filterHidden(value: string[] | string): boolean;
|
|
43
|
-
isBinaryFileExtension(filePath: string): boolean;
|
|
44
45
|
start(returnResults?: boolean): Promise<string>;
|
|
45
46
|
scanFileSystem(nodes: string[]): Promise<void>;
|
|
46
47
|
readFileContent(filePath: string): Promise<string>;
|
package/dist/core.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { basename,
|
|
2
|
-
import { GitIgnoreHandler } from "./gitIgnoreHandler.js";
|
|
3
|
-
import { STR_TYPE_BOTH, STR_TYPE_DIRECTORY, STR_TYPE_FILE, checkPattern, formatLongListings, printStatistics, runCommandOnNode, runGrepOnNode } from "./utilities.js";
|
|
1
|
+
import { basename, join, relative } from "node:path";
|
|
4
2
|
import { promisify } from "node:util";
|
|
5
3
|
import { Logger } from "@node-cli/logger";
|
|
6
4
|
import { Performance } from "@node-cli/perf";
|
|
7
5
|
import fs from "fs-extra";
|
|
8
6
|
import kleur from "kleur";
|
|
9
7
|
import plur from "plur";
|
|
8
|
+
import { GitIgnoreHandler } from "./gitIgnoreHandler.js";
|
|
9
|
+
import { minifyFileContent } from "./minifiers.js";
|
|
10
|
+
import { STR_TYPE_BOTH, STR_TYPE_DIRECTORY, STR_TYPE_FILE, checkPattern, formatLongListings, getFileExtension, isBinaryFileExtension, printStatistics, runCommandOnNode, runGrepOnNode } from "./utilities.js";
|
|
10
11
|
const lstatAsync = promisify(fs.lstat);
|
|
11
12
|
const readdirAsync = promisify(fs.readdir);
|
|
12
13
|
const readFileAsync = promisify(fs.readFile);
|
|
@@ -38,7 +39,8 @@ export class Search {
|
|
|
38
39
|
printMode;
|
|
39
40
|
gitIgnoreHandler;
|
|
40
41
|
ignoreGitIgnore;
|
|
41
|
-
|
|
42
|
+
minifyForLLM;
|
|
43
|
+
constructor({ boring, command, dot, grep, ignoreCase, short, path, pattern, stats, type, ignoreExtension, ignoreFile, ignoreFolder, printMode, ignoreGitIgnore, minifyForLLM }){
|
|
42
44
|
this.path = path;
|
|
43
45
|
this.rePattern = pattern ? new RegExp(pattern, ignoreCase ? "i" : "") : undefined;
|
|
44
46
|
this.type = type || STR_TYPE_BOTH;
|
|
@@ -58,6 +60,7 @@ export class Search {
|
|
|
58
60
|
this.ignoreFolders = ignoreFolder || [];
|
|
59
61
|
this.printMode = printMode;
|
|
60
62
|
this.ignoreGitIgnore = ignoreGitIgnore;
|
|
63
|
+
this.minifyForLLM = minifyForLLM;
|
|
61
64
|
this.gitIgnoreHandler = new GitIgnoreHandler();
|
|
62
65
|
try {
|
|
63
66
|
this.grep = grep ? new RegExp(grep, ignoreCase ? "gi" : "g") : undefined;
|
|
@@ -84,7 +87,7 @@ export class Search {
|
|
|
84
87
|
if (!this.ignoreExtensions || this.ignoreExtensions.length === 0) {
|
|
85
88
|
return false;
|
|
86
89
|
}
|
|
87
|
-
const extension =
|
|
90
|
+
const extension = getFileExtension(filePath);
|
|
88
91
|
// Check for exact extension match
|
|
89
92
|
if (this.ignoreExtensions.includes(extension)) {
|
|
90
93
|
return true;
|
|
@@ -108,70 +111,6 @@ export class Search {
|
|
|
108
111
|
}
|
|
109
112
|
return value[0] !== ".";
|
|
110
113
|
}
|
|
111
|
-
isBinaryFileExtension(filePath) {
|
|
112
|
-
const ext = extname(filePath).toLowerCase().replace(/^\./, "");
|
|
113
|
-
// If there's no extension, assume it's binary
|
|
114
|
-
/* istanbul ignore if */ if (!ext) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
const binaryExtensions = [
|
|
118
|
-
// Executables and compiled code
|
|
119
|
-
"exe",
|
|
120
|
-
"dll",
|
|
121
|
-
"so",
|
|
122
|
-
"dylib",
|
|
123
|
-
"bin",
|
|
124
|
-
"obj",
|
|
125
|
-
"o",
|
|
126
|
-
// Compressed files
|
|
127
|
-
"zip",
|
|
128
|
-
"tar",
|
|
129
|
-
"gz",
|
|
130
|
-
"rar",
|
|
131
|
-
"7z",
|
|
132
|
-
"jar",
|
|
133
|
-
"war",
|
|
134
|
-
// Media files
|
|
135
|
-
"jpg",
|
|
136
|
-
"jpeg",
|
|
137
|
-
"png",
|
|
138
|
-
"gif",
|
|
139
|
-
"bmp",
|
|
140
|
-
"ico",
|
|
141
|
-
"tif",
|
|
142
|
-
"tiff",
|
|
143
|
-
"mp3",
|
|
144
|
-
"mp4",
|
|
145
|
-
"avi",
|
|
146
|
-
"mov",
|
|
147
|
-
"wmv",
|
|
148
|
-
"flv",
|
|
149
|
-
"wav",
|
|
150
|
-
"ogg",
|
|
151
|
-
// Document formats
|
|
152
|
-
"pdf",
|
|
153
|
-
"doc",
|
|
154
|
-
"docx",
|
|
155
|
-
"xls",
|
|
156
|
-
"xlsx",
|
|
157
|
-
"ppt",
|
|
158
|
-
"pptx",
|
|
159
|
-
// Database files
|
|
160
|
-
"db",
|
|
161
|
-
"sqlite",
|
|
162
|
-
"mdb",
|
|
163
|
-
// Other binary formats
|
|
164
|
-
"class",
|
|
165
|
-
"pyc",
|
|
166
|
-
"pyd",
|
|
167
|
-
"pyo",
|
|
168
|
-
"woff",
|
|
169
|
-
"woff2",
|
|
170
|
-
"ttf",
|
|
171
|
-
"otf"
|
|
172
|
-
];
|
|
173
|
-
return binaryExtensions.includes(ext);
|
|
174
|
-
}
|
|
175
114
|
async start(returnResults = false) {
|
|
176
115
|
if (this.displayStats) {
|
|
177
116
|
perf.start();
|
|
@@ -254,13 +193,13 @@ export class Search {
|
|
|
254
193
|
async readFileContent(filePath) {
|
|
255
194
|
try {
|
|
256
195
|
// Check if it's a known binary extension
|
|
257
|
-
/* istanbul ignore if */ if (
|
|
258
|
-
return
|
|
196
|
+
/* istanbul ignore if */ if (isBinaryFileExtension(filePath)) {
|
|
197
|
+
return null;
|
|
259
198
|
}
|
|
260
199
|
const content = await readFileAsync(filePath, "utf8");
|
|
261
|
-
return content;
|
|
262
|
-
} catch (
|
|
263
|
-
/* istanbul ignore next */ return
|
|
200
|
+
return this.minifyForLLM ? await minifyFileContent(filePath, content) : content;
|
|
201
|
+
} catch (_error) {
|
|
202
|
+
/* istanbul ignore next */ return null;
|
|
264
203
|
}
|
|
265
204
|
}
|
|
266
205
|
async printFilesContent(returnResults) {
|
|
@@ -299,13 +238,15 @@ export class Search {
|
|
|
299
238
|
const relativePath = relative(this.path, node.name);
|
|
300
239
|
const content = await this.readFileContent(node.name);
|
|
301
240
|
if (returnResults) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
241
|
+
if (content) {
|
|
242
|
+
loggerInMemory.log(`<document index="${i + 1}">`);
|
|
243
|
+
loggerInMemory.log(`<source>./${relativePath}</source>`);
|
|
244
|
+
loggerInMemory.log("<document_content>");
|
|
245
|
+
loggerInMemory.log(content);
|
|
246
|
+
loggerInMemory.log("</document_content>");
|
|
247
|
+
loggerInMemory.log("</document>");
|
|
248
|
+
}
|
|
249
|
+
} else if (content) {
|
|
309
250
|
logger.log(`<document index="${i + 1}">`);
|
|
310
251
|
logger.log(`<source>./${relativePath}</source>`);
|
|
311
252
|
logger.log("<document_content>");
|
|
@@ -325,7 +266,7 @@ export class Search {
|
|
|
325
266
|
return results;
|
|
326
267
|
}
|
|
327
268
|
async shouldIgnoreByGitIgnore(nodePath, isDirectory) {
|
|
328
|
-
|
|
269
|
+
if (this.ignoreGitIgnore) {
|
|
329
270
|
return false;
|
|
330
271
|
}
|
|
331
272
|
return this.gitIgnoreHandler.isIgnored(nodePath, isDirectory);
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core.ts"],"sourcesContent":["import { basename, extname, join, relative } from \"node:path\";\n\nimport { GitIgnoreHandler } from \"./gitIgnoreHandler.js\";\nimport {\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\";\n\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\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\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}: {\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}) {\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.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 = extname(filePath).toLowerCase().replace(/^\\./, \"\");\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\tisBinaryFileExtension(filePath: string): boolean {\n\t\tconst ext = extname(filePath).toLowerCase().replace(/^\\./, \"\");\n\n\t\t// If there's no extension, assume it's binary\n\t\t/* istanbul ignore if */\n\t\tif (!ext) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst binaryExtensions = [\n\t\t\t// Executables and compiled code\n\t\t\t\"exe\",\n\t\t\t\"dll\",\n\t\t\t\"so\",\n\t\t\t\"dylib\",\n\t\t\t\"bin\",\n\t\t\t\"obj\",\n\t\t\t\"o\",\n\t\t\t// Compressed files\n\t\t\t\"zip\",\n\t\t\t\"tar\",\n\t\t\t\"gz\",\n\t\t\t\"rar\",\n\t\t\t\"7z\",\n\t\t\t\"jar\",\n\t\t\t\"war\",\n\t\t\t// Media files\n\t\t\t\"jpg\",\n\t\t\t\"jpeg\",\n\t\t\t\"png\",\n\t\t\t\"gif\",\n\t\t\t\"bmp\",\n\t\t\t\"ico\",\n\t\t\t\"tif\",\n\t\t\t\"tiff\",\n\t\t\t\"mp3\",\n\t\t\t\"mp4\",\n\t\t\t\"avi\",\n\t\t\t\"mov\",\n\t\t\t\"wmv\",\n\t\t\t\"flv\",\n\t\t\t\"wav\",\n\t\t\t\"ogg\",\n\t\t\t// Document formats\n\t\t\t\"pdf\",\n\t\t\t\"doc\",\n\t\t\t\"docx\",\n\t\t\t\"xls\",\n\t\t\t\"xlsx\",\n\t\t\t\"ppt\",\n\t\t\t\"pptx\",\n\t\t\t// Database files\n\t\t\t\"db\",\n\t\t\t\"sqlite\",\n\t\t\t\"mdb\",\n\t\t\t// Other binary formats\n\t\t\t\"class\",\n\t\t\t\"pyc\",\n\t\t\t\"pyd\",\n\t\t\t\"pyo\",\n\t\t\t\"woff\",\n\t\t\t\"woff2\",\n\t\t\t\"ttf\",\n\t\t\t\"otf\",\n\t\t];\n\n\t\treturn binaryExtensions.includes(ext);\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 (this.isBinaryFileExtension(filePath)) {\n\t\t\t\treturn \"[Binary file]\";\n\t\t\t}\n\t\t\tconst content = await readFileAsync(filePath, \"utf8\");\n\t\t\treturn content;\n\t\t} catch (error) {\n\t\t\t/* istanbul ignore next */\n\t\t\treturn `Error reading file: ${error.message}`;\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\tloggerInMemory.log(`<document index=\"${i + 1}\">`);\n\t\t\t\t\tloggerInMemory.log(`<source>./${relativePath}</source>`);\n\t\t\t\t\tloggerInMemory.log(\"<document_content>\");\n\t\t\t\t\tloggerInMemory.log(content);\n\t\t\t\t\tloggerInMemory.log(\"</document_content>\");\n\t\t\t\t\tloggerInMemory.log(\"</document>\");\n\t\t\t\t} else {\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\t/* istanbul ignore if */\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","extname","join","relative","GitIgnoreHandler","STR_TYPE_BOTH","STR_TYPE_DIRECTORY","STR_TYPE_FILE","checkPattern","formatLongListings","printStatistics","runCommandOnNode","runGrepOnNode","promisify","Logger","Performance","fs","kleur","plur","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","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","replace","endsWith","filterHidden","value","isBinaryFileExtension","binaryExtensions","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","message","printFilesContent","fileNodes","relativePath","log","i","getMemoryLogs","clearMemoryLogs","nodePath","isIgnored","list","group","mdate","mode","owner","size","separator","color","gray","blue","matchStr","String","highlightedMatch","black","bgYellow","totalMatchingLines","occurrences","white"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,IAAI,EAAEC,QAAQ,QAAQ,YAAY;AAE9D,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SACCC,aAAa,EACbC,kBAAkB,EAClBC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,QACP,iBAAiB;AAExB,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,MAAMC,aAAaN,UAAUG,GAAGI,KAAK;AACrC,MAAMC,eAAeR,UAAUG,GAAGM,OAAO;AACzC,MAAMC,gBAAgBV,UAAUG,GAAGQ,QAAQ;AAC3C,MAAMC,OAAO,IAAIV;AACjB,MAAMW,SAAS,IAAIZ,OAAO;IACzBa,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAClC;AACA,MAAMC,iBAAiB,IAAIjB,OAAO;IACjCkB,UAAU;AACX;AAEA,OAAO,MAAMC;IACZN,OAAiB;IACjBO,QAAiB;IACjBC,6BAAuC;IACvCC,mBAA6B;IAC7BC,aAAuB;IACvBC,KAAc;IACdC,UAAkB;IAClBC,KAAc;IACdC,UAAmB;IACnBC,cAAuB;IACvBC,gBAAyB;IACzBC,eAAwB;IACxBC,iBAA0B;IAC1BC,KAAc;IACdC,iBAA4B;IAC5BC,YAAuB;IACvBC,cAAyB;IACzBC,UAAmB;IACnBC,iBAAmC;IACnCC,gBAA0B;IAE1BC,YAAY,EACX1B,MAAM,EACNO,OAAO,EACPoB,GAAG,EACHhB,IAAI,EACJiB,UAAU,EACVC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AKlD,IAAI,KAAKvC,eAAe;oBAC7C,MAAM,EAAEmI,kBAAkB,EAAEjD,OAAO,EAAE,GAAG,MAAM7E,cAC7CoF,KAAKU,IAAI,EACT,IAAI,CAACpE,IAAI;oBAEV,wBAAwB,GACxB,IAAIoG,oBAAoB;wBACvB,IAAI,CAAC9F,cAAc;wBACnB,MAAM+F,cAAczH,KAAK,cAAcwH;wBAEvChH,OAAO2F,GAAG,CACT,CAAC,GAAG,EAAEY,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,CAAC,EAC7DN,KAAKG,IAAI,CAAC7D,IAAI,IACd0D,KAAKI,KAAK,CAAC9D,IAAI,IACf0D,KAAKK,IAAI,CAAC/D,IAAI,IACd0D,KAAKE,KAAK,EACVnB,MACA,CAAC,CAAC,EAAEzF,MAAM2H,KAAK,CAACF,oBAAoB,CAAC,EAAEC,YAAY,CAAC,CAAC;wBAEtDjH,OAAO2F,GAAG,CAAC,GAAG5B,QAAQvF,IAAI,CAAC,MAAM,EAAE,CAAC;oBACrC;gBACD,OAAO;oBACN,wBAAwB,GACxB,IAAI,CAAC,IAAI,CAACoC,IAAI,EAAE;wBACfZ,OAAO2F,GAAG,CACT,CAAC,GAAG,EAAEY,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,EAAEA,UAAU,EAAE,CAAC,EAC7DN,KAAKG,IAAI,CAAC7D,IAAI,IACd0D,KAAKI,KAAK,CAAC9D,IAAI,IACf0D,KAAKK,IAAI,CAAC/D,IAAI,IACd0D,KAAKE,KAAK,EACVnB;wBAED,IAAIV,KAAK9D,OAAO,EAAE;4BACjB,MAAMvB,iBAAiBqF,KAAKU,IAAI,EAAEV,KAAK9D,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/* 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,kBA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C1D,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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function minifyImports(content: string): string;
|
|
2
|
+
export declare function minifyJs(content: string): string;
|
|
3
|
+
export declare function minifyCss(content: string): string;
|
|
4
|
+
export declare function minifyFileContent(filePath: string, content: string): Promise<string>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { getFileExtension } from "./utilities.js";
|
|
3
|
+
export function minifyImports(content) {
|
|
4
|
+
return content.replace(/(import\s*\{)([^}]*?)(\}\s*from)/g, (_match, _importStart, importItems, _importEnd)=>{
|
|
5
|
+
// Process the items being imported
|
|
6
|
+
const cleanedItems = importItems.split(",").map((item)=>{
|
|
7
|
+
// Handle 'type' keyword specifically
|
|
8
|
+
return item.trim().replace(/(\btype\b)\s+/, "$1");
|
|
9
|
+
}).join(",");
|
|
10
|
+
return `import {${cleanedItems}} from`;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function minifyJs(content) {
|
|
14
|
+
// Store template literals and regular expressions to protect them from minification
|
|
15
|
+
const tokenPrefix = `__PROTECTED_${uuidv4()}_`;
|
|
16
|
+
const protectedSegments = [];
|
|
17
|
+
// Function to create a unique token for each protected segment
|
|
18
|
+
const createToken = (index)=>`${tokenPrefix}${index}__`;
|
|
19
|
+
// Function to protect a segment of code with a custom handler
|
|
20
|
+
const protect = (pattern, handler)=>{
|
|
21
|
+
content = content.replace(pattern, (match)=>{
|
|
22
|
+
// If a handler is provided, use it to determine if we should protect this match
|
|
23
|
+
if (handler && !handler(match)) {
|
|
24
|
+
return ""; // Return empty string for JSDoc comments we don't want to keep
|
|
25
|
+
}
|
|
26
|
+
const index = protectedSegments.length;
|
|
27
|
+
protectedSegments.push(match);
|
|
28
|
+
return createToken(index);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
// Protect template literals
|
|
32
|
+
protect(/`[\s\S]*?`/g);
|
|
33
|
+
// Protect regular expressions
|
|
34
|
+
// This regex pattern matches JavaScript regular expressions while avoiding division operators
|
|
35
|
+
protect(/(?<![a-zA-Z0-9_$])\/(?![*+?\/])(?:[^\r\n\[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*\])+\/[gimyus]*/g);
|
|
36
|
+
// Protect important JSDoc comments
|
|
37
|
+
protect(/\/\*\*[\s\S]*?\*\//g, (match)=>{
|
|
38
|
+
return match.includes("@param") || match.includes("@returns") || match.includes("@description");
|
|
39
|
+
});
|
|
40
|
+
// Remove comments (both single-line and multi-line)
|
|
41
|
+
content = content.replace(/\/\/.*$/gm, ""); // Remove single-line comments
|
|
42
|
+
content = content.replace(/\/\*[\s\S]*?\*\//g, ""); // Remove multi-line comments
|
|
43
|
+
// Compact import statements
|
|
44
|
+
content = minifyImports(content);
|
|
45
|
+
// Remove extra whitespace
|
|
46
|
+
content = content.replace(/^\s+/gm, ""); // Remove leading whitespace
|
|
47
|
+
content = content.replace(/\s+$/gm, ""); // Remove trailing whitespace
|
|
48
|
+
content = content.replace(/\s{2,}/g, " "); // Replace multiple spaces with a single space
|
|
49
|
+
// Compact newlines ( we protected template literals before)
|
|
50
|
+
content = content.replace(/\n+/g, " ");
|
|
51
|
+
// Replace semicolon + space with just semicolon
|
|
52
|
+
content = content.replace(/;\s+/g, ";");
|
|
53
|
+
// Replace colon + space with just colon
|
|
54
|
+
content = content.replace(/,\s+/g, ",");
|
|
55
|
+
// Remove spaces around operators (we protected regex operators before)
|
|
56
|
+
content = content.replace(/\s+([+\-*/%=&|<>!?:;,])\s+/g, "$1");
|
|
57
|
+
// Handle spaces around parentheses and brackets
|
|
58
|
+
content = content.replace(/\(\s+/g, "(");
|
|
59
|
+
content = content.replace(/\s+\)/g, ")");
|
|
60
|
+
content = content.replace(/\[\s+/g, "[");
|
|
61
|
+
content = content.replace(/\s+\]/g, "]");
|
|
62
|
+
// Handle spaces in all curly braces (for object literals, destructuring, etc.)
|
|
63
|
+
content = content.replace(/\{\s+/g, "{");
|
|
64
|
+
content = content.replace(/\s+\}/g, "}");
|
|
65
|
+
// Restore protected segments
|
|
66
|
+
// We need to handle nested tokens, so we'll iterate until all tokens are replaced
|
|
67
|
+
let previousContent = "";
|
|
68
|
+
while(previousContent !== content){
|
|
69
|
+
previousContent = content;
|
|
70
|
+
// Sort indices in descending order to handle nested tokens correctly
|
|
71
|
+
const indices = Array.from({
|
|
72
|
+
length: protectedSegments.length
|
|
73
|
+
}, (_, i)=>i).sort((a, b)=>b - a);
|
|
74
|
+
for (const index of indices){
|
|
75
|
+
const token = createToken(index);
|
|
76
|
+
const segment = protectedSegments[index];
|
|
77
|
+
// Use global replacement to catch all instances
|
|
78
|
+
const tokenRegex = new RegExp(token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g");
|
|
79
|
+
content = content.replace(tokenRegex, ()=>segment);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return content;
|
|
83
|
+
}
|
|
84
|
+
export function minifyCss(content) {
|
|
85
|
+
// Remove CSS comments
|
|
86
|
+
content = content.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
87
|
+
// Remove extra whitespace
|
|
88
|
+
content = content.replace(/\s+/g, " ");
|
|
89
|
+
content = content.replace(/\s*{\s*/g, "{");
|
|
90
|
+
content = content.replace(/\s*}\s*/g, "}");
|
|
91
|
+
content = content.replace(/\s*:\s*/g, ":");
|
|
92
|
+
content = content.replace(/\s*;\s*/g, ";");
|
|
93
|
+
content = content.replace(/\s*,\s*/g, ",");
|
|
94
|
+
return content;
|
|
95
|
+
}
|
|
96
|
+
export async function minifyFileContent(filePath, content) {
|
|
97
|
+
if (!content || content.length < 100) {
|
|
98
|
+
return content;
|
|
99
|
+
}
|
|
100
|
+
const fileExtension = getFileExtension(filePath);
|
|
101
|
+
if (content && content.length > 0 && (fileExtension.endsWith("js") || fileExtension.endsWith("ts") || /* istanbul ignore next */ fileExtension.endsWith("jsx") || /* istanbul ignore next */ fileExtension.endsWith("tsx"))) {
|
|
102
|
+
return minifyJs(content);
|
|
103
|
+
}
|
|
104
|
+
/* istanbul ignore next */ if (content && content.length > 0 && fileExtension.endsWith("css")) {
|
|
105
|
+
return minifyCss(content);
|
|
106
|
+
}
|
|
107
|
+
return content;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=minifiers.js.map
|
|
@@ -0,0 +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/* istanbul ignore next */\n\t\t\tfileExtension.endsWith(\"jsx\") ||\n\t\t\t/* istanbul ignore next */\n\t\t\tfileExtension.endsWith(\"tsx\"))\n\t) {\n\t\treturn minifyJs(content);\n\t}\n\n\t/* istanbul 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,U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B,wBAAwB,GACxBD,cAAcC,QAAQ,CAAC,UACvB,wBAAwB,GACxBD,cAAcC,QAAQ,CAAC,MAAK,GAC5B;QACD,OAAO7B,SAASZ;IACjB;IAEA,wBAAwB,GACxB,IAAIA,WAAWA,QAAQqB,MAAM,GAAG,KAAKmB,cAAcC,QAAQ,CAAC,QAAQ;QACnE,OAAOJ,UAAUrC;IAClB;IAEA,OAAOA;AACR"}
|
package/dist/utilities.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const STR_TYPE_DIRECTORY = "d";
|
|
2
2
|
export declare const STR_TYPE_FILE = "f";
|
|
3
3
|
export declare const STR_TYPE_BOTH = "both";
|
|
4
|
+
export declare const getFileExtension: (filename: string) => string;
|
|
4
5
|
export declare const extractMode: (mode: number) => string;
|
|
5
6
|
export declare const convertSize: (bytes: number) => string;
|
|
6
7
|
export declare const convertDate: (mtime: Date) => string;
|
|
@@ -34,3 +35,4 @@ export type RunGrepOnNode = {
|
|
|
34
35
|
totalMatchingLines: number;
|
|
35
36
|
};
|
|
36
37
|
export declare const runGrepOnNode: (node?: string, rePattern?: RegExp) => Promise<RunGrepOnNode>;
|
|
38
|
+
export declare function isBinaryFileExtension(filePath: string): boolean;
|
package/dist/utilities.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { run } from "@node-cli/run";
|
|
2
1
|
import fs from "node:fs";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
3
|
import { Logger } from "@node-cli/logger";
|
|
4
|
+
import { run } from "@node-cli/run";
|
|
4
5
|
import kleur from "kleur";
|
|
5
6
|
import prettyMilliseconds from "pretty-ms";
|
|
6
7
|
const BYTE_CHUNKS = 1000;
|
|
@@ -17,6 +18,62 @@ const PERMISSIONS_PREFIX = {
|
|
|
17
18
|
[STR_TYPE_DIRECTORY]: "d",
|
|
18
19
|
[STR_TYPE_FILE]: "-"
|
|
19
20
|
};
|
|
21
|
+
const BINARY_EXTENSIONS = [
|
|
22
|
+
// Executables and compiled code
|
|
23
|
+
"exe",
|
|
24
|
+
"dll",
|
|
25
|
+
"so",
|
|
26
|
+
"dylib",
|
|
27
|
+
"bin",
|
|
28
|
+
"obj",
|
|
29
|
+
"o",
|
|
30
|
+
// Compressed files
|
|
31
|
+
"zip",
|
|
32
|
+
"tar",
|
|
33
|
+
"gz",
|
|
34
|
+
"rar",
|
|
35
|
+
"7z",
|
|
36
|
+
"jar",
|
|
37
|
+
"war",
|
|
38
|
+
// Media files
|
|
39
|
+
"jpg",
|
|
40
|
+
"jpeg",
|
|
41
|
+
"png",
|
|
42
|
+
"gif",
|
|
43
|
+
"bmp",
|
|
44
|
+
"ico",
|
|
45
|
+
"tif",
|
|
46
|
+
"tiff",
|
|
47
|
+
"mp3",
|
|
48
|
+
"mp4",
|
|
49
|
+
"avi",
|
|
50
|
+
"mov",
|
|
51
|
+
"wmv",
|
|
52
|
+
"flv",
|
|
53
|
+
"wav",
|
|
54
|
+
"ogg",
|
|
55
|
+
// Document formats
|
|
56
|
+
"pdf",
|
|
57
|
+
"doc",
|
|
58
|
+
"docx",
|
|
59
|
+
"xls",
|
|
60
|
+
"xlsx",
|
|
61
|
+
"ppt",
|
|
62
|
+
"pptx",
|
|
63
|
+
// Database files
|
|
64
|
+
"db",
|
|
65
|
+
"sqlite",
|
|
66
|
+
"mdb",
|
|
67
|
+
// Other binary formats
|
|
68
|
+
"class",
|
|
69
|
+
"pyc",
|
|
70
|
+
"pyd",
|
|
71
|
+
"pyo",
|
|
72
|
+
"woff",
|
|
73
|
+
"woff2",
|
|
74
|
+
"ttf",
|
|
75
|
+
"otf"
|
|
76
|
+
];
|
|
20
77
|
const ownerNames = {
|
|
21
78
|
0: "root"
|
|
22
79
|
};
|
|
@@ -37,6 +94,9 @@ const MONTHS = {
|
|
|
37
94
|
const logger = new Logger({
|
|
38
95
|
boring: process.env.NODE_ENV === "test"
|
|
39
96
|
});
|
|
97
|
+
export const getFileExtension = (filename)=>{
|
|
98
|
+
return extname(filename).toLowerCase().replace(/^\./, "");
|
|
99
|
+
};
|
|
40
100
|
export const extractMode = (mode)=>{
|
|
41
101
|
const modeDec = Number.parseInt(mode.toString(OCTAL), DECIMAL).toString().slice(LAST_THREE_ENTRIES);
|
|
42
102
|
const modeOwner = modeDec.charAt(MODE_OWNER_POS);
|
|
@@ -172,5 +232,13 @@ export const runGrepOnNode = async (node, rePattern)=>{
|
|
|
172
232
|
/* istanbul ignore next */ logger.error(error);
|
|
173
233
|
}
|
|
174
234
|
};
|
|
235
|
+
export function isBinaryFileExtension(filePath) {
|
|
236
|
+
const ext = getFileExtension(filePath);
|
|
237
|
+
// If there's no extension, assume it's binary
|
|
238
|
+
if (!ext) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return BINARY_EXTENSIONS.includes(ext);
|
|
242
|
+
}
|
|
175
243
|
|
|
176
244
|
//# sourceMappingURL=utilities.js.map
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { RunResult, run } from \"@node-cli/run\";\n\nimport fs from \"node:fs\";\nimport { Logger } from \"@node-cli/logger\";\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\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"],"names":["run","fs","Logger","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,OAAOC,QAAQ,UAAU;AACzB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,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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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,EAAEzF,MAAM6F,IAAI,CAACP,MAAM,CAACG,aAAa,EAAE,GAAG;YAClE;YACAL,MAAMQ,IAAI,CACT,GAAGH,aAAa,EAAE,EAAE,EAAEzF,MAAM6F,IAAI,CAC/BH,KAAKI,OAAO,CAACjB,WAAW7E,MAAM+F,KAAK,GAAGC,QAAQ,CAACzC,MAAM,CAAC,EAAE,KACtD,EACH,GAAGkC,aAAa,EAAE,EAAE,EAAEzF,MAAM6F,IAAI,CAACP,MAAM,CAACG,aAAa,EAAE,GAAG,EAC1D;QAEF;QACA,OAAO;YACNQ,SAASb,MAAMjD,MAAM,GAAG,IAAIiD,QAAQ,EAAE;YACtCC;QACD;IACD,EAAE,OAAOa,OAAO;QACf,wBAAwB,GACxBnF,OAAOmF,KAAK,CAACA;IACd;AACD,EAAE"}
|
|
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,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;I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AQ,CAACD;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/search",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Search for files in a directory",
|
|
@@ -33,10 +33,11 @@
|
|
|
33
33
|
"kleur": "4.1.5",
|
|
34
34
|
"micromatch": "4.0.8",
|
|
35
35
|
"plur": "5.1.0",
|
|
36
|
-
"pretty-ms": "9.2.0"
|
|
36
|
+
"pretty-ms": "9.2.0",
|
|
37
|
+
"uuid": "11.1.0"
|
|
37
38
|
},
|
|
38
39
|
"publishConfig": {
|
|
39
40
|
"access": "public"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "decdedb3863d685996d0abd91f4c23746e9e3172"
|
|
42
43
|
}
|