-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(generator): mapping user inputs to template names (#11450)
* refactor: get template name by matching inputs * refactor: set default replace map * refactor: use a map instead of a list
- Loading branch information
Showing
7 changed files
with
309 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { OfficeAddinGeneratorNew } from "./officeAddin/generator"; | ||
import { SsrTabGenerator } from "./templates/ssrTabGenerator"; | ||
import { DefaultTemplateGenerator } from "./templates/templateGenerator"; | ||
|
||
export const Generators = [new DefaultTemplateGenerator(), new OfficeAddinGeneratorNew()]; | ||
// When multiple generators are activated, only the top one will be executed. | ||
export const Generators = [ | ||
new OfficeAddinGeneratorNew(), | ||
new SsrTabGenerator(), | ||
new DefaultTemplateGenerator(), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/fx-core/src/component/generator/templates/ssrTabGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { Context, FxError, Inputs, Result, ok } from "@microsoft/teamsfx-api"; | ||
import { DefaultTemplateGenerator } from "./templateGenerator"; | ||
import { TemplateInfo } from "./templateInfo"; | ||
import { CapabilityOptions, ProgrammingLanguage, QuestionNames } from "../../../question"; | ||
import { TemplateNames } from "./templateNames"; | ||
|
||
// For the APS.NET server-side rendering tab | ||
export class SsrTabGenerator extends DefaultTemplateGenerator { | ||
capabilities2TemplateNames = { | ||
[CapabilityOptions.nonSsoTab().id]: TemplateNames.TabSSR, | ||
[CapabilityOptions.tab().id]: TemplateNames.SsoTabSSR, | ||
}; | ||
override activate(context: Context, inputs: Inputs): boolean { | ||
const capability = inputs.capabilities as string; | ||
return ( | ||
this.capabilities2TemplateNames[capability] !== undefined && | ||
inputs[QuestionNames.ProgrammingLanguage] === ProgrammingLanguage.CSharp && | ||
inputs.targetFramework !== "net6.0" && | ||
inputs.targetFramework !== "net7.0" | ||
); | ||
} | ||
override getTemplateInfos( | ||
context: Context, | ||
inputs: Inputs | ||
): Promise<Result<TemplateInfo[], FxError>> { | ||
return Promise.resolve( | ||
ok([ | ||
{ | ||
templateName: this.capabilities2TemplateNames[inputs.capabilities as string], | ||
language: ProgrammingLanguage.CSharp, | ||
}, | ||
]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.