Skip to content

Commit

Permalink
Fix dialog can't be deleted and .gitignore (microsoft#1113)
Browse files Browse the repository at this point in the history
* Fix dialog can't be deleted

* Delete luis.status.json

* Fix git ignore

* update comments

* clean DS_Store

* Update botProject.test.ts
  • Loading branch information
boydc2014 authored Oct 15, 2019
1 parent 43ac6bb commit 8028890
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 42 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
14 changes: 6 additions & 8 deletions Composer/packages/server/__tests__/models/bot/botProject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -132,25 +132,24 @@ 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);
}
});

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);
expect(lgFiles.length).toEqual(2);

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);
}
});
Expand Down Expand Up @@ -203,17 +202,16 @@ 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);
expect(luFiles.length).toEqual(4);

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);
}
});
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Composer/packages/server/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
15 changes: 9 additions & 6 deletions Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class BotProject {
return this.dialogIndexer.getDialogs();
};

public createDialog = async (id: string, content = '', dir = ''): Promise<Dialog[]> => {
public createDialog = async (id: string, content = '', dir: string = this.defaultDir(id)): Promise<Dialog[]> => {
const dialog = this.dialogIndexer.getDialogs().find(d => d.id === id);
if (dialog) {
throw new Error(`${id} dialog already exist`);
Expand Down Expand Up @@ -227,7 +227,7 @@ export class BotProject {
return this.lgIndexer.getLgFiles();
};

public createLgFile = async (id: string, content: string, dir = ''): Promise<LGFile[]> => {
public createLgFile = async (id: string, content: string, dir: string = this.defaultDir(id)): Promise<LGFile[]> => {
const lgFile = this.lgIndexer.getLgFiles().find(lg => lg.id === id);
if (lgFile) {
throw new Error(`${id} lg file already exist`);
Expand Down Expand Up @@ -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<LUFile[]> => {
public createLuFile = async (id: string, content: string, dir: string = this.defaultDir(id)): Promise<LUFile[]> => {
const luFile = this.luIndexer.getLuFiles().find(lu => lu.id === id);
if (luFile) {
throw new Error(`${id} lu file already exist`);
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 0 additions & 12 deletions SampleBots/ToDoBot/ComposerDialogs/settings/appsettings.json

This file was deleted.

12 changes: 0 additions & 12 deletions SampleBots/ToDoLuisBot/ComposerDialogs/settings/appsettings.json

This file was deleted.

0 comments on commit 8028890

Please sign in to comment.