modelerfour pipeline
This commit is contained in:
Родитель
93af7a4eac
Коммит
8519755cdb
34
README.md
34
README.md
|
@ -1,14 +1,28 @@
|
|||
# configuration
|
||||
|
||||
# Contributing
|
||||
See documentation [here](doc/00-overview.md)
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
|
||||
``` yaml
|
||||
use-extension:
|
||||
"@autorest/modelerfour": "~4.1.60"
|
||||
"cli.common": "$(this-folder)"
|
||||
|
||||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
||||
pipeline-model: v3
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
pipeline:
|
||||
modelerfour:
|
||||
input: openapi-document/multi-api/identity
|
||||
common/generate:
|
||||
plugin: cli.common
|
||||
input: modelerfour
|
||||
output-artifact: source-file-common
|
||||
|
||||
common/emitter:
|
||||
input: generate
|
||||
scope: scope-here
|
||||
|
||||
scope-here:
|
||||
is-object: false
|
||||
output-artifact:
|
||||
- source-file-common
|
||||
```
|
||||
|
|
95
src/index.ts
95
src/index.ts
|
@ -1,5 +1,4 @@
|
|||
import { AutoRestExtension, Channel } from '@azure-tools/autorest-extension-base';
|
||||
import * as yaml from "node-yaml";
|
||||
|
||||
|
||||
export type LogCallback = (message: string) => void;
|
||||
|
@ -7,34 +6,8 @@ export type FileCallback = (path: string, rows: string[]) => void;
|
|||
|
||||
const extension = new AutoRestExtension();
|
||||
|
||||
export enum ArtifactType
|
||||
{
|
||||
ArtifactTypeAzureAzModule,
|
||||
ArtifactTypeAzureAzExtension,
|
||||
}
|
||||
|
||||
extension.Add("cli.common", async autoRestApi => {
|
||||
|
||||
let log = await autoRestApi.GetValue("log");
|
||||
|
||||
function Info(s: string)
|
||||
{
|
||||
if (log)
|
||||
{
|
||||
autoRestApi.Message({
|
||||
Channel: Channel.Information,
|
||||
Text: s
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function Error(s: string)
|
||||
{
|
||||
autoRestApi.Message({
|
||||
Channel: Channel.Error,
|
||||
Text: s
|
||||
});
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -43,54 +16,32 @@ extension.Add("cli.common", async autoRestApi => {
|
|||
|
||||
const inputFiles: string[] = await Promise.all(inputFileUris.map(uri => autoRestApi.ReadFile(uri)));
|
||||
|
||||
let artifactType: ArtifactType;
|
||||
let writeIntermediate: boolean = false;
|
||||
// read a setting
|
||||
|
||||
// namespace is the only obligatory option
|
||||
// we will derive default "package-name" and "root-name" from it
|
||||
const namespace = await autoRestApi.GetValue("namespace");
|
||||
|
||||
if (!namespace)
|
||||
{
|
||||
Error("\"namespace\" is not defined, please add readme.az.md file to the specification.");
|
||||
return;
|
||||
}
|
||||
|
||||
// package name and group name can be guessed from namespace
|
||||
let packageName = await autoRestApi.GetValue("package-name") || namespace.replace(/\./g, '-');
|
||||
let cliCommonName = await autoRestApi.GetValue("group-name") || await autoRestApi.GetValue("cli-common-name") || packageName.split('-').pop();
|
||||
|
||||
|
||||
let tag = await autoRestApi.GetValue("tag");
|
||||
Info(tag);
|
||||
|
||||
// Handle generation type parameter
|
||||
if (await autoRestApi.GetValue("cli-common"))
|
||||
{
|
||||
Info("GENERATION: --cli-common");
|
||||
artifactType = (await autoRestApi.GetValue("extension")) ? ArtifactType.ArtifactTypeAzureAzExtension : ArtifactType.ArtifactTypeAzureAzModule;
|
||||
}
|
||||
|
||||
for (let iff of inputFiles)
|
||||
{
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// PARSE INPUT MODEL
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
let swagger = JSON.parse(iff);
|
||||
const isDebugFlagSet = await autoRestApi.GetValue("debug");
|
||||
let cliCommonSettings = await autoRestApi.GetValue("cli.common");
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// WRITE INTERMEDIATE FILE IF --intermediate OPTION WAS SPECIFIED
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
if (writeIntermediate)
|
||||
{
|
||||
autoRestApi.WriteFile("intermediate/" + cliCommonName + "-input.yml", yaml.dump(swagger));
|
||||
}
|
||||
}
|
||||
// emit messages
|
||||
|
||||
autoRestApi.Message({
|
||||
Channel: Channel.Warning,
|
||||
Text: "Hello World! The `debug` flag is " + (isDebugFlagSet ? "set" : "not set"),
|
||||
});
|
||||
|
||||
autoRestApi.Message({
|
||||
Channel: Channel.Warning,
|
||||
Text: "cli.common settings " + JSON.stringify(cliCommonSettings)
|
||||
});
|
||||
|
||||
autoRestApi.Message({
|
||||
Channel: Channel.Information,
|
||||
Text: "AutoRest offers the following input files: " + inputFileUris.join(", "),
|
||||
});
|
||||
|
||||
// emit a file (all input files concatenated)
|
||||
|
||||
autoRestApi.WriteFile("myfolder/concat.txt", inputFiles.join("\n---\n"));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче