зеркало из https://github.com/Azure/autorest.az.git
Refactor Generator Phase 1 (#502)
This commit is contained in:
Родитель
f2708d2114
Коммит
a2604ef91f
|
@ -0,0 +1,71 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { AzGeneratorBase } from "./AzGeneratorBase";
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
import { GenerateAzureCliActions } from "./TemplateAzureCliActions";
|
||||
import { GenerateAzureCliAzextMetadata } from "./TemplateAzureCliAzextMetadata";
|
||||
import { GenerateAzureCliClientFactory } from "./TemplateAzureCliClientFactory";
|
||||
import { GenerateAzureCliCommands } from "./TemplateAzureCliCommands";
|
||||
import { GenerateAzureCliCustom } from "./TemplateAzureCliCustom";
|
||||
import { GenerateAzureCliHelp } from "./TemplateAzureCliHelp";
|
||||
import { GenerateAzureCliHistory } from "./TemplateAzureCliHistory";
|
||||
import { GenerateAzureCliInit } from "./TemplateAzureCliInit";
|
||||
import { GenerateNamespaceInit } from "./TemplateAzureCliNamespaceInit";
|
||||
import { GenerateAzureCliParams } from "./TemplateAzureCliParams";
|
||||
import { GenerateAzureCliReadme } from "./TemplateAzureCliReadme";
|
||||
import { GenerateAzureCliReport } from "./TemplateAzureCliReport";
|
||||
import { GenerateAzureCliSetupCfg } from "./TemplateAzureCliSetupCfg";
|
||||
import { GenerateAzureCliSetupPy } from "./TemplateAzureCliSetupPy";
|
||||
import { GenerateAzureCliTestInit } from "./TemplateAzureCliTestInit";
|
||||
import { GenerateAzureCliTestPrepare } from "./TemplateAzureCliTestPrepare";
|
||||
import { GenerateAzureCliTestScenario, NeedPreparer } from "./TemplateAzureCliTestScenario";
|
||||
import { GenerateTopLevelImport } from "./TemplateAzureCliTopLevelImport";
|
||||
import { GenerateAzureCliValidators } from "./TemplateAzureCliValidators";
|
||||
|
||||
|
||||
export class AzExtensionFullGenerator extends AzGeneratorBase {
|
||||
constructor(model: CodeModelAz, isDebugMode: boolean) {
|
||||
super(model, isDebugMode);
|
||||
this.path = "azext_" + this.model.Extension_NameUnderscored + "/";
|
||||
}
|
||||
|
||||
|
||||
public generateAll(): void {
|
||||
|
||||
this.files[this.path + "generated/_params.py"] = GenerateAzureCliParams(this.model, this.isDebugMode);
|
||||
this.files[this.path + "generated/commands.py"] = GenerateAzureCliCommands(this.model);
|
||||
this.files[this.path + "generated/custom.py"] = GenerateAzureCliCustom(this.model);
|
||||
this.files[this.path + "generated/_client_factory.py"] = GenerateAzureCliClientFactory(this.model);
|
||||
this.files[this.path + "generated/_validators.py"] = GenerateAzureCliValidators(this.model);
|
||||
this.files[this.path + "generated/action.py"] = GenerateAzureCliActions(this.model);
|
||||
this.files[this.path + "generated/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
this.files[this.path + "tests/__init__.py"] = GenerateAzureCliTestInit(this.model);
|
||||
this.files[this.path + "tests/latest/test_" + this.model.Extension_NameUnderscored + "_scenario.py"] = GenerateAzureCliTestScenario(this.model);
|
||||
if (NeedPreparer()) {
|
||||
this.files[this.path + "tests/latest/preparers.py"] = GenerateAzureCliTestPrepare(this.model);
|
||||
};
|
||||
this.files[this.path + "tests/latest/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
this.files[this.path + "generated/_help.py"] = GenerateAzureCliHelp(this.model, this.isDebugMode);
|
||||
|
||||
|
||||
this.files[this.path + "manual/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
|
||||
this.files[this.path + "vendored_sdks/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
this.files[this.path + "action.py"] = GenerateTopLevelImport(this.model, "action");
|
||||
this.files[this.path + "custom.py"] = GenerateTopLevelImport(this.model, "custom");
|
||||
this.files[this.path + "__init__.py"] = GenerateAzureCliInit(this.model);
|
||||
this.files[this.path + "azext_metadata.json"] = GenerateAzureCliAzextMetadata(this.model);
|
||||
|
||||
this.files["report.md"] = GenerateAzureCliReport(this.model);
|
||||
this.files["HISTORY.rst"] = GenerateAzureCliHistory(this.model);
|
||||
this.files["README.md"] = GenerateAzureCliReadme(this.model);
|
||||
this.files["setup.cfg"] = GenerateAzureCliSetupCfg(this.model);
|
||||
this.files["setup.py"] = GenerateAzureCliSetupPy(this.model);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { AzGeneratorBase } from "./AzGeneratorBase";
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
import { GenerateAzureCliActions } from "./TemplateAzureCliActions";
|
||||
import { GenerateAzureCliClientFactory } from "./TemplateAzureCliClientFactory";
|
||||
import { GenerateAzureCliCommands } from "./TemplateAzureCliCommands";
|
||||
import { GenerateAzureCliCustom } from "./TemplateAzureCliCustom";
|
||||
import { GenerateAzureCliHelp } from "./TemplateAzureCliHelp";
|
||||
import { GenerateNamespaceInit } from "./TemplateAzureCliNamespaceInit";
|
||||
import { GenerateAzureCliParams } from "./TemplateAzureCliParams";
|
||||
import { GenerateAzureCliTestPrepare } from "./TemplateAzureCliTestPrepare";
|
||||
import { GenerateAzureCliTestScenario, NeedPreparer } from "./TemplateAzureCliTestScenario";
|
||||
import { GenerateAzureCliValidators } from "./TemplateAzureCliValidators";
|
||||
|
||||
export class AzExtensionIncrementalGenerator extends AzGeneratorBase {
|
||||
|
||||
constructor(model: CodeModelAz, isDebugMode: boolean) {
|
||||
super(model, isDebugMode);
|
||||
this.path = "azext_" + this.model.Extension_NameUnderscored + "/";
|
||||
}
|
||||
|
||||
public generateAll(): void {
|
||||
this.files[this.path + "generated/_params.py"] = GenerateAzureCliParams(this.model, this.isDebugMode);
|
||||
this.files[this.path + "generated/commands.py"] = GenerateAzureCliCommands(this.model);
|
||||
this.files[this.path + "generated/custom.py"] = GenerateAzureCliCustom(this.model);
|
||||
this.files[this.path + "generated/_client_factory.py"] = GenerateAzureCliClientFactory(this.model);
|
||||
this.files[this.path + "generated/_validators.py"] = GenerateAzureCliValidators(this.model);
|
||||
this.files[this.path + "generated/action.py"] = GenerateAzureCliActions(this.model);
|
||||
this.files[this.path + "generated/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
this.files[this.path + "tests/latest/test_" + this.model.Extension_NameUnderscored + "_scenario.py"] = GenerateAzureCliTestScenario(this.model);
|
||||
if (NeedPreparer()) {
|
||||
this.files[this.path + "tests/latest/preparers.py"] = GenerateAzureCliTestPrepare(this.model);
|
||||
};
|
||||
|
||||
this.files[this.path + "generated/_help.py"] = GenerateAzureCliHelp(this.model, this.isDebugMode);
|
||||
|
||||
|
||||
this.files[this.path + "manual/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
|
||||
this.files[this.path + "vendored_sdks/__init__.py"] = GenerateNamespaceInit(this.model);
|
||||
|
||||
// Add Import and run method from generated folder (Init)
|
||||
// Add Import from generated folder (Custom)
|
||||
// Add Import from generated folder (Help)
|
||||
// Update version in HISTORY.rst
|
||||
// Update version in setup.py
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
|
||||
|
||||
export abstract class AzGeneratorBase {
|
||||
model: CodeModelAz;
|
||||
files: any = {};
|
||||
path: string;
|
||||
isDebugMode: boolean;
|
||||
|
||||
constructor(model: CodeModelAz, isDebugMode: boolean) {
|
||||
this.model = model;
|
||||
this.path = "";
|
||||
this.isDebugMode = isDebugMode;
|
||||
}
|
||||
|
||||
public abstract generateAll(): void;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { AzExtensionFullGenerator } from "./AzExtensionFullGenerator";
|
||||
import { AzGeneratorBase } from "./AzGeneratorBase";
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
|
||||
export class AzGeneratorFactory {
|
||||
static async createAzGenerator(model: CodeModelAz, isDebugMode: boolean): Promise<AzGeneratorBase> {
|
||||
await model.init();
|
||||
model.GenerateTestInit();
|
||||
|
||||
return new AzExtensionFullGenerator(model, isDebugMode);
|
||||
}
|
||||
}
|
|
@ -3,66 +3,64 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CodeModelAz } from "./CodeModelAz"
|
||||
import { GenerateAzureCliActions } from "./TemplateAzureCliActions"
|
||||
import { GenerateAzureCliAzextMetadata } from "./TemplateAzureCliAzextMetadata"
|
||||
import { GenerateAzureCliClientFactory } from "./TemplateAzureCliClientFactory"
|
||||
import { GenerateAzureCliCommands } from "./TemplateAzureCliCommands"
|
||||
import { GenerateAzureCliCustom } from "./TemplateAzureCliCustom"
|
||||
import { GenerateAzureCliHelp } from "./TemplateAzureCliHelp"
|
||||
import { GenerateAzureCliParams} from "./TemplateAzureCliParams"
|
||||
import { GenerateAzureCliClientFactory } from "./TemplateAzureCliClientFactory"
|
||||
import { GenerateAzureCliTestScenario, NeedPreparer } from "./TemplateAzureCliTestScenario"
|
||||
import { GenerateAzureCliTestPrepare } from "./TemplateAzureCliTestPrepare"
|
||||
import { GenerateAzureCliReport } from "./TemplateAzureCliReport"
|
||||
import { GenerateAzureCliInit } from "./TemplateAzureCliInit"
|
||||
import { GenerateAzureCliAzextMetadata } from "./TemplateAzureCliAzextMetadata"
|
||||
import { GenerateAzureCliValidators } from "./TemplateAzureCliValidators"
|
||||
import { GenerateAzureCliHistory } from "./TemplateAzureCliHistory"
|
||||
import { GenerateAzureCliInit } from "./TemplateAzureCliInit"
|
||||
import { GenerateNamespaceInit } from "./TemplateAzureCliNamespaceInit"
|
||||
import { GenerateAzureCliParams } from "./TemplateAzureCliParams"
|
||||
import { GenerateAzureCliReadme } from "./TemplateAzureCliReadme"
|
||||
import { GenerateAzureCliReport } from "./TemplateAzureCliReport"
|
||||
import { GenerateAzureCliSetupCfg } from "./TemplateAzureCliSetupCfg"
|
||||
import { GenerateAzureCliSetupPy } from "./TemplateAzureCliSetupPy"
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
import { GenerateAzureCliActions } from "./TemplateAzureCliActions"
|
||||
import { GenerateTopLevelImport } from "./TemplateAzureCliTopLevelImport"
|
||||
import { GenerateNamespaceInit } from "./TemplateAzureCliNamespaceInit"
|
||||
import { GenerateAzureCliTestInit } from "./TemplateAzureCliTestInit"
|
||||
import { GenerateAzureCliTestPrepare } from "./TemplateAzureCliTestPrepare"
|
||||
import { GenerateAzureCliTestScenario, NeedPreparer } from "./TemplateAzureCliTestScenario"
|
||||
import { GenerateTopLevelImport } from "./TemplateAzureCliTopLevelImport"
|
||||
import { GenerateAzureCliValidators } from "./TemplateAzureCliValidators"
|
||||
|
||||
// [Deprecating] Try to depreacate this method. Move logic to AzGeneratorBase and AzExtensionFullGenerator class
|
||||
export async function GenerateAll(model: CodeModelAz,
|
||||
generateReport: any, debug: boolean) {
|
||||
let files: any = {};
|
||||
|
||||
await model.init();
|
||||
|
||||
if (model.SelectFirstExtension())
|
||||
{
|
||||
do
|
||||
{
|
||||
if (model.SelectFirstExtension()) {
|
||||
do {
|
||||
let pathTop = "";
|
||||
let path = "azext_" + model.Extension_NameUnderscored + "/";
|
||||
|
||||
|
||||
files[path + "generated/_params.py"] = GenerateAzureCliParams(model, debug);
|
||||
files[path + "generated/commands.py"] = GenerateAzureCliCommands(model);
|
||||
files[path + "generated/custom.py"] = GenerateAzureCliCustom(model);
|
||||
files[path + "generated/_client_factory.py"] = GenerateAzureCliClientFactory(model);
|
||||
files[path + "generated/_validators.py"] = GenerateAzureCliValidators(model);
|
||||
files[path + "generated/action.py"] = GenerateAzureCliActions(model);
|
||||
files[path + "generated/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "generated/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "tests/__init__.py"] = GenerateAzureCliTestInit(model);
|
||||
model.GenerateTestInit();
|
||||
files[path + "tests/latest/test_" + model.Extension_NameUnderscored + "_scenario.py"] = GenerateAzureCliTestScenario(model);
|
||||
if (NeedPreparer()) files[path + "tests/latest/preparers.py"] = GenerateAzureCliTestPrepare(model);
|
||||
files[path + "generated/_help.py"] = GenerateAzureCliHelp(model, debug);
|
||||
files[path + "tests/latest/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "tests/latest/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "azext_metadata.json"] = GenerateAzureCliAzextMetadata(model);
|
||||
files[path + "vendored_sdks/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "manual/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "action.py"] = GenerateTopLevelImport(model, "action");
|
||||
files[path + "custom.py"] = GenerateTopLevelImport(model, "custom");
|
||||
files[path + "vendored_sdks/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "manual/__init__.py"] = GenerateNamespaceInit(model);
|
||||
files[path + "action.py"] = GenerateTopLevelImport(model, "action");
|
||||
files[path + "custom.py"] = GenerateTopLevelImport(model, "custom");
|
||||
files[path + "__init__.py"] = GenerateAzureCliInit(model);
|
||||
files[pathTop + "HISTORY.rst"] = GenerateAzureCliHistory(model);
|
||||
files[pathTop + "README.md"] = GenerateAzureCliReadme(model);
|
||||
files[pathTop + "setup.cfg"] = GenerateAzureCliSetupCfg(model);
|
||||
files[pathTop + "setup.py"] = GenerateAzureCliSetupPy(model);
|
||||
files[pathTop + "setup.py"] = GenerateAzureCliSetupPy(model);
|
||||
|
||||
if (generateReport)
|
||||
{
|
||||
if (generateReport) {
|
||||
files[pathTop + "report.md"] = GenerateAzureCliReport(model);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,12 @@ import { Channel, Host, startSession } from '@azure-tools/autorest-extension-bas
|
|||
import { CodeModel, codeModelSchema } from '@azure-tools/codemodel';
|
||||
import { EOL } from "os";
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { GenerationMode } from '../models';
|
||||
import { GenerationMode } from "../models";
|
||||
import { AzGeneratorFactory } from "./AzGeneratorFactory";
|
||||
import { CodeModelCliImpl } from "./CodeModelAzImpl";
|
||||
import { GenerateAll } from "./Generator";
|
||||
|
||||
|
||||
export async function processRequest(host: Host) {
|
||||
const debug = await host.GetValue('debug') || false;
|
||||
//host.Message({Channel:Channel.Warning, Text:"in azgenerator processRequest"});
|
||||
try {
|
||||
const session = await startSession<CodeModel>(host, {}, codeModelSchema);
|
||||
let model = new CodeModelCliImpl(session);
|
||||
|
@ -44,7 +42,10 @@ export async function processRequest(host: Host) {
|
|||
}
|
||||
host.Message({ Channel: Channel.Information, Text: "generation-mode in code model is: " + GenerationMode[session.model.language['az']['generation-mode']] });
|
||||
|
||||
let files: any = await GenerateAll(model, true, debug);
|
||||
let generator = await AzGeneratorFactory.createAzGenerator(model, debug);
|
||||
generator.generateAll();
|
||||
let files = generator.files;
|
||||
|
||||
if (model.SelectFirstExtension()) {
|
||||
do {
|
||||
let path = "azext_" + model.Extension_Name.replace("-", "_") + "/";
|
||||
|
|
Загрузка…
Ссылка в новой задаче