Skip to content

Commit

Permalink
refactor: rename apiPlugin to plugin (#11011)
Browse files Browse the repository at this point in the history
* refactor: rename apiPlugin to plugin

* refactor: minor

* refactor: rename
  • Loading branch information
yuqizhou77 authored Mar 8, 2024
1 parent 4c89d70 commit e3ec125
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,13 @@ export class CreateAppPackageDriver implements StepDriver {
}

// API plugin
if (
manifest.apiPlugins &&
manifest.apiPlugins.length > 0 &&
manifest.apiPlugins[0].pluginFile
) {
const pluginFile = path.resolve(appDirectory, manifest.apiPlugins[0].pluginFile);
if (manifest.plugins && manifest.plugins.length > 0 && manifest.plugins[0].pluginFile) {
const pluginFile = path.resolve(appDirectory, manifest.plugins[0].pluginFile);
const checkExistenceRes = await this.validateReferencedFile(pluginFile, appDirectory);
if (checkExistenceRes.isErr()) {
return err(checkExistenceRes.error);
}
const dir = path.dirname(manifest.apiPlugins[0].pluginFile);
const dir = path.dirname(manifest.plugins[0].pluginFile);
this.addFileInZip(zip, dir, pluginFile);

const addFilesRes = await this.addPluginRelatedFiles(zip, pluginFile, appDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class ManifestUtils {
manifest: TeamsAppManifest,
manifestPath: string
): Promise<Result<string, FxError>> {
const pluginFile = manifest.apiPlugins?.[0]?.pluginFile;
const pluginFile = manifest.plugins?.[0]?.pluginFile;
if (pluginFile) {
const plugin = path.resolve(path.dirname(manifestPath), pluginFile);
const doesFileExist = await fs.pathExists(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ export class CopilotPluginGenerator {
destinationPath: string,
templateName: string,
componentName: string,
isApiPlugin: boolean,
isPlugin: boolean,
apiKeyAuthData?: ApiKeyAuthInfo
): Promise<Result<CopilotPluginGeneratorResult, FxError>> {
try {
const appName = inputs[QuestionNames.AppName];
const language = inputs[QuestionNames.ProgrammingLanguage];
const safeProjectNameFromVS =
language === "csharp" ? inputs[QuestionNames.SafeProjectName] : undefined;
const type = isApiPlugin ? GenerateType.ApiPlugin : GenerateType.ME;
const type = isPlugin ? GenerateType.ApiPlugin : GenerateType.ME;

const manifestPath = path.join(
destinationPath,
Expand Down
8 changes: 4 additions & 4 deletions packages/fx-core/src/question/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ export function apiOperationQuestion(includeExistingAPIs = true): MultiSelectQue
// export for unit test
let placeholder = "";

const isApiPlugin = (inputs?: Inputs): boolean => {
const isPlugin = (inputs?: Inputs): boolean => {
return (
!!inputs && inputs[QuestionNames.Capabilities] === CapabilityOptions.copilotPluginApiSpec().id
);
Expand All @@ -1863,20 +1863,20 @@ export function apiOperationQuestion(includeExistingAPIs = true): MultiSelectQue
type: "multiSelect",
name: QuestionNames.ApiOperation,
title: (inputs: Inputs) => {
return isApiPlugin(inputs)
return isPlugin(inputs)
? getLocalizedString("core.createProjectQuestion.apiSpec.copilotOperation.title")
: getLocalizedString("core.createProjectQuestion.apiSpec.operation.title");
},
cliDescription: "Select Operation(s) Teams Can Interact with.",
cliShortName: "o",
placeholder: (inputs: Inputs) => {
const isApiPlugin =
const isPlugin =
inputs[QuestionNames.Capabilities] === CapabilityOptions.copilotPluginApiSpec().id;
if (!includeExistingAPIs) {
placeholder = getLocalizedString(
"core.createProjectQuestion.apiSpec.operation.placeholder.skipExisting"
);
} else if (isApiPlugin) {
} else if (isPlugin) {
placeholder = ""; // TODO: add placeholder for api plugin
} else if (isApiKeyEnabled()) {
placeholder = getLocalizedString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe("teamsApp/createAppPackage", async () => {
});

const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "plugin.json",
},
Expand Down Expand Up @@ -247,7 +247,7 @@ describe("teamsApp/createAppPackage", async () => {
});

const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "resources/ai-plugin.json",
},
Expand Down Expand Up @@ -278,7 +278,7 @@ describe("teamsApp/createAppPackage", async () => {
sinon.stub(fs, "readJSON").throws(new Error("fake error"));

const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "resources/ai-plugin.json",
},
Expand Down Expand Up @@ -590,7 +590,7 @@ describe("teamsApp/createAppPackage", async () => {
};

const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "resources/ai-plugin.json",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("pluginManifestUtils", () => {
staticTabs: [],
permissions: [],
validDomains: [],
apiPlugins: [
plugins: [
{
pluginFile: "resources/plugin.json",
},
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("pluginManifestUtils", () => {
sandbox.stub(fs, "pathExists").resolves(true);

const res = await pluginManifestUtils.getApiSpecFilePathFromTeamsManifest(
{ ...teamsManifest, apiPlugins: [] },
{ ...teamsManifest, plugins: [] },
"/test/path"
);
chai.assert.isTrue(res.isErr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ describe("formatValidationErrors", () => {
describe("listPluginExistingOperations", () => {
const teamsManifestWithPlugin: TeamsAppManifest = {
...teamsManifest,
apiPlugins: [
plugins: [
{
pluginFile: "resources/plugin.json",
},
Expand Down
4 changes: 2 additions & 2 deletions packages/fx-core/tests/core/FxCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ describe("copilotPlugin", async () => {
projectPath: path.join(os.tmpdir(), appName),
};
const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "ai-plugin.json",
},
Expand Down Expand Up @@ -1705,7 +1705,7 @@ describe("copilotPlugin", async () => {
projectPath: path.join(os.tmpdir(), appName),
};
const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "ai-plugin.json",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/manifest/src/ManifestCommonProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export interface ManifestCommonProperties {
/**
* Whether it's an API plugin
*/
isApiPlugin: boolean;
isPlugin: boolean;
}
8 changes: 4 additions & 4 deletions packages/manifest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ManifestUtil {
manifestVersion: manifest.manifestVersion,
isApiME: false,
isSPFx: false,
isApiPlugin: false,
isPlugin: false,
};

// If it's copilot plugin app
Expand All @@ -155,10 +155,10 @@ export class ManifestUtil {
properties.isSPFx = true;
}

if ((manifest as TeamsAppManifest).apiPlugins) {
const apiPlugins = (manifest as TeamsAppManifest).apiPlugins;
if ((manifest as TeamsAppManifest).plugins) {
const apiPlugins = (manifest as TeamsAppManifest).plugins;
if (apiPlugins && apiPlugins.length > 0 && apiPlugins[0].pluginFile)
properties.isApiPlugin = true;
properties.isPlugin = true;
}

return properties;
Expand Down
6 changes: 3 additions & 3 deletions packages/manifest/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export interface ITogetherModeScene {
seatsReservedForOrganizersOrPresenters: number;
}

export interface IApiPlugin {
export interface IPlugin {
pluginFile: string;
}

Expand Down Expand Up @@ -541,7 +541,7 @@ export class TeamsAppManifest implements AppManifest {
};
};
/**
* Pointer to Plugin manifest.
* Pointer to plugin manifest.
*/
apiPlugins?: IApiPlugin[];
plugins?: IPlugin[];
}
2 changes: 1 addition & 1 deletion packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ManifestUpdater {
): Promise<[TeamsAppManifest, PluginManifestSchema]> {
const manifest: TeamsAppManifest = await fs.readJSON(manifestPath);
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: apiPluginRelativePath,
},
Expand Down
24 changes: 12 additions & 12 deletions packages/spec-parser/test/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ describe("updateManifestWithAiPlugin", () => {
const expectedManifest = {
name: { short: "Original Name", full: "Original Full Name" },
description: { short: "My API", full: "My API description" },
apiPlugins: [
plugins: [
{
pluginFile: "ai-plugin.json",
},
],
};

const expectedApiPlugins: PluginManifestSchema = {
const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
name_for_human: "My API",
description_for_human: "My API description",
Expand Down Expand Up @@ -147,7 +147,7 @@ describe("updateManifestWithAiPlugin", () => {
);

expect(manifest).to.deep.equal(expectedManifest);
expect(apiPlugin).to.deep.equal(expectedApiPlugins);
expect(apiPlugin).to.deep.equal(expectedPlugins);
});

it("should update the manifest with the correct manifest and apiPlugin files with optional parameters", async () => {
Expand Down Expand Up @@ -221,14 +221,14 @@ describe("updateManifestWithAiPlugin", () => {
const expectedManifest = {
name: { short: "Original Name", full: "Original Full Name" },
description: { short: "My API", full: "My API description" },
apiPlugins: [
plugins: [
{
pluginFile: "ai-plugin.json",
},
],
};

const expectedApiPlugins: PluginManifestSchema = {
const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
name_for_human: "My API",
description_for_human: "My API description",
Expand Down Expand Up @@ -289,7 +289,7 @@ describe("updateManifestWithAiPlugin", () => {
);

expect(manifest).to.deep.equal(expectedManifest);
expect(apiPlugin).to.deep.equal(expectedApiPlugins);
expect(apiPlugin).to.deep.equal(expectedPlugins);
});

it("should generate default ai plugin file if no api", async () => {
Expand Down Expand Up @@ -318,14 +318,14 @@ describe("updateManifestWithAiPlugin", () => {
const expectedManifest = {
name: { short: "Original Name", full: "Original Full Name" },
description: { short: "My API", full: "My API description" },
apiPlugins: [
plugins: [
{
pluginFile: "ai-plugin.json",
},
],
};

const expectedApiPlugins: PluginManifestSchema = {
const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
name_for_human: "My API",
description_for_human: "My API description",
Expand Down Expand Up @@ -353,7 +353,7 @@ describe("updateManifestWithAiPlugin", () => {
);

expect(manifest).to.deep.equal(expectedManifest);
expect(apiPlugin).to.deep.equal(expectedApiPlugins);
expect(apiPlugin).to.deep.equal(expectedPlugins);
});

it("should truncate if title is long", async () => {
Expand Down Expand Up @@ -425,14 +425,14 @@ describe("updateManifestWithAiPlugin", () => {
short: "long title long title long title long title long title long title long title lon",
full: "This is the description",
},
apiPlugins: [
plugins: [
{
pluginFile: "ai-plugin.json",
},
],
};

const expectedApiPlugins: PluginManifestSchema = {
const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
name_for_human:
"long title long title long title long title long title long title long title long title long title long title long title long title",
Expand Down Expand Up @@ -490,7 +490,7 @@ describe("updateManifestWithAiPlugin", () => {
);

expect(manifest).to.deep.equal(expectedManifest);
expect(apiPlugin).to.deep.equal(expectedApiPlugins);
expect(apiPlugin).to.deep.equal(expectedPlugins);
});

it("should throw error if has nested object property", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ export class ApiPluginCodeLensProvider implements vscode.CodeLensProvider {
const manifestContent = fs.readFileSync(manifestFilePath, "utf-8");
const manifest = JSON.parse(manifestContent);
const manifestProperties = ManifestUtil.parseCommonProperties(manifest);
if (!manifestProperties.isApiPlugin) {
if (!manifestProperties.isPlugin) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe("Api plugin CodeLensProvider", () => {

it("Add API", async () => {
const manifest = new TeamsAppManifest();
manifest.apiPlugins = [
manifest.plugins = [
{
pluginFile: "test.json",
},
Expand Down Expand Up @@ -433,7 +433,7 @@ describe("Api plugin CodeLensProvider", () => {

it("Do not show codelens for if not API plugin project", async () => {
const manifest = new TeamsAppManifest();
manifest.apiPlugins = [];
manifest.plugins = [];
const openApiObject = {
openapi: "3.0",
};
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/test/extension/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,7 @@ describe("autoOpenProjectHandler", () => {
isApiME: true,
isSPFx: false,
isApiBasedMe: true,
isApiPlugin: false,
isPlugin: false,
};
const parseManifestStub = sandbox.stub(ManifestUtil, "parseCommonProperties").returns(parseRes);
VsCodeLogInstance.outputChannel = {
Expand Down

0 comments on commit e3ec125

Please sign in to comment.