Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export class BotProject {
if (dialog === undefined) {
throw new Error(`no such dialog ${id}`);
}

await this._removeFile(dialog.relativePath);
this._cleanUp(dialog.relativePath);
return this.dialogIndexer.getDialogs();
};

Expand Down Expand Up @@ -292,8 +292,11 @@ export class BotProject {
if (luFile === undefined) {
throw new Error(`no such lu file ${id}`);
}

await this._removeFile(luFile.relativePath);

await this.luPublisher.onFileChange(luFile.relativePath, FileUpdateType.DELETE);
this._cleanUp(luFile.relativePath);
return this.mergeLuStatus(this.luIndexer.getLuFiles(), this.luPublisher.status);
};

Expand Down Expand Up @@ -357,6 +360,19 @@ export class BotProject {
return (await this.fileStorage.exists(this.dir)) && (await this.fileStorage.stat(this.dir)).isDir;
}

private _cleanUp = (relativePath: string) => {
const absolutePath = `${this.dir}/${relativePath}`;
const dirPath = Path.dirname(absolutePath);
this._removeEmptyFolder(dirPath);
};

private _removeEmptyFolder = async (folderPath: string) => {
const files = await this.fileStorage.readDir(folderPath);
if (files.length === 0) {
this.fileStorage.rmDir(folderPath);
}
};

private defaultDir = (id: string) => Path.join(DIALOGFOLDER, id);

// create a file with relativePath and content
Expand Down