Skip to content

Commit

Permalink
Make enclusion in the eject list dependent on the runtime plugin impl…
Browse files Browse the repository at this point in the history
…ementing the eject method (#6020)

Remove eject method from v2 runtime
Correct ejected path of runtime to match relative path
  • Loading branch information
benbrown authored Feb 26, 2021
1 parent b05aa30 commit 43355d4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Composer/packages/server/src/controllers/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { LocalDiskStorage } from '../models/storage/localDiskStorage';

export const EjectController = {
getTemplates: async (req, res) => {
res.json(ExtensionContext.extensions.runtimeTemplates);
res.json(ExtensionContext.extensions.runtimeTemplates.filter((t) => (t.eject ? true : false)));
},
eject: async (req, res) => {
const user = await ExtensionContext.getUserFromRequest(req);
const projectId = req.params.projectId;
const currentProject = await BotProjectService.getProjectById(projectId, user);

const template = ExtensionContext.extensions.runtimeTemplates.find((i) => i.key === req.params.template);
if (template) {
if (template?.eject) {
let runtimePath;
try {
runtimePath = await template.eject(currentProject, new LocalDiskStorage(), req.body?.isReplace);
Expand Down
3 changes: 3 additions & 0 deletions Composer/packages/server/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,9 @@
"downloading_bb6fb34b": {
"message": "Downloading..."
},
"downloading_language_model_9d40c817": {
"message": "Downloading Language Model"
},
"duplicate_31cec192": {
"message": "Duplicate"
},
Expand Down
7 changes: 5 additions & 2 deletions Composer/packages/server/src/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ export async function ejectAndMerge(currentProject: BotProject, jobId: string) {
const runtimePath = currentProject.getRuntimePath();
if (runtimePath) {
if (!fs.existsSync(runtimePath)) {
await runtime.eject(currentProject, currentProject.fileStorage);
if (runtime.eject) {
await runtime.eject(currentProject, currentProject.fileStorage);
} else {
log('Eject skipped for project with invalid runtime setting');
}
}

// install all dependencies and build the app
BackgroundProcessManager.updateProcess(jobId, 202, formatMessage('Building runtime'));
await runtime.build(runtimePath, currentProject);
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/types/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type BotTemplate = {

export type RuntimeTemplate = {
/** method used to eject the runtime into a project. returns resulting path of runtime! */
eject: (project: IBotProject, localDisk?: any, isReplace?: boolean) => Promise<string>;
eject?: (project: IBotProject, localDisk?: any, isReplace?: boolean) => Promise<string>;

/** build method used for local publish */
build: (runtimePath: string, project: IBotProject) => Promise<void>;
Expand Down
31 changes: 2 additions & 29 deletions extensions/runtimes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default async (composer: any): Promise<void> => {
await copyDir(schemaSrcPath, localDisk, schemaDstPath, project.fileStorage, pathsToExclude);
const schemaFolderInRuntime = path.join(destPath, 'azurewebapp/Schemas');
await removeDirAndFiles(schemaFolderInRuntime);
return path.relative(project.dir, destPath);
return path.relative(path.join(project.dir, 'settings'), destPath);
}
throw new Error(`Runtime already exists at ${destPath}`);
},
Expand Down Expand Up @@ -308,7 +308,7 @@ export default async (composer: any): Promise<void> => {
const schemaFolderInRuntime = path.join(destPath, 'schemas');
await removeDirAndFiles(schemaFolderInRuntime);

return path.relative(project.dir, destPath);
return path.relative(path.join(project.dir, 'settings'), destPath);
}
throw new Error(`Runtime already exists at ${destPath}`);
},
Expand Down Expand Up @@ -452,33 +452,6 @@ export default async (composer: any): Promise<void> => {
// return the location of the build artifiacts
return publishFolder;
},
eject: async (project, localDisk: IFileStorage, isReplace: boolean) => {
const sourcePath = dotnetTemplatePath;
const destPath = path.join(project.dir, 'runtime');
if ((await project.fileStorage.exists(destPath)) && isReplace) {
// remove runtime folder
await removeDirAndFiles(destPath);
}
if (!(await project.fileStorage.exists(destPath))) {
// used to read bot project template from source (bundled in plugin)
await copyDir(sourcePath, localDisk, destPath, project.fileStorage);
const schemaDstPath = path.join(project.dir, 'schemas');
const schemaSrcPath = path.join(sourcePath, 'azurewebapp/Schemas');
const customSchemaExists = fs.existsSync(schemaDstPath);
const pathsToExclude: Set<string> = new Set();
if (customSchemaExists) {
const sdkExcludePath = await localDisk.glob('sdk.schema', schemaSrcPath);
if (sdkExcludePath.length > 0) {
pathsToExclude.add(path.join(schemaSrcPath, sdkExcludePath[0]));
}
}
await copyDir(schemaSrcPath, localDisk, schemaDstPath, project.fileStorage, pathsToExclude);
const schemaFolderInRuntime = path.join(destPath, 'azurewebapp/Schemas');
await removeDirAndFiles(schemaFolderInRuntime);
return path.relative(project.dir, destPath);
}
throw new Error(`Runtime already exists at ${destPath}`);
},
setSkillManifest: async (
dstRuntimePath: string,
dstStorage: IFileStorage,
Expand Down

0 comments on commit 43355d4

Please sign in to comment.