Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Composer/packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import DLServerContext from './directline/store/dlServerState';
import { mountConversationsRoutes } from './directline/mountConversationRoutes';
import { mountDirectLineRoutes } from './directline/mountDirectlineRoutes';
import { mountAttachmentRoutes } from './directline/mountAttachmentRoutes';
import { cleanHostedBots } from './utility/cleanHostedBots';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const session = require('express-session');
Expand All @@ -42,6 +43,7 @@ export async function start(electronContext?: ElectronContext): Promise<number |
if (electronContext) {
setElectronContext(electronContext);
}
cleanHostedBots();
const clientDirectory = path.resolve(require.resolve('@bfc/client'), '..');
const app: Express = express();
app.set('view engine', 'ejs');
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/server/src/settings/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ export const extensionDataDir = process.env.COMPOSER_EXTENSION_DATA_DIR || resol
export const extensionsBuiltinDir = process.env.COMPOSER_BUILTIN_EXTENSIONS_DIR || resolveFromRoot('../extensions');
export const extensionsRemoteDir =
process.env.COMPOSER_REMOTE_EXTENSIONS_DIR || resolveFromRoot('.composer/extensions');
export const localPublishPath =
process.env.LOCAL_PUBLISH_PATH || resolveFromRoot('../extensions/localPublish/hostedBots');
31 changes: 31 additions & 0 deletions Composer/packages/server/src/utility/cleanHostedBots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { join } from 'path';

import { pathExists, readJson, readdir, remove } from 'fs-extra';

import { appDataPath, localPublishPath } from './../settings/env';

// this function is used to clean the deleted bots in the extensions's cache
export const cleanHostedBots = async () => {
try {
if (!(await pathExists(appDataPath))) return;
const envData = await readJson(appDataPath);

if (!envData.projectLocationMap) return;
const projects = envData.projectLocationMap;

let localHostedBots: string[] = [];
if (await pathExists(localPublishPath)) {
localHostedBots = await readdir(localPublishPath);
}

localHostedBots.forEach((id) => {
if (!projects[id]) {
remove(join(localPublishPath, id));
}
});
} catch (error) {
//TODO: if we can't remove these hostedBots, do we need to show the error
}
};
2 changes: 1 addition & 1 deletion extensions/localPublish/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class LocalPublisher implements PublishPlugin<PublishConfig> {
};

removeRuntimeData = async (botId: string) => {
const targetDir = path.resolve(__dirname, `../hostedBots/${botId}`);
const targetDir = path.resolve(this.getBotsDir(), `./${botId}`);
if (!(await this.dirExist(targetDir))) {
return { msg: `runtime path ${targetDir} does not exist` };
}
Expand Down