@parseme/cli 0.0.4 → 0.0.5
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/README.md +38 -50
- package/dist/cli/cli.js +21 -32
- package/dist/core/analyzers/ast-analyzer.d.ts +1 -1
- package/dist/core/analyzers/ast-analyzer.js +9 -23
- package/dist/core/analyzers/framework-detector.d.ts +4 -6
- package/dist/core/analyzers/framework-detector.js +154 -165
- package/dist/core/analyzers/pattern-detector.d.ts +2 -2
- package/dist/core/analyzers/pattern-detector.js +93 -13
- package/dist/core/analyzers/project-analyzer.d.ts +1 -1
- package/dist/core/analyzers/project-analyzer.js +7 -18
- package/dist/core/config.d.ts +0 -1
- package/dist/core/config.js +6 -30
- package/dist/core/context-builder.d.ts +1 -3
- package/dist/core/context-builder.js +97 -181
- package/dist/core/generator.js +4 -4
- package/dist/core/types/analyzer-types.d.ts +3 -4
- package/dist/core/types/config-types.d.ts +2 -3
- package/dist/core/types/generator-types.d.ts +0 -2
- package/dist/core/types/project-types.d.ts +1 -1
- package/dist/utils/file-collector.d.ts +23 -0
- package/dist/utils/file-collector.js +61 -0
- package/dist/utils/file-filter.d.ts +30 -0
- package/dist/utils/file-filter.js +99 -0
- package/dist/{core/analyzers/git-analyzer.d.ts → utils/git.d.ts} +1 -1
- package/package.json +10 -5
- /package/dist/{core/analyzers/git-analyzer.js → utils/git.js} +0 -0
- /package/dist/{cli → utils}/prompt.d.ts +0 -0
- /package/dist/{cli → utils}/prompt.js +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import { readdir, stat } from 'fs/promises';
|
|
3
|
+
import { join, relative } from 'path';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import ignore from 'ignore';
|
|
6
|
+
const execAsync = promisify(exec);
|
|
7
|
+
export class FileFilterService {
|
|
8
|
+
excludePatterns;
|
|
9
|
+
useGitForFiles;
|
|
10
|
+
ig;
|
|
11
|
+
constructor(excludePatterns = [], useGitForFiles = true) {
|
|
12
|
+
this.excludePatterns = excludePatterns;
|
|
13
|
+
this.useGitForFiles = useGitForFiles;
|
|
14
|
+
this.ig = ignore();
|
|
15
|
+
this.ig.add(excludePatterns);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get all files that should be analyzed, respecting:
|
|
19
|
+
* 1. Git-tracked files (respects all .gitignore files automatically)
|
|
20
|
+
* 2. All files (if non-git repo) - respects only custom excludePatterns
|
|
21
|
+
* 3. Custom excludePatterns from config (always applied)
|
|
22
|
+
*/
|
|
23
|
+
async getFilteredFiles(rootDir, fileExtensions) {
|
|
24
|
+
try {
|
|
25
|
+
let files;
|
|
26
|
+
// Try to get git-tracked files first (only if useGitForFiles is enabled)
|
|
27
|
+
const isGitRepo = this.useGitForFiles && (await this.isGitRepository(rootDir));
|
|
28
|
+
if (isGitRepo) {
|
|
29
|
+
files = await this.getGitTrackedFiles(rootDir);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Fallback: get all files recursively
|
|
33
|
+
files = await this.getAllFilesRecursive(rootDir, rootDir);
|
|
34
|
+
}
|
|
35
|
+
// Apply custom exclude patterns
|
|
36
|
+
const filteredFiles = files.filter((file) => !this.ig.ignores(file));
|
|
37
|
+
// Optionally filter by file extensions
|
|
38
|
+
if (fileExtensions && fileExtensions.length > 0) {
|
|
39
|
+
const extensionSet = new Set(fileExtensions.map((ext) => (ext.startsWith('.') ? ext : `.${ext}`)));
|
|
40
|
+
return filteredFiles.filter((file) => {
|
|
41
|
+
const ext = file.substring(file.lastIndexOf('.'));
|
|
42
|
+
return extensionSet.has(ext);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return filteredFiles;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error(`Failed to get filtered files: ${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if the directory is a git repository
|
|
53
|
+
*/
|
|
54
|
+
async isGitRepository(rootDir) {
|
|
55
|
+
try {
|
|
56
|
+
await execAsync('git rev-parse --git-dir', { cwd: rootDir });
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get all tracked files from git
|
|
65
|
+
* This respects all .gitignore files in the repository (parent, current, and child dirs)
|
|
66
|
+
*/
|
|
67
|
+
async getGitTrackedFiles(rootDir) {
|
|
68
|
+
const { stdout } = await execAsync('git ls-files', { cwd: rootDir });
|
|
69
|
+
return stdout
|
|
70
|
+
.split('\n')
|
|
71
|
+
.map((line) => line.trim())
|
|
72
|
+
.filter((line) => line);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get all files recursively (fallback for non-git repos)
|
|
76
|
+
*/
|
|
77
|
+
async getAllFilesRecursive(dir, rootDir) {
|
|
78
|
+
const entries = await readdir(dir);
|
|
79
|
+
const files = [];
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const fullPath = join(dir, entry);
|
|
82
|
+
const relativePath = relative(rootDir, fullPath);
|
|
83
|
+
const stats = await stat(fullPath);
|
|
84
|
+
if (stats.isFile()) {
|
|
85
|
+
files.push(relativePath);
|
|
86
|
+
}
|
|
87
|
+
else if (stats.isDirectory() && !entry.startsWith('.')) {
|
|
88
|
+
files.push(...(await this.getAllFilesRecursive(fullPath, rootDir)));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return files;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if a specific file should be filtered out
|
|
95
|
+
*/
|
|
96
|
+
shouldIgnore(filePath) {
|
|
97
|
+
return this.ig.ignores(filePath);
|
|
98
|
+
}
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parseme/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Adds a PARSEME.md file—a README.md for AI agents—to your project, providing context and structure for automated tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,10 +25,15 @@
|
|
|
25
25
|
"lint": "eslint --config ./eslint.config.js --fix",
|
|
26
26
|
"lint:check": "eslint --config ./eslint.config.js --no-fix --max-warnings 0",
|
|
27
27
|
"test": "node --test --experimental-test-coverage 'tests/**/*.test.ts'",
|
|
28
|
-
"
|
|
29
|
-
"test:
|
|
30
|
-
"
|
|
31
|
-
"test:
|
|
28
|
+
"pretest:unit": "npm run build",
|
|
29
|
+
"test:unit": "node --test 'tests/unit/**/*.test.ts'",
|
|
30
|
+
"pretest:integration": "npm run build",
|
|
31
|
+
"test:integration": "node --test 'tests/integration/**/*.test.ts'",
|
|
32
|
+
"test:watch": "node --test --watch 'tests/**/*.test.ts'",
|
|
33
|
+
"pretest:coverage": "npm run build",
|
|
34
|
+
"test:coverage": "node --test --experimental-test-coverage 'tests/unit/**/*.test.ts' 'tests/integration/**/*.test.ts'",
|
|
35
|
+
"test:setup:e2e": "npm run -C ../e2e setup",
|
|
36
|
+
"test:e2e": "npm run -C ../e2e test",
|
|
32
37
|
"clean": "rm -rf dist"
|
|
33
38
|
},
|
|
34
39
|
"keywords": [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|