Skip to content

Commit

Permalink
Remove .botproj (microsoft#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
boydc2014 authored Jul 5, 2019
1 parent 097b894 commit eb2d233
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 286 deletions.
19 changes: 5 additions & 14 deletions BotProject/CSharp/BotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public BotManager(IConfiguration config)

// set init bot
var bot = Config.GetSection("bot").Get<string>();
var botProj = BotProject.Load(bot);
SetCurrent(botProj);
SetCurrent(bot);
}

public IConfiguration Config { get; }
Expand All @@ -50,19 +49,15 @@ public BotManager(IConfiguration config)

private static readonly object locker = new object();

public void SetCurrent(BotProject botProject)
public void SetCurrent(string botDir)
{
IStorage storage = new MemoryStorage();
var userState = new UserState(storage);
var conversationState = new ConversationState(storage);

// manage all bot resources
var resourceExplorer = new ResourceExplorer();
foreach (var folder in botProject.Folders)
{
resourceExplorer.AddFolder(folder);
}

var resourceExplorer = new ResourceExplorer().AddFolder(botDir);

var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(Config));

adapter
Expand Down Expand Up @@ -93,16 +88,12 @@ public void SetCurrent(Stream fileStream, LuConfigFile luConfig = null)
// extract to bot folder
var extractPath = ExtractFile(downloadPath, GenNewBotDir());

// locate the proj file
var projFile = FindBotProjFile(extractPath);

if (luConfig != null)
{
AddLuisConfig(extractPath, luConfig);
}

var botProj = BotProject.Load(projFile);
SetCurrent(botProj);
SetCurrent(extractPath);
}
}

Expand Down
34 changes: 0 additions & 34 deletions BotProject/CSharp/BotProject.cs

This file was deleted.

2 changes: 1 addition & 1 deletion BotProject/CSharp/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"bot": "../../SampleBots/Inputs_Samples/inputs_samples.botproj",
"bot": "../../SampleBots/Inputs_Samples",
"MicrosoftAppId": "",
"MicrosoftAppPassword": ""
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jest.mock('azure-storage', () => {
return {};
});
const mockAssetLibraryPath = Path.join(__dirname, '../../mocks/asset');
const mockCopyToPath = Path.join(__dirname, '../../mocks/new/1.botproj');
const mockCopyToPath = Path.join(__dirname, '../../mocks/new');
const locationRef = {
storageId: 'default',
path: mockCopyToPath,
Expand All @@ -23,10 +23,10 @@ describe('test assetManager', () => {
it('test copyProjectTemplateTo', async () => {
const assetManager = new AssetManager(mockAssetLibraryPath);
await assetManager.getProjectTemplate();
await expect(async () => assetManager.copyProjectTemplateTo('SampleBot', locationRef)).not.toThrowError();
await expect(assetManager.copyProjectTemplateTo('SampleBot', locationRef)).resolves.toBe(locationRef);
// remove the saveas files
try {
rimraf.sync(Path.dirname(mockCopyToPath));
rimraf.sync(mockCopyToPath);
} catch (error) {
//ignore
}
Expand Down
31 changes: 10 additions & 21 deletions Composer/packages/server/__tests__/models/bot/botProject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const botDir = '../../mocks/samplebots/bot1';

const mockLocationRef: LocationRef = {
storageId: 'default',
path: Path.join(__dirname, `${botDir}/1.botproj`),
path: Path.join(__dirname, `${botDir}`),
};

const proj = new BotProject(mockLocationRef);
Expand Down Expand Up @@ -46,25 +46,14 @@ describe('updateDialog', () => {
});
});

describe('updateBotFile', () => {
it('should update a file at a path', async () => {
const initValue = { services: [], entry: 'main.dialog' };
const newValue = { services: ['test'], entry: 'main.dialog' };
const botFile = await proj.updateBotFile('1', newValue);
// @ts-ignore
expect(botFile.content).toEqual(newValue);
await proj.updateBotFile('1', initValue);
});
});

describe('createFromTemplate', () => {
const dialogName = 'MyTestDialog';

afterEach(() => {
try {
fs.unlinkSync(Path.resolve(__dirname, `${botDir}/${dialogName}.dialog`));
} catch (err) {
// ignore
throw new Error(err);
}
});

Expand Down Expand Up @@ -134,7 +123,7 @@ describe('modify non exist files', () => {
describe('lg operation', () => {
afterEach(() => {
try {
fs.rmdirSync(Path.resolve(__dirname, `${botDir}/root`));
fs.rmdirSync(Path.resolve(__dirname, `${botDir} / root`));
} catch (err) {
// ignore
}
Expand All @@ -147,7 +136,7 @@ describe('lg operation', () => {
const lgFiles = await proj.createLgFile(id, content, dir);
const result = lgFiles.find(f => f.id === id);

expect(proj.files.length).toEqual(9);
expect(proj.files.length).toEqual(8);
expect(lgFiles.length).toEqual(2);

expect(result).not.toBeUndefined();
Expand All @@ -163,7 +152,7 @@ describe('lg operation', () => {
const lgFiles = await proj.updateLgFile(id, content);
const result = lgFiles.find(f => f.id === id);

expect(proj.files.length).toEqual(9);
expect(proj.files.length).toEqual(8);
expect(lgFiles.length).toEqual(2);

expect(result).not.toBeUndefined();
Expand All @@ -178,7 +167,7 @@ describe('lg operation', () => {
const lgFiles = await proj.removeLgFile(id);
const result = lgFiles.find(f => f.id === id);

expect(proj.files.length).toEqual(8);
expect(proj.files.length).toEqual(7);
expect(lgFiles.length).toEqual(1);

expect(result).toBeUndefined();
Expand All @@ -188,7 +177,7 @@ describe('lg operation', () => {
describe('lu operation', () => {
afterEach(() => {
try {
fs.rmdirSync(Path.resolve(__dirname, `${botDir}/root`));
fs.rmdirSync(Path.resolve(__dirname, `${botDir} / root`));
} catch (err) {
// ignore
}
Expand All @@ -201,7 +190,7 @@ describe('lu operation', () => {
const luFiles = await proj.createLuFile(id, content, dir);
const result = luFiles.find(f => f.id === id);

expect(proj.files.length).toEqual(9);
expect(proj.files.length).toEqual(8);
expect(luFiles.length).toEqual(4);

expect(result).not.toBeUndefined();
Expand All @@ -217,7 +206,7 @@ describe('lu operation', () => {
const luFiles = await proj.updateLuFile(id, content);
const result = luFiles.find(f => f.id === id);

expect(proj.files.length).toEqual(9);
expect(proj.files.length).toEqual(8);
expect(luFiles.length).toEqual(4);

expect(result).not.toBeUndefined();
Expand All @@ -232,7 +221,7 @@ describe('lu operation', () => {
const luFiles = await proj.removeLuFile(id);
const result = luFiles.find(f => f.id === id);

expect(proj.files.length).toEqual(8);
expect(proj.files.length).toEqual(7);
expect(luFiles.length).toEqual(3);

expect(result).toBeUndefined();
Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/server/__tests__/services/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jest.mock('../../src/store/store', () => {

jest.mock('azure-storage', () => {});

const projPath = Path.resolve(__dirname, '../mocks/samplebots/bot1/1.botproj');
const projPath = Path.resolve(__dirname, '../mocks/samplebots/bot1');

const saveAsDir = Path.resolve(__dirname, '../mocks/samplebots/saveas');

Expand All @@ -44,15 +44,15 @@ describe('test BotProjectService', () => {
};
await projectService.openProject(botProj);
expect(projectService.currentBotProject).toBeDefined();
expect((projectService.currentBotProject as BotProject).absolutePath).toBe(projPath);
expect((projectService.currentBotProject as BotProject).dir).toBe(projPath);
});
it('saveProjectAs', async () => {
const botProj = {
storageId: 'default',
path: saveAsDir,
};
await projectService.saveProjectAs(botProj);
expect((projectService.currentBotProject as BotProject).absolutePath).toBe(`${saveAsDir}/1.botproj`);
expect((projectService.currentBotProject as BotProject).dir).toBe(`${saveAsDir}`);
// remove the saveas files
try {
rimraf.sync(saveAsDir);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 3 additions & 22 deletions Composer/packages/server/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,13 @@ async function openProject(req: Request, res: Response) {
return;
}

//find *.botproj
const storage = StorageService.getStorageClient(req.body.storageId);
const botprojPaths = await storage.glob('**/*.botproj', req.body.path);

if (botprojPaths.length !== 1) {
res.status(400).json('unsupported project file type, expect .botproj');
return;
}

const locationRef: LocationRef = {
const location: LocationRef = {
storageId: req.body.storageId,
path: Path.join(req.body.path, botprojPaths[0]),
path: req.body.path,
};

try {
await ProjectService.openProject(locationRef);
await ProjectService.openProject(location);
if (ProjectService.currentBotProject !== undefined) {
const project = await ProjectService.currentBotProject.getIndexes();
res.status(200).json({
Expand Down Expand Up @@ -122,15 +113,6 @@ async function updateDialog(req: Request, res: Response) {
}
}

async function updateBotFile(req: Request, res: Response) {
if (ProjectService.currentBotProject !== undefined) {
const botFile = await ProjectService.currentBotProject.updateBotFile(req.body.name, req.body.content);
res.status(200).json({ botFile });
} else {
res.status(404).json({ error: 'No bot project opened' });
}
}

async function createDialog(req: Request, res: Response) {
if (ProjectService.currentBotProject !== undefined) {
const dialogs = await ProjectService.currentBotProject.createDialog(req.body.name);
Expand Down Expand Up @@ -230,7 +212,6 @@ export const ProjectController = {
createLuFile,
removeLuFile,
publishLuis,
updateBotFile,
saveProjectAs,
createProject,
getAllProjects,
Expand Down
37 changes: 11 additions & 26 deletions Composer/packages/server/src/models/asset/assetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,17 @@ export class AssetManager {

public async copyProjectTemplateTo(templateId: string, ref: LocationRef): Promise<LocationRef> {
const template = find(this.projectTemplates, { id: templateId });
if (template !== undefined && template.path !== undefined) {
// user storage maybe diff from template storage
const dstStorage = StorageService.getStorageClient(ref.storageId);
const dstDir = Path.resolve(ref.path);
if (await dstStorage.exists(dstDir)) {
throw new Error('already have this folder, please give another name');
}

await copyDir(template.path, this.templateStorage, dstDir, dstStorage);

const oldBotprojPaths = await dstStorage.glob('**/*.botproj', ref.path);

if (oldBotprojPaths && oldBotprojPaths.length === 1) {
const oldBotprojPath = Path.join(ref.path, oldBotprojPaths[0]);
const botPath = Path.dirname(oldBotprojPath);
const botName = Path.basename(ref.path);
const newBotprojPath = Path.join(botPath, `${botName}.botproj`);
await dstStorage.rename(oldBotprojPath, newBotprojPath);
return {
storageId: ref.storageId,
path: newBotprojPath,
};
} else {
throw new Error('more than one botproj');
}
if (template === undefined || template.path === undefined) {
throw new Error(`no such template with id ${templateId}`);
}
// user storage maybe diff from template storage
const dstStorage = StorageService.getStorageClient(ref.storageId);
const dstDir = Path.resolve(ref.path);
if (await dstStorage.exists(dstDir)) {
throw new Error('already have this folder, please give another name');
}
throw new Error('no template botproject');

await copyDir(template.path, this.templateStorage, dstDir, dstStorage);
return ref;
}
}
Loading

0 comments on commit eb2d233

Please sign in to comment.