mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Progressively rebuild when files change
This commit is contained in:
8 files changed
+225
-6
No files matched your search
@@ -17,6 +17,7 @@ export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams
|
||||
private cwd: string;
|
||||
private projectsPath: string;
|
||||
private tmpPath: string;
|
||||
private onFileChanged?: (filePath: string) => void;
|
||||
|
||||
readonly description = "Replace a string in a file with a new string";
|
||||
|
||||
@@ -29,11 +30,12 @@ export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams
|
||||
),
|
||||
});
|
||||
|
||||
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string; tmpPath?: string }) {
|
||||
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string; tmpPath?: string; onFileChanged?: (filePath: string) => void }) {
|
||||
this.fs = fs;
|
||||
this.cwd = cwd;
|
||||
this.projectsPath = options?.projectsPath || '/projects';
|
||||
this.tmpPath = options?.tmpPath || '/tmp';
|
||||
this.onFileChanged = options?.onFileChanged;
|
||||
}
|
||||
|
||||
async execute(args: TextEditorStrReplaceParams): Promise<string> {
|
||||
@@ -172,6 +174,11 @@ export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams
|
||||
|
||||
await this.fs.writeFile(absolutePath, newContent, "utf8");
|
||||
|
||||
// Notify about file change (for auto-build)
|
||||
if (this.onFileChanged) {
|
||||
this.onFileChanged(path);
|
||||
}
|
||||
|
||||
let successMessage = `String successfully replaced in ${path}`;
|
||||
if (occurrences > 1) {
|
||||
successMessage += ` (${occurrences} occurrences found, only first occurrence replaced)`;
|
||||
|
||||
Reference in new issue
Block a user