This commit is contained in:
Zim Kalinowski 2020-01-21 09:42:30 +08:00
Родитель dc63ad5410
Коммит 5788cb025e
2 изменённых файлов: 66 добавлений и 19 удалений

Просмотреть файл

@ -24,18 +24,50 @@ extension.Add("clicommon", async autoRestApi => {
const namer = await new Namer(session).init();
let result = namer.process();
session.model = result;
autoRestApi.Message({
Channel: Channel.Warning,
Text: "XXX --- namer finished"
});
const modifiers = await new Modifiers(session);
modifiers.process();
const modifiers = new Modifiers(session);
autoRestApi.Message({
Channel: Channel.Warning,
Text: "XXX --- created modifiers"
});
modifiers.codeModel = result;
modifiers.directives = cliCommonSettings['directives'];
autoRestApi.Message({
Channel: Channel.Warning,
Text: "XXX --- processing modifiers"
});
//result = modifiers.process();
autoRestApi.Message({
Channel: Channel.Warning,
Text: "XXX --- modifiers-processed"
});
// add test scenario from common settings
if (cliCommonSettings) {
result["test-scenario"] = cliCommonSettings['test-scenario'];
}
autoRestApi.Message({
Channel: Channel.Warning,
Text: "XXX --- writing file"
});
// emit a file (all input files concatenated)
autoRestApi.WriteFile("code-model-v4-cli.yaml", serialize(result));
autoRestApi.Message({
Channel: Channel.Warning,
Text: "XXX --- file written"
});
}
catch (e)
{

Просмотреть файл

@ -108,43 +108,58 @@ function hasSpecialChars(str: string): boolean {
export class Modifiers {
codeModel: CodeModel;
directives: any;
constructor(protected session: Session<CodeModel>) {
this.codeModel = session.model;
}
async process() {
let azSettings = await this.session.getValue('az');
directives = azSettings['directive'];
process() {
this.session.message({Channel:Channel.Warning, Text: "PROCESSING MODIFIERS" });
let cliSettings = null; //await this.session.getValue('cli');
this.session.message({Channel:Channel.Warning, Text: "GOT CLI SETTINGS" });
this.session.message({Channel:Channel.Warning, Text: "CLI SETTINGS: " + JSON.stringify(cliSettings) });
//directives = cliSettings['directive'];
if (directives != null) {
for (const directive of directives.filter(each => !each.transform)) {
if (this.directives != null) {
for (const directive of this.directives.filter(each => !each.transform)) {
const getPatternToMatch = (selector: string | undefined): RegExp | undefined => {
return selector? !hasSpecialChars(selector)? new RegExp(`^${selector}$`, "gi"): new RegExp(selector, "gi"): undefined;
};
if (isWhereCommandDirective(directive)) {
const selectType = directive.select;
const groupRegex = getPatternToMatch(directive.where["group"]);
const operationRegex = getPatternToMatch(directive.where["operation"]);
const parameterRegex = getPatternToMatch(directive.where["parameter-name"]);
const commandRegex = getPatternToMatch(directive.where["command"]);
const modelRegex = getPatternToMatch(directive.where["model"]);
const propertyRegex = getPatternToMatch(directive.where["property"]);
const parameterReplacer = directive.set !== undefined? directive.set["parameter-name"]: undefined;
const paramDescriptionReplacer = directive.set !== undefined? directive.set["parameter-description"]: undefined;
const commandReplacer = directive.set !== undefined ? directive.set["command"] : undefined;
const commandDescriptionReplacer = directive.set !== undefined? directive.set["command-description"]: undefined;
this.session.message({Channel:Channel.Warning, Text:serialize(commandRegex) + " " + serialize(commandReplacer)});
const groupReplacer = directive.set !== undefined ? directive.set["name"] : undefined;
const groupDescriptionReplacer = directive.set !== undefined? directive.set["description"]: undefined;
const operationReplacer = directive.set !== undefined ? directive.set["name"] : undefined;
const operationDescriptionReplacer = directive.set !== undefined? directive.set["description"]: undefined;
this.session.message({Channel:Channel.Warning, Text:serialize(groupRegex) + " " + serialize(groupReplacer)});
for (const operationGroup of values(this.codeModel.operationGroups)) {
//operationGroup
//operation
if (operationGroup.language['cli']['name'] != undefined && operationGroup.language["cli"]["name"].match(groupRegex)) {
operationGroup.language["cli"]["name"] = groupReplacer? groupRegex? operationGroup.language["cli"]["name"].replace(groupRegex, groupReplacer): groupReplacer : operationGroup["cli"]["name"];
operationGroup.language["cli"]["description"] = groupDescriptionReplacer? groupDescriptionReplacer: operationGroup.language["cli"]["description"];
}
for (const operation of values(operationGroup.operations)) {
//operation
if (operation.language['az']['command'] != undefined && operation.language["az"]["command"].match(commandRegex)) {
operation.language["az"]["command"] = commandReplacer? commandRegex? operation.language["az"]["command"].replace(commandRegex, commandReplacer): commandReplacer: operation.language["az"]["command"];
operation.language["az"]["description"] = commandDescriptionReplacer? commandDescriptionReplacer: operation.language["az"]["description"];
if (operation.language['cli']['name'] != undefined && operation.language["cli"]["name"].match(operationRegex)) {
operation.language["cli"]["name"] = operationReplacer? operationRegex? operation.language["cli"]["name"].replace(operationRegex, operationReplacer): operationReplacer: operation.language["cli"]["name"];
operation.language["cli"]["description"] = operationDescriptionReplacer? operationDescriptionReplacer: operation.language["cli"]["description"];
}
for (const parameter of values(operation.request.parameters)) {
if (parameter.language['az']['name'] != undefined && parameter.language["az"]["name"].match(parameterRegex)) {
parameter.language["az"]["name"] = parameterReplacer? parameterRegex? parameter.language["az"]["name"].replace(parameterRegex, parameterReplacer): parameterReplacer: parameter.language["az"]["name"];
parameter.language["az"]["description"] = paramDescriptionReplacer? paramDescriptionReplacer: parameter.language["az"]["description"];
if (parameter.language['cli']['name'] != undefined && parameter.language["cli"]["name"].match(parameterRegex)) {
parameter.language["cli"]["name"] = parameterReplacer? parameterRegex? parameter.language["az"]["name"].replace(parameterRegex, parameterReplacer): parameterReplacer: parameter.language["az"]["name"];
parameter.language["cli"]["description"] = paramDescriptionReplacer? paramDescriptionReplacer: parameter.language["az"]["description"];
}
}
}