Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dc with api plugin generator & template update #12104

Merged
merged 14 commits into from
Jul 30, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Context, FxError, Inputs, ok, Result } from "@microsoft/teamsfx-api";
import { DefaultTemplateGenerator } from "../templates/templateGenerator";
import {
ApiAuthOptions,
ApiPluginStartOptions,
CapabilityOptions,
ProgrammingLanguage,
QuestionNames,
} from "../../../question";
import { ActionContext } from "../../middleware/actionExecutionMW";
import { Generator } from "../generator";
import { merge } from "lodash";
Fixed Show fixed Hide fixed
import { TemplateNames } from "../templates/templateNames";
import { TemplateInfo } from "../templates/templateInfo";

/**
* @author [email protected]
*/

export class DeclarativeCopilotActionGenerator extends DefaultTemplateGenerator {
public activate(context: Context, inputs: Inputs): boolean {
return (
(inputs[QuestionNames.Capabilities] === CapabilityOptions.declarativeCopilot().id ||
inputs[QuestionNames.Capabilities] === CapabilityOptions.apiPlugin().id) &&
inputs[QuestionNames.ApiPluginType] === ApiPluginStartOptions.newApi().id
);
}

public getTemplateInfos(
context: Context,
inputs: Inputs,
destinationPath: string,
actionContext?: ActionContext
): Promise<Result<TemplateInfo[], FxError>> {
const auth = inputs[QuestionNames.ApiAuth];
const appName = inputs[QuestionNames.AppName];
const language = inputs[QuestionNames.ProgrammingLanguage] as ProgrammingLanguage;
const safeProjectNameFromVS =
language === "csharp" ? inputs[QuestionNames.SafeProjectName] : undefined;
const isDeclarativeCopilot =
inputs[QuestionNames.Capabilities] === CapabilityOptions.declarativeCopilot().id;

const replaceMap = {
...Generator.getDefaultVariables(
appName,
safeProjectNameFromVS,
inputs.targetFramework,
inputs.placeProjectFileInSolutionDir === "true"
),
DeclarativeCopilot: isDeclarativeCopilot ? "true" : "",
};

const filterFn = (fileName: string) => {
if (fileName.startsWith("repairDeclarativeCopilot.json")) {
return isDeclarativeCopilot;
} else {
return true;
}
};

if (auth === ApiAuthOptions.none()) {
return ok([
{
templateName: TemplateNames.ApiPluginFromScratch,
language: language,
replaceMap,
filterFn,
},
]);
} else if (auth === ApiAuthOptions.apiKey()) {
return ok([
{
templateName: TemplateNames.ApiPluginFromScratchBearer,
language: language,
replaceMap,
filterFn,
},
]);
} else if (auth === ApiAuthOptions.oauth()) {
return ok([
{
templateName: TemplateNames.ApiPluginFromScratchOAuth,
language: language,
replaceMap,
filterFn,
},
]);
} else {
return ok([]);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SpecGenerator } from "./apiSpec/generator";
import { DeclarativeCopilotActionGenerator } from "./declarativeCopilotAction/generator";
import { OfficeAddinGeneratorNew } from "./officeAddin/generator";
import { SPFxGeneratorImport, SPFxGeneratorNew } from "./spfx/spfxGenerator";
import { SsrTabGenerator } from "./templates/ssrTabGenerator";
Expand All @@ -14,4 +15,5 @@ export const Generators = [
new SPFxGeneratorNew(),
new SPFxGeneratorImport(),
new SpecGenerator(),
new DeclarativeCopilotActionGenerator(),
];
120 changes: 0 additions & 120 deletions templates/js/api-plugin-from-scratch/.vscode/launch.json

This file was deleted.

143 changes: 0 additions & 143 deletions templates/js/api-plugin-from-scratch/.vscode/tasks.json

This file was deleted.

Loading
Loading