lunel-cli 0.1.100 → 0.1.101
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/index.js +67 -48
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { WebSocket } from "ws";
|
|
3
3
|
import qrcode from "qrcode-terminal";
|
|
4
|
+
import shell from "shelljs";
|
|
4
5
|
import { createAiManager } from "./ai/index.js";
|
|
5
6
|
import { V2SessionTransport } from "./transport/v2.js";
|
|
6
7
|
import Ignore from "ignore";
|
|
@@ -566,64 +567,82 @@ async function handleFsGrep(payload) {
|
|
|
566
567
|
throw Object.assign(new Error("pattern is required"), { code: "EINVAL" });
|
|
567
568
|
const safePath = assertSafePath(reqPath);
|
|
568
569
|
const matches = [];
|
|
569
|
-
|
|
570
|
+
let regex;
|
|
571
|
+
try {
|
|
572
|
+
regex = new RegExp(pattern, caseSensitive ? "g" : "gi");
|
|
573
|
+
}
|
|
574
|
+
catch {
|
|
575
|
+
throw Object.assign(new Error("pattern must be a valid regular expression"), { code: "EINVAL" });
|
|
576
|
+
}
|
|
570
577
|
const rootIgnore = await loadGitignore(ROOT_DIR);
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
content: lines[i].substring(0, 500),
|
|
583
|
-
});
|
|
578
|
+
const previousSilent = shell.config.silent;
|
|
579
|
+
shell.config.silent = true;
|
|
580
|
+
try {
|
|
581
|
+
async function searchFile(filePath, relativePath) {
|
|
582
|
+
if (matches.length >= maxResults)
|
|
583
|
+
return;
|
|
584
|
+
try {
|
|
585
|
+
const grepResult = shell.grep(regex, filePath);
|
|
586
|
+
if (grepResult.code !== 0 || !grepResult.stdout.trim()) {
|
|
587
|
+
regex.lastIndex = 0;
|
|
588
|
+
return;
|
|
584
589
|
}
|
|
590
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
591
|
+
const lines = content.split("\n");
|
|
592
|
+
for (let i = 0; i < lines.length && matches.length < maxResults; i++) {
|
|
593
|
+
if (regex.test(lines[i])) {
|
|
594
|
+
matches.push({
|
|
595
|
+
file: relativePath,
|
|
596
|
+
line: i + 1,
|
|
597
|
+
content: lines[i].substring(0, 500),
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
regex.lastIndex = 0;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
catch {
|
|
585
604
|
regex.lastIndex = 0;
|
|
586
605
|
}
|
|
587
606
|
}
|
|
588
|
-
|
|
589
|
-
// Skip unreadable files
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
async function searchDir(dirPath, relativePath, ig) {
|
|
593
|
-
if (matches.length >= maxResults)
|
|
594
|
-
return;
|
|
595
|
-
const localIgnore = ignore().add(ig);
|
|
596
|
-
try {
|
|
597
|
-
const localGitignorePath = path.join(dirPath, ".gitignore");
|
|
598
|
-
const content = await fs.readFile(localGitignorePath, "utf-8");
|
|
599
|
-
localIgnore.add(content);
|
|
600
|
-
}
|
|
601
|
-
catch {
|
|
602
|
-
// No local .gitignore
|
|
603
|
-
}
|
|
604
|
-
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
605
|
-
for (const entry of entries) {
|
|
607
|
+
async function searchDir(dirPath, relativePath, ig) {
|
|
606
608
|
if (matches.length >= maxResults)
|
|
607
|
-
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
609
|
+
return;
|
|
610
|
+
const localIgnore = ignore().add(ig);
|
|
611
|
+
try {
|
|
612
|
+
const localGitignorePath = path.join(dirPath, ".gitignore");
|
|
613
|
+
const content = await fs.readFile(localGitignorePath, "utf-8");
|
|
614
|
+
localIgnore.add(content);
|
|
615
|
+
}
|
|
616
|
+
catch {
|
|
617
|
+
// No local .gitignore
|
|
615
618
|
}
|
|
616
|
-
|
|
617
|
-
|
|
619
|
+
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
620
|
+
for (const entry of entries) {
|
|
621
|
+
if (matches.length >= maxResults)
|
|
622
|
+
break;
|
|
623
|
+
const relPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
624
|
+
const checkPath = entry.isDirectory() ? `${relPath}/` : relPath;
|
|
625
|
+
if (localIgnore.ignores(checkPath))
|
|
626
|
+
continue;
|
|
627
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
628
|
+
if (entry.isDirectory()) {
|
|
629
|
+
await searchDir(fullPath, relPath, localIgnore);
|
|
630
|
+
}
|
|
631
|
+
else if (entry.isFile()) {
|
|
632
|
+
await searchFile(fullPath, relPath);
|
|
633
|
+
}
|
|
618
634
|
}
|
|
619
635
|
}
|
|
636
|
+
const stat = await fs.stat(safePath);
|
|
637
|
+
if (stat.isDirectory()) {
|
|
638
|
+
await searchDir(safePath, reqPath === "." ? "" : reqPath, rootIgnore);
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
await searchFile(safePath, reqPath);
|
|
642
|
+
}
|
|
620
643
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
await searchDir(safePath, reqPath === "." ? "" : reqPath, rootIgnore);
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
await searchFile(safePath, reqPath);
|
|
644
|
+
finally {
|
|
645
|
+
shell.config.silent = previousSilent;
|
|
627
646
|
}
|
|
628
647
|
return { matches };
|
|
629
648
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lunel-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.101",
|
|
4
4
|
"author": [
|
|
5
5
|
{
|
|
6
6
|
"name": "Soham Bharambe",
|
|
@@ -30,12 +30,14 @@
|
|
|
30
30
|
"ignore": "^6.0.2",
|
|
31
31
|
"libsodium-wrappers": "^0.7.15",
|
|
32
32
|
"qrcode-terminal": "^0.12.0",
|
|
33
|
+
"shelljs": "^0.10.0",
|
|
33
34
|
"ws": "^8.18.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@types/minimatch": "^5.1.2",
|
|
37
38
|
"@types/node": "^20.0.0",
|
|
38
39
|
"@types/qrcode-terminal": "^0.12.2",
|
|
40
|
+
"@types/shelljs": "^0.10.0",
|
|
39
41
|
"@types/ws": "^8.5.13",
|
|
40
42
|
"typescript": "^5.0.0"
|
|
41
43
|
},
|