From b60d17274a328feba14401faa7e9100005939ad1 Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Tue, 15 Oct 2019 10:44:42 -0700 Subject: [PATCH 1/6] Fix dialog can't be deleted --- .../server/src/controllers/project.ts | 4 ++-- .../server/src/models/bot/botProject.ts | 15 ++++++++----- .../generated/luis.status.json | 22 +++++++++++++++++++ .../ComposerDialogs/settings/appsettings.json | 12 ---------- 4 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json delete mode 100644 SampleBots/ToDoBot/ComposerDialogs/settings/appsettings.json 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..f1583c2161 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 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/generated/luis.status.json b/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json new file mode 100644 index 0000000000..75f8ea3bf0 --- /dev/null +++ b/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json @@ -0,0 +1,22 @@ +{ + "ComposerDialogs/AddToDo/AddToDo.lu": { + "lastUpdateTime": 1, + "lastPublishTime": 0 + }, + "ComposerDialogs/ClearToDos/ClearToDos.lu": { + "lastUpdateTime": 1, + "lastPublishTime": 0 + }, + "ComposerDialogs/DeleteToDo/DeleteToDo.lu": { + "lastUpdateTime": 1, + "lastPublishTime": 0 + }, + "ComposerDialogs/Main/Main.lu": { + "lastUpdateTime": 1, + "lastPublishTime": 0 + }, + "ComposerDialogs/ShowToDos/ShowToDos.lu": { + "lastUpdateTime": 1, + "lastPublishTime": 0 + } +} \ No newline at end of file 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 From bf474a3e52594b79eaf4d590e783da6074e93c8f Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Tue, 15 Oct 2019 10:47:33 -0700 Subject: [PATCH 2/6] Delete luis.status.json --- .../generated/luis.status.json | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json diff --git a/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json b/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json deleted file mode 100644 index 75f8ea3bf0..0000000000 --- a/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "ComposerDialogs/AddToDo/AddToDo.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/ClearToDos/ClearToDos.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/DeleteToDo/DeleteToDo.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/Main/Main.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/ShowToDos/ShowToDos.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - } -} \ No newline at end of file From 9be1330369942470f25f16a832aa808c1312f0c3 Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Tue, 15 Oct 2019 10:52:29 -0700 Subject: [PATCH 3/6] Fix git ignore --- .gitignore | 4 ++-- .../generated/luis.status.json | 22 ------------------- .../ComposerDialogs/settings/appsettings.json | 12 ---------- 3 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json delete mode 100644 SampleBots/ToDoLuisBot/ComposerDialogs/settings/appsettings.json diff --git a/.gitignore b/.gitignore index 2fefe8cd23..24451b2a45 100644 --- a/.gitignore +++ b/.gitignore @@ -389,8 +389,8 @@ typings/ # Local sample bots SampleBots/Local* SampleBots/__Test* -SampleBots/*/generated/ -SampleBots/*/settings +SampleBots/*/*/generated +SampleBots/*/*/settings #tmp.zip *.zip diff --git a/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json b/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json deleted file mode 100644 index 75f8ea3bf0..0000000000 --- a/SampleBots/ToDoBot/ComposerDialogs/generated/luis.status.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "ComposerDialogs/AddToDo/AddToDo.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/ClearToDos/ClearToDos.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/DeleteToDo/DeleteToDo.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/Main/Main.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - }, - "ComposerDialogs/ShowToDos/ShowToDos.lu": { - "lastUpdateTime": 1, - "lastPublishTime": 0 - } -} \ 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 From 98dbe97be7f0d5863aee332174cc06eb16a623f4 Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Tue, 15 Oct 2019 10:59:07 -0700 Subject: [PATCH 4/6] update comments --- Composer/packages/server/src/models/bot/botProject.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Composer/packages/server/src/models/bot/botProject.ts b/Composer/packages/server/src/models/bot/botProject.ts index f1583c2161..3431349be5 100644 --- a/Composer/packages/server/src/models/bot/botProject.ts +++ b/Composer/packages/server/src/models/bot/botProject.ts @@ -361,7 +361,7 @@ export class BotProject { // create a file with relativePath and content // relativePath is a path relative to root dir instead of dataDir - // dataDir is not aware at this + // dataDir is not aware at this layer private _createFile = async (relativePath: string, content: string) => { const absolutePath = Path.resolve(this.dir, relativePath); await this.ensureDirExists(Path.dirname(absolutePath)); From 272ddb4615402c953e8178077c6e63b22a004311 Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Tue, 15 Oct 2019 11:12:22 -0700 Subject: [PATCH 5/6] clean DS_Store --- .gitignore | 3 +++ .../packages/server/assets/projects/.DS_Store | Bin 12292 -> 0 bytes .../server/assets/projects/EchoBot/.DS_Store | Bin 6148 -> 0 bytes .../server/assets/projects/EmptyBot/.DS_Store | Bin 6148 -> 0 bytes .../server/assets/projects/ToDoBot/.DS_Store | Bin 6148 -> 0 bytes 5 files changed, 3 insertions(+) delete mode 100644 Composer/packages/server/assets/projects/.DS_Store delete mode 100644 Composer/packages/server/assets/projects/EchoBot/.DS_Store delete mode 100644 Composer/packages/server/assets/projects/EmptyBot/.DS_Store delete mode 100644 Composer/packages/server/assets/projects/ToDoBot/.DS_Store diff --git a/.gitignore b/.gitignore index 24451b2a45..907bd96e96 100644 --- a/.gitignore +++ b/.gitignore @@ -395,5 +395,8 @@ SampleBots/*/*/settings #tmp.zip *.zip +#DS_Store +*.DS_Store + # VsCode Composer/.vscode/ diff --git a/Composer/packages/server/assets/projects/.DS_Store b/Composer/packages/server/assets/projects/.DS_Store deleted file mode 100644 index b68aeb46a466bfca1516ee8b4949cfa18c2d2dcf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12292 zcmeHNU2GLa6h5ad?M|VxMgI08aHRn%UZl5y0`hm;UMS@!Ah*y`kh1sgLN{)A%iX=b zlv-004KHHUXiR8gVt7O3Nu#{@;!h05pBRi1!-Kx~Xf&GmWIQvox1qP~g9#!0%p@~s zX3jZxXU?73^PQOm0BkE*Nq|NG&?s}N&jF~a1&Gh4#%+o7d7hFgsRt?7QKq^MFbE+G zLmT)+RZwc{ zjLkMW_w3!*r|X5lK4iOQ=nUCuGqi&~eQwb27dvylcQ9`cId-u-=evagk2v)?)6Eq~ z*lu;*jC0NodP4hb$ZNfUpAXxGV2?w(ysuB6$Mp{khK}zAN9=q+l(F~bELgf?)ssyd zp5BqZQTNDPy?!2Jy^dvjp>xWy^M{L$74{!BgPiSIj(56y$O)XRYj=6(fL&iX$k>gA zix$@zG2^ikt6W9X8?>H6);Uvf!eQ}@Wy=kA+@g{1_bvVuOaD+~g43|vFphCfd)}tf z(lpV%y3t@=0nI`;Bf-R4#=4$!JWCH~2z=nlW@a3A&8+R}7L#f%8=28PB&VwHjXJk% zWkyfV9~hu12KAVTx>K!&ae_a2pBaP)25pZ<^(8%C%x<~Sp=n1sx7D&}R1GQqj;AEd z(2#19Egk8vHy{DqVHfm54m>ErD{ui`g^O?ruEGcK348%x!8hY#!{ z2+rpaLL{nF93cAQ5luyOOj4mrIzpAGRON0+@`XC}$D?*CqGOUubwH^O7(E%I2nD4& zU|fg;rX*FRvVgL{R0~v7*L2wbe;|pwiT!WRk%0fv`3sgcG_GylxV3cx7?(le+cCKS z;u2{K1YSbe0t-)q^&C7Ku_bKjOrgPH0`T@(jiYeAMoPzHD>MS$xuav^;SW+Xjug{X)^{jf%yz};Sub{qXg!20?ha08O&pd1p@VB_##32m+^cA>fgk-@EyD)7u*Dd@0`2< z@yc|oZzz-ZT;DrQJpQt;fi6P0=@QD#7K3PQ!u1l${jn66YPDKzUG1|O3P3ZV85V*z zGk=V?4w_+qHmY~|zB^Gjvqvbz?9=DB`(9`|o}CxU6it%I@oxIF{bHM6@T@@mPDU~` zjcKe;H%3O*Z`hcKH*ablO~gl%>yw)k@s{MK(NU%?TAAF|d2(R*+{p8zFI<%K#>jcW zT-lx|$EVIy#osFazQ^P5X&0?>9MN%8`I(Y(9Cz4plsSenw=wZs~ zvZeSriJiDlY7!F>&!5*bqA3woXo4)ph{*8h)QLGyfLzu{w4;04Ql!U`h5q7@rWjXES|Or(**~4XzrI}^-=|IMA4GKzgX|6x zb<-Je2AlzBz!?}YfIC~HI#YD*3^)VMz!w8@J_Izu+Au4YqXVjx06=+07lAFcgv12H z+Au3(2ErN&)KIn(gEbuE!Tf5&tf=9{R(!DS{8_wk*&XYL;!a#Ex^@Pffj$GL+MUY% zzrZguTIBabyypx!1OJQxp2TIGWoeyHe YuQtqzvWkqCaG*Z~3L&nXfnQ+Y1F`TqzW@LL 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 6b2c8408aa9f30995eac0e0a3840ede2cede1ef7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKK~4iP478z#l{ip|3&(t+KUhlof_?x>QH!*ztXgr;iGTDdynxT}0LHO_u6CtL z91udb6pxeGiFc$;Vj|-C^Lj=!C87#Vki{4g86KTFGv^7A%NmLH^hi63^fa>2UmTL$ zFX@&NwbVg>=YLNP`WxCeo7wUqwcSzrCnDMu&@wX+O+;bRJR>u zca*4`&VV!E3^)VMz<>eV*&@}2qHAZs8E^)^7?ATJpb6H7S+N`)P^AO_$}_qMY^fzA zCK%R+SrIc3)=;2^vXvOD;TR9*R~u$U4JWqZgKg)};)ToZSU(hZ;#$$QGvEyL893MO zRPO%;ewooCzaQc~XTTZwXAJNpF5?^@Wq0e~^W?4#Xm@BL;+MsM!0tT)(2;ZGx=iYP a5F38AVOEq?WW0m}{UJ~YapesB0s|kFcRD)& 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 2b804cacbf5a4af82afd92e871d7e1a24f10cd28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKK~4iP478z#l{nC2kNHA>5K4GKKLDkufOeG?7599Fr|=p+zylb^2D;jnDseyv z*-|`CVkh2_Hi?OdSI^re(VU1HG(i?)LS%Sy>cpI9K(1?K+S469QKE;5h5q7@<&-vU-XNlRd+ZkPFRvHJ_v!NX2T}d~D7%A1 z-E;<=0cXG&a0W&U;La9l&JR4QSVBBH~xXfWRI+0??6jWKkz|K8Ov! XXjl|w6&bJLKz|5SLR>imzrer;r35-h From 5f6e11ac1cde9044d6a285b30db1775a523aa9d4 Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Tue, 15 Oct 2019 13:16:22 -0700 Subject: [PATCH 6/6] Update botProject.test.ts --- .../server/__tests__/models/bot/botProject.test.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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); } });