Skip to content

Commit e19d816

Browse files
author
gd
committed
wip
1 parent d3aea7c commit e19d816

File tree

3 files changed

+243
-125
lines changed

3 files changed

+243
-125
lines changed

scripts/jsdoc-automation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dbg": "node --inspect-brk --loader ts-node/esm src/index.ts",
1414
"dbg2": "node --inspect --loader ts-node/esm src/index.ts",
1515
"dbg3": "npx --node-options=--inspect-brk tsx ./src/index",
16-
"ts": "NODE_ENV=development VERBOSE=true DEFAULT_LOG_LEVEL=debug DEBUG=eliza:* npx tsx src/index",
16+
"ts": "npx tsx src/index",
1717
"clean": "rm -rf node_modules dist"
1818
},
1919
"keywords": [],

scripts/jsdoc-automation/src/DirectoryTraversal.ts

+69-42
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import * as fs from "fs";
1+
import { promises as fs } from "fs";
22
import * as path from "path";
33
import type { Configuration } from "./Configuration.js";
44

5+
export interface FileChange {
6+
filename: string;
7+
status: string;
8+
additions: number;
9+
deletions: number;
10+
changes: number;
11+
contents_url?: string;
12+
}
13+
514
/**
615
* DirectoryTraversal class for traversing through directories and files.
716
* @class DirectoryTraversal
@@ -30,15 +39,19 @@ export class DirectoryTraversal {
3039
"static",
3140
];
3241

42+
private fileChanges: Map<string, FileChange>;
43+
3344
/**
3445
* Constructor for directory traversal
3546
* @param {Configuration} config - Configuration object containing paths and exclusions
36-
* @param {string[]} [prFiles=[]] - PR files to process
47+
* @param {FileChange[]} [changes=[]] - Array of file changes from git diff
3748
*/
3849
constructor(
3950
private config: Configuration,
40-
public prFiles: string[] = []
41-
) {}
51+
changes: FileChange[] = []
52+
) {
53+
this.fileChanges = new Map(changes.map(change => [change.filename, change]));
54+
}
4255

4356
/**
4457
* Gets the absolute path for a file
@@ -55,62 +68,76 @@ export class DirectoryTraversal {
5568
}
5669

5770
/**
58-
* Traverses the directory based on PRFiles or all files in the root directory.
59-
* If PRFiles are detected, processes only files from the PR.
71+
* Gets the file change information for a given file
72+
* @param {string} filePath - The path to the file
73+
* @returns {FileChange | undefined} The file change information if available
74+
*/
75+
public getFileChange(filePath: string): FileChange | undefined {
76+
const relativePath = this.getRelativePath(filePath);
77+
return this.fileChanges.get(relativePath);
78+
}
79+
80+
/**
81+
* Traverses the directory based on file changes from git diff.
82+
* If changes are detected, processes only changed files.
6083
* Otherwise, scans all files in the root directory for TypeScript files.
6184
*
62-
*
6385
* @returns An array of string containing the files to process.
6486
*/
6587
public traverse(): string[] {
66-
if (this.prFiles.length > 0) {
67-
console.log("Detected PR Files:", this.prFiles);
88+
if (this.fileChanges.size > 0) {
89+
console.log("Detected Changes:", Array.from(this.fileChanges.values()));
90+
91+
// Changes are already relative to repo root, filter and convert to absolute paths
92+
const files = Array.from(this.fileChanges.entries())
93+
.filter(([file, change]: [string, FileChange]) => {
94+
// Skip deleted files
95+
if (change.status === 'deleted') {
96+
return false;
97+
}
6898

69-
// PR files are already relative to repo root, filter and convert to absolute paths
70-
const files = this.prFiles
71-
.filter((file) => {
72-
// Convert PR file (repo-relative) to absolute path
99+
// Convert file (repo-relative) to absolute path
73100
const absolutePath = this.config.toAbsolutePath(file);
74101

75-
// Check if the file is within our target directory
76-
const isInTargetDir = absolutePath.startsWith(
77-
this.config.absolutePath
78-
);
79-
80-
return (
81-
isInTargetDir &&
82-
fs.existsSync(absolutePath) &&
83-
!this.isExcluded(absolutePath) &&
84-
path.extname(file) === ".ts"
85-
);
102+
// // Check if the file is within our target directory
103+
// const isInTargetDir = absolutePath.startsWith(
104+
// this.config.absolutePath
105+
// );
106+
107+
// return (
108+
// isInTargetDir &&
109+
// fs.existsSync(absolutePath) &&
110+
// !this.isExcluded(absolutePath) &&
111+
// path.extname(file) === ".ts"
112+
// );
86113
})
87-
.map((file) => this.config.toAbsolutePath(file));
114+
.map(([file]) => this.config.toAbsolutePath(file));
88115

89116
console.log("Files to process:", files);
90117
return files;
91118
} else {
92119
console.log(
93-
"No PR Files Detected, Scanning all files in root directory"
120+
"No Changes Detected, Scanning all files in root directory"
94121
);
95122
const typeScriptFiles: string[] = [];
96123

97124
const traverseDirectory = (currentDirectory: string) => {
98-
const files = fs.readdirSync(currentDirectory);
99-
100-
files.forEach((file) => {
101-
const filePath = path.join(currentDirectory, file);
102-
const stats = fs.statSync(filePath);
103-
104-
if (stats.isDirectory()) {
105-
if (!this.isExcluded(filePath)) {
106-
traverseDirectory(filePath);
107-
}
108-
} else if (stats.isFile() && !this.isExcluded(filePath)) {
109-
if (path.extname(file) === ".ts") {
110-
typeScriptFiles.push(filePath);
111-
}
112-
}
113-
});
125+
// const files = fs.readdirSync(currentDirectory);
126+
127+
// files.forEach((file) => {
128+
// const filePath = path.join(currentDirectory, file);
129+
// const stats = fs.statSync(filePath);
130+
131+
// if (stats.isDirectory()) {
132+
// if (!this.isExcluded(filePath)) {
133+
// traverseDirectory(filePath);
134+
// }
135+
// } else if (stats.isFile() && !this.isExcluded(filePath)) {
136+
// if (path.extname(file) === ".ts") {
137+
// typeScriptFiles.push(filePath);
138+
// }
139+
// }
140+
// });
114141
};
115142

116143
traverseDirectory(this.config.absolutePath);

0 commit comments

Comments
 (0)