Skip to content

Commit

Permalink
redo on a clean master
Browse files Browse the repository at this point in the history
  • Loading branch information
boydc2014 committed May 5, 2020
1 parent c329a2f commit 2370c68
Show file tree
Hide file tree
Showing 229 changed files with 805 additions and 363 deletions.
4 changes: 3 additions & 1 deletion Composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"build:server": "yarn workspace @bfc/server build",
"build:client": "yarn workspace @bfc/client build",
"build:tools": "yarn workspace @bfc/tools build:all",
"build:plugins": "cd plugins/localPublish && yarn install && yarn build",
"build:plugins": "yarn build:plugins:localpublish && yarn build:plugins:samples",
"build:plugins:localpublish": "cd plugins/localPublish && yarn install && yarn build",
"build:plugins:samples": "cd plugins/samples && yarn install && yarn build",
"start": "cross-env NODE_ENV=production PORT=3000 yarn start:server",
"startall": "node scripts/update.js && yarn start",
"start:dev": "concurrently \"npm:start:client\" \"npm:start:server:dev\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { JSONSchema7 } from 'json-schema';

import { PluginLoader } from './pluginLoader';
import log from './logger';
import { PublishPlugin, RuntimeTemplate } from './types';
import { PublishPlugin, RuntimeTemplate, BotTemplate } from './types';

export class ComposerPluginRegistration {
public loader: PluginLoader;
Expand Down Expand Up @@ -88,6 +88,20 @@ export class ComposerPluginRegistration {
this.loader.extensions.runtimeTemplates.push(plugin);
}

/**************************************************************************************
* Add Bot Template (aka, SampleBot)
*************************************************************************************/
public addBotTemplate(template: BotTemplate) {
this.loader.extensions.botTemplates.push(template);
}

/**************************************************************************************
* Add Base Template (aka, BoilerPlate)
*************************************************************************************/
public addBaseTemplate(template: BotTemplate) {
this.loader.extensions.baseTemplates.push(template);
}

/**************************************************************************************
* Express/web related features
*************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class PluginLoader {
allowedUrls: [this.loginUri],
},
runtimeTemplates: [],
botTemplates: [],
baseTemplates: [],
};
this._passport = passport;
}
Expand Down
11 changes: 11 additions & 0 deletions Composer/packages/extensions/plugin-loader/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export interface PublishResponse {
result: PublishResult;
}

export interface BotTemplate {
id: string;
name: string;
description: string;
path: string; // absolute path
tags?: string[]; // tags for further grouping and search secenario
support?: string[]; // list of supported runtime versions
}

// TODO: Add types for project, metadata
export interface PublishPlugin<Config = any> {
publish: (config: Config, project: any, metadata: any, user?: UserIdentity) => Promise<PublishResponse>;
Expand Down Expand Up @@ -71,4 +80,6 @@ export interface ExtensionCollection {
[key: string]: any;
};
runtimeTemplates: RuntimeTemplate[];
botTemplates: BotTemplate[];
baseTemplates: BotTemplate[];
}
7 changes: 3 additions & 4 deletions Composer/packages/lib/shared/src/types/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export interface ProjectTemplate {
id: string;
name: string;
description: string;
/** Absolute path of the template */
path?: string;
/** Optional order property */
order?: number;
path: string; // absolute path
tags?: string[]; // tags for further grouping and search secenario
support?: string[]; // list of supported runtime versions
}
26 changes: 25 additions & 1 deletion Composer/packages/server/__tests__/controllers/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@

import { Request, Response } from 'express';
import rimraf from 'rimraf';
import { pluginLoader } from '@bfc/plugin-loader';

import { BotProjectService } from '../../src/services/project';
import { ProjectController } from '../../src/controllers/project';
import { Path } from '../../src/utility/path';

jest.mock('@bfc/plugin-loader', () => {
//const p = require('path');
return {
pluginLoader: {
extensions: {
botTemplates: [],
baseTemplates: [],
},
},
PluginLoader: {
getUserFromRequest: jest.fn(),
},
};
});

const mockSampleBotPath = Path.join(__dirname, '../mocks/asset/projects/SampleBot');

let mockRes: Response;

const newBot = Path.resolve(__dirname, '../mocks/samplebots/newBot');
Expand All @@ -34,6 +52,12 @@ beforeEach(() => {
});

beforeAll(async () => {
pluginLoader.extensions.botTemplates.push({
id: 'SampleBot',
name: 'Sample Bot',
description: 'Sample Bot',
path: mockSampleBotPath,
});
const currentProjectId = await BotProjectService.openProject(location1);
const currentProject = await BotProjectService.getProjectById(currentProjectId);
await BotProjectService.saveProjectAs(currentProject, location2);
Expand Down Expand Up @@ -134,7 +158,7 @@ describe('create a Empty Bot project', () => {
const mockReq = {
params: {},
query: {},
body: { storageId: 'default', location: newBotDir, description: '', name: name, templateId: '' },
body: { storageId: 'default', location: newBotDir, description: '', name: name, templateId: 'SampleBot' },
} as Request;
await ProjectController.createProject(mockReq, mockRes);
expect(mockRes.status).toHaveBeenCalledWith(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,53 @@
// Licensed under the MIT License.

import rimraf from 'rimraf';
import { pluginLoader } from '@bfc/plugin-loader';

import { Path } from '../../../src/utility/path';
import { AssetManager } from '../../../src/models/asset/assetManager';
jest.mock('azure-storage', () => {
return {};
});
const mockAssetLibraryPath = Path.join(__dirname, '../../mocks/asset');
const mockRuntimeLibraryPath = Path.join(__dirname, '../../mocks/runtimes');

jest.mock('@bfc/plugin-loader', () => {
//const p = require('path');
return {
pluginLoader: {
extensions: {
botTemplates: [],
},
},
};
});

const mockSampleBotPath = Path.join(__dirname, '../../mocks/asset/projects/SampleBot');
const mockCopyToPath = Path.join(__dirname, '../../mocks/new');
const locationRef = {
storageId: 'default',
path: mockCopyToPath,
};

beforeAll(() => {
pluginLoader.extensions.botTemplates.push({
id: 'SampleBot',
name: 'Sample Bot',
description: 'Sample Bot',
path: mockSampleBotPath,
});
});

describe('assetManager', () => {
it('getProjectTemplate', async () => {
const assetManager = new AssetManager(mockAssetLibraryPath, mockRuntimeLibraryPath);
const assetManager = new AssetManager();
const result = await assetManager.getProjectTemplates();
expect(result.length).toBeGreaterThan(0);
expect(result[0].name).toBe('Sample Bot');
expect(result[0].id).toBe('SampleBot');
});

it('copyProjectTemplateTo', async () => {
const assetManager = new AssetManager(mockAssetLibraryPath, mockRuntimeLibraryPath);
const assetManager = new AssetManager();
await assetManager.getProjectTemplates();
await assetManager.getProjectRuntime();

await expect(assetManager.copyProjectTemplateTo('SampleBot', locationRef)).resolves.toBe(locationRef);
// remove the saveas files
Expand Down
Loading

0 comments on commit 2370c68

Please sign in to comment.