From b0c6713692b21489b4e95388b1cab4f9a6113f9f Mon Sep 17 00:00:00 2001 From: Andy Brown Date: Wed, 4 Mar 2020 10:55:14 -0800 Subject: [PATCH 1/3] fix: correctly fetch the bot project schema --- .../server/src/models/bot/botProject.ts | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Composer/packages/server/src/models/bot/botProject.ts b/Composer/packages/server/src/models/bot/botProject.ts index 22e86e5579..d46290c2ed 100644 --- a/Composer/packages/server/src/models/bot/botProject.ts +++ b/Composer/packages/server/src/models/bot/botProject.ts @@ -517,7 +517,7 @@ export class BotProject { } const fileList: FileInfo[] = []; - const patterns = ['**/*.dialog', '**/*.lg', '**/*.lu', '**/*.schema']; + const patterns = ['**/*.dialog', '**/*.lg', '**/*.lu']; for (const pattern of patterns) { // load only from the data dir, otherwise may get "build" versions from // deployment process @@ -526,22 +526,50 @@ export class BotProject { for (const filePath of paths.sort()) { const realFilePath: string = Path.join(root, filePath); - // skip lg files for now - if ((await this.fileStorage.stat(realFilePath)).isFile) { - const content: string = await this.fileStorage.readFile(realFilePath); - fileList.push({ - name: Path.basename(filePath), - content: content, - path: realFilePath, - relativePath: Path.relative(this.dir, realFilePath), - }); + const fileInfo = await this._getFileInfo(realFilePath); + if (fileInfo) { + fileList.push(fileInfo); } } } + const schemas = await this._getSchemas(); + fileList.push(...schemas); + return fileList; }; + private _getSchemas = async (): Promise => { + if (!(await this.exists())) { + throw new Error(`${this.dir} is not a valid path`); + } + + const schemasDir = Path.join(this.dir, 'Schemas'); + const schemas: FileInfo[] = []; + const paths = await this.fileStorage.glob('*.schema', schemasDir); + + for (const path of paths) { + const fileInfo = await this._getFileInfo(Path.join(schemasDir, path)); + if (fileInfo) { + schemas.push(fileInfo); + } + } + + return schemas; + }; + + private _getFileInfo = async (path: string): Promise => { + if ((await this.fileStorage.stat(path)).isFile) { + const content: string = await this.fileStorage.readFile(path); + return { + name: Path.basename(path), + content: content, + path: path, + relativePath: Path.relative(this.dir, path), + }; + } + }; + // check project stracture is valid or not, if not, try fix it. private _checkProjectStructure = async () => { const dialogs: DialogInfo[] = this.dialogs; From d823e03a285c42e88140df9885e4bf140e175923 Mon Sep 17 00:00:00 2001 From: Andy Brown Date: Fri, 6 Mar 2020 10:54:28 -0800 Subject: [PATCH 2/3] do not throw error if schemas directory does not exist --- .../server/src/models/bot/botProject.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Composer/packages/server/src/models/bot/botProject.ts b/Composer/packages/server/src/models/bot/botProject.ts index 5694b19fee..f518c05df1 100644 --- a/Composer/packages/server/src/models/bot/botProject.ts +++ b/Composer/packages/server/src/models/bot/botProject.ts @@ -3,17 +3,8 @@ import fs from 'fs'; -import { getNewDesigner } from '@bfc/shared'; -import { - FileInfo, - DialogInfo, - LgFile, - LuFile, - dialogIndexer, - lgIndexer, - luIndexer, - createSingleMessage, -} from '@bfc/indexers'; +import { FileInfo, DialogInfo, LgFile, LuFile, getNewDesigner } from '@bfc/shared'; +import { dialogIndexer, lgIndexer, luIndexer, createSingleMessage } from '@bfc/indexers'; import { Path } from '../../utility/path'; import { copyDir } from '../../utility/storage'; @@ -513,6 +504,12 @@ export class BotProject { } const schemasDir = Path.join(this.dir, 'Schemas'); + + if (!(await this.fileStorage.exists(schemasDir))) { + debug('No schemas directory found.'); + return []; + } + const schemas: FileInfo[] = []; const paths = await this.fileStorage.glob('*.schema', schemasDir); From 61007b3db462a873df41280e618d45a2a4306180 Mon Sep 17 00:00:00 2001 From: Andy Brown Date: Fri, 6 Mar 2020 11:18:58 -0800 Subject: [PATCH 3/3] fix type imports --- .../packages/server/src/models/bot/botProject.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Composer/packages/server/src/models/bot/botProject.ts b/Composer/packages/server/src/models/bot/botProject.ts index f518c05df1..bfba48e2c9 100644 --- a/Composer/packages/server/src/models/bot/botProject.ts +++ b/Composer/packages/server/src/models/bot/botProject.ts @@ -3,8 +3,17 @@ import fs from 'fs'; -import { FileInfo, DialogInfo, LgFile, LuFile, getNewDesigner } from '@bfc/shared'; -import { dialogIndexer, lgIndexer, luIndexer, createSingleMessage } from '@bfc/indexers'; +import { getNewDesigner } from '@bfc/shared'; +import { + FileInfo, + DialogInfo, + LgFile, + LuFile, + dialogIndexer, + lgIndexer, + luIndexer, + createSingleMessage, +} from '@bfc/indexers'; import { Path } from '../../utility/path'; import { copyDir } from '../../utility/storage';