diff --git a/.gitignore b/.gitignore index 2fefe8cd23..907bd96e96 100644 --- a/.gitignore +++ b/.gitignore @@ -389,11 +389,14 @@ typings/ # Local sample bots SampleBots/Local* SampleBots/__Test* -SampleBots/*/generated/ -SampleBots/*/settings +SampleBots/*/*/generated +SampleBots/*/*/settings #tmp.zip *.zip +#DS_Store +*.DS_Store + # VsCode Composer/.vscode/ diff --git a/Composer/packages/server/__tests__/models/bot/botProject.test.ts b/Composer/packages/server/__tests__/models/bot/botProject.test.ts index 73bcb3b80d..242f19864b 100644 --- a/Composer/packages/server/__tests__/models/bot/botProject.test.ts +++ b/Composer/packages/server/__tests__/models/bot/botProject.test.ts @@ -61,7 +61,7 @@ describe('createFromTemplate', () => { afterEach(() => { try { - fs.unlinkSync(Path.resolve(__dirname, `${botDir}/ComposerDialogs/${dialogName}.dialog`)); + fs.unlinkSync(Path.resolve(__dirname, `${botDir}/ComposerDialogs/${dialogName}/${dialogName}.dialog`)); } catch (err) { throw new Error(err); } @@ -132,7 +132,7 @@ describe('modify non exist files', () => { describe('lg operation', () => { afterAll(() => { try { - fs.rmdirSync(Path.resolve(__dirname, `${botDir}/root`)); + fs.rmdirSync(Path.resolve(__dirname, `${botDir}/ComposerDialogs/root`)); } catch (err) { throw new Error(err); } @@ -140,9 +140,8 @@ describe('lg operation', () => { it('should create lg file and update index', async () => { const id = 'root'; - const dir = 'root'; const content = '# hello \n - hello'; - const lgFiles = await proj.createLgFile(id, content, dir); + const lgFiles = await proj.createLgFile(id, content); const result = lgFiles.find(f => f.id === id); expect(proj.files.length).toEqual(8); @@ -150,7 +149,7 @@ describe('lg operation', () => { expect(result).not.toBeUndefined(); if (result !== undefined) { - expect(result.relativePath).toEqual('root/root.lg'); + expect(result.relativePath).toEqual('ComposerDialogs/root/root.lg'); expect(result.content).toEqual(content); } }); @@ -203,9 +202,8 @@ describe('lu operation', () => { it('should create lu file and update index', async () => { const id = 'root'; - const dir = 'root'; const content = '## hello \n - hello'; - const luFiles = await proj.createLuFile(id, content, dir); + const luFiles = await proj.createLuFile(id, content); const result = luFiles.find(f => f.id === id); expect(proj.files.length).toEqual(8); @@ -213,7 +211,7 @@ describe('lu operation', () => { expect(result).not.toBeUndefined(); if (result !== undefined) { - expect(result.relativePath).toEqual('root/root.lu'); + expect(result.relativePath).toEqual('ComposerDialogs/root/root.lu'); expect(result.content).toEqual(content); } }); diff --git a/Composer/packages/server/assets/projects/.DS_Store b/Composer/packages/server/assets/projects/.DS_Store deleted file mode 100644 index b68aeb46a4..0000000000 Binary files a/Composer/packages/server/assets/projects/.DS_Store and /dev/null differ diff --git a/Composer/packages/server/assets/projects/EchoBot/.DS_Store b/Composer/packages/server/assets/projects/EchoBot/.DS_Store deleted file mode 100644 index 7098c996d8..0000000000 Binary files a/Composer/packages/server/assets/projects/EchoBot/.DS_Store and /dev/null differ diff --git a/Composer/packages/server/assets/projects/EmptyBot/.DS_Store b/Composer/packages/server/assets/projects/EmptyBot/.DS_Store deleted file mode 100644 index 6b2c8408aa..0000000000 Binary files a/Composer/packages/server/assets/projects/EmptyBot/.DS_Store and /dev/null differ diff --git a/Composer/packages/server/assets/projects/ToDoBot/.DS_Store b/Composer/packages/server/assets/projects/ToDoBot/.DS_Store deleted file mode 100644 index 2b804cacbf..0000000000 Binary files a/Composer/packages/server/assets/projects/ToDoBot/.DS_Store and /dev/null differ diff --git a/Composer/packages/server/src/controllers/project.ts b/Composer/packages/server/src/controllers/project.ts index 8834fa3eed..c1cad21017 100644 --- a/Composer/packages/server/src/controllers/project.ts +++ b/Composer/packages/server/src/controllers/project.ts @@ -159,8 +159,8 @@ async function createDialog(req: Request, res: Response) { if (currentProject !== undefined) { const content = JSON.stringify(req.body.content, null, 2) + '\n'; //dir = id - const dialogs = await currentProject.createDialog(req.body.id, content, req.body.id); - const luFiles = await currentProject.createLuFile(req.body.id, '', req.body.id); + const dialogs = await currentProject.createDialog(req.body.id, content); + const luFiles = await currentProject.createLuFile(req.body.id, ''); res.status(200).json({ dialogs, luFiles }); } else { res.status(404).json({ diff --git a/Composer/packages/server/src/models/bot/botProject.ts b/Composer/packages/server/src/models/bot/botProject.ts index 0609465bce..3431349be5 100644 --- a/Composer/packages/server/src/models/bot/botProject.ts +++ b/Composer/packages/server/src/models/bot/botProject.ts @@ -188,7 +188,7 @@ export class BotProject { return this.dialogIndexer.getDialogs(); }; - public createDialog = async (id: string, content = '', dir = ''): Promise => { + public createDialog = async (id: string, content = '', dir: string = this.defaultDir(id)): Promise => { const dialog = this.dialogIndexer.getDialogs().find(d => d.id === id); if (dialog) { throw new Error(`${id} dialog already exist`); @@ -227,7 +227,7 @@ export class BotProject { return this.lgIndexer.getLgFiles(); }; - public createLgFile = async (id: string, content: string, dir = ''): Promise => { + public createLgFile = async (id: string, content: string, dir: string = this.defaultDir(id)): Promise => { const lgFile = this.lgIndexer.getLgFiles().find(lg => lg.id === id); if (lgFile) { throw new Error(`${id} lg file already exist`); @@ -274,7 +274,7 @@ export class BotProject { return this.mergeLuStatus(this.luIndexer.getLuFiles(), this.luPublisher.status); }; - public createLuFile = async (id: string, content: string, dir = ''): Promise => { + public createLuFile = async (id: string, content: string, dir: string = this.defaultDir(id)): Promise => { const luFile = this.luIndexer.getLuFiles().find(lu => lu.id === id); if (luFile) { throw new Error(`${id} lu file already exist`); @@ -357,10 +357,13 @@ export class BotProject { return (await this.fileStorage.exists(this.dir)) && (await this.fileStorage.stat(this.dir)).isDir; } - // create file in this project this function will gurantee the memory cache - // (this.files, all indexes) also gets updated + private defaultDir = (id: string) => Path.join(DIALOGFOLDER, id); + + // create a file with relativePath and content + // relativePath is a path relative to root dir instead of dataDir + // dataDir is not aware at this layer private _createFile = async (relativePath: string, content: string) => { - const absolutePath = Path.resolve(this.dataDir, relativePath); + const absolutePath = Path.resolve(this.dir, relativePath); await this.ensureDirExists(Path.dirname(absolutePath)); await this.fileStorage.writeFile(absolutePath, content); diff --git a/SampleBots/ToDoBot/ComposerDialogs/settings/appsettings.json b/SampleBots/ToDoBot/ComposerDialogs/settings/appsettings.json deleted file mode 100644 index 35602f7c12..0000000000 --- a/SampleBots/ToDoBot/ComposerDialogs/settings/appsettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "MicrosoftAppPassword": "", - "MicrosoftAppId": "", - "luis": { - "name": "", - "authoringKey": "", - "endpointKey": "", - "authoringRegion": "westus", - "defaultLanguage": "en-us", - "environment": "composer" - } -} \ No newline at end of file diff --git a/SampleBots/ToDoLuisBot/ComposerDialogs/settings/appsettings.json b/SampleBots/ToDoLuisBot/ComposerDialogs/settings/appsettings.json deleted file mode 100644 index 0ed2add9db..0000000000 --- a/SampleBots/ToDoLuisBot/ComposerDialogs/settings/appsettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "MicrosoftAppPassword": "", - "MicrosoftAppId": "", - "luis": { - "name": "TestAgain", - "authoringKey": "", - "endpointKey": "", - "authoringRegion": "westus", - "defaultLanguage": "en-us", - "environment": "composer2" - } -} \ No newline at end of file