Browse Source

Generate proxy command bug fix

pull/3138/head
Arkat Erol 7 years ago
parent
commit
88df0a3e37
  1. 94
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs

94
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs

@ -53,43 +53,41 @@ namespace Volo.Abp.Cli.Commands
Logger.LogInformation("Modules are combining"); Logger.LogInformation("Modules are combining");
var moduleList = GetCombinedModules(data); var moduleList = GetCombinedModules(data);
Logger.LogInformation("Modules and types are creating"); Logger.LogInformation("Modules and types are creating");
var serviceIndexList = new List<string>();
var modelIndexList = new List<string>();
foreach (var module in moduleList) foreach (var module in moduleList)
{ {
var moduleValue = JObject.Parse(module.Value); var moduleValue = JObject.Parse(module.Value);
var rootPath = module.Key; var rootPath = module.Key;
var controllerName = "";
var controllerServiceName = "";
Logger.LogInformation($"{rootPath} directory is creating"); Logger.LogInformation($"{rootPath} directory is creating");
Directory.CreateDirectory($"src/app/{rootPath}/shared/models"); Directory.CreateDirectory($"src/app/{rootPath}/shared/models");
Directory.CreateDirectory($"src/app/{rootPath}/shared/services"); Directory.CreateDirectory($"src/app/{rootPath}/shared/services");
var serviceFileText = new StringBuilder(); var serviceIndexList = new List<string>();
var modelIndexList = new List<string>();
serviceFileText.AppendLine("[firstTypeList]");
serviceFileText.AppendLine("import { Injectable } from '@angular/core';");
serviceFileText.AppendLine("import { Observable } from 'rxjs';");
serviceFileText.AppendLine("[secondTypeList]");
serviceFileText.AppendLine("");
serviceFileText.AppendLine("@Injectable()");
serviceFileText.AppendLine("export class [controllerName]Service {");
serviceFileText.AppendLine(" constructor(private restService: RestService) {}");
serviceFileText.AppendLine("");
var firstTypeList = new List<string>();
var secondTypeList = new List<string>();
foreach (var controller in moduleValue.Root.ToList().Select(item => item.First)) foreach (var controller in moduleValue.Root.ToList().Select(item => item.First))
{ {
controllerName = (string)controller["controllerName"]; var serviceFileText = new StringBuilder();
controllerServiceName = controllerName.PascalToKebabCase() + ".service.ts";
serviceFileText.AppendLine("[firstTypeList]");
serviceFileText.AppendLine("import { Injectable } from '@angular/core';");
serviceFileText.AppendLine("import { Observable } from 'rxjs';");
serviceFileText.AppendLine("[secondTypeList]");
serviceFileText.AppendLine("");
serviceFileText.AppendLine("@Injectable()");
serviceFileText.AppendLine("export class [controllerName]Service {");
serviceFileText.AppendLine(" constructor(private restService: RestService) {}");
serviceFileText.AppendLine("");
var firstTypeList = new List<string>();
var secondTypeList = new List<string>();
var controllerName = (string)controller["controllerName"];
var controllerServiceName = controllerName.PascalToKebabCase() + ".service.ts";
foreach (var actionItem in controller["actions"]) foreach (var actionItem in controller["actions"])
{ {
@ -221,38 +219,38 @@ namespace Volo.Abp.Cli.Commands
} }
serviceIndexList.Add(controllerServiceName.Replace(".ts", "")); serviceIndexList.Add(controllerServiceName.Replace(".ts", ""));
}
if (firstTypeList != null && firstTypeList.Count > 0) if (firstTypeList != null && firstTypeList.Count > 0)
{ {
var firstTypeListDistinct = ", " + Join(", ", firstTypeList.Where(p => p != "void").Distinct().ToArray()); var firstTypeListDistinct = ", " + Join(", ", firstTypeList.Where(p => p != "void").Distinct().ToArray());
serviceFileText.Replace("[firstTypeList]", serviceFileText.Replace("[firstTypeList]",
$"import {{ RestService {firstTypeListDistinct}}} from '@abp/ng.core';"); $"import {{ RestService {firstTypeListDistinct}}} from '@abp/ng.core';");
} }
else else
{ {
serviceFileText.Replace("[firstTypeList]", ""); serviceFileText.Replace("[firstTypeList]", "");
} }
if (secondTypeList != null && secondTypeList.Count > 0) if (secondTypeList != null && secondTypeList.Count > 0)
{ {
var secondTypeListDistinct = Join(", ", secondTypeList.Where(p => p != "void").Distinct().ToArray()); var secondTypeListDistinct = Join(", ", secondTypeList.Where(p => p != "void").Distinct().ToArray());
serviceFileText.Replace("[secondTypeList]", serviceFileText.Replace("[secondTypeList]",
$"import {{{secondTypeListDistinct}}} from '../models';"); $"import {{{secondTypeListDistinct}}} from '../models';");
} }
else else
{ {
serviceFileText.Replace("[secondTypeList]", ""); serviceFileText.Replace("[secondTypeList]", "");
} }
serviceFileText.AppendLine("}"); serviceFileText.AppendLine("}");
serviceFileText.Replace("[controllerName]", controllerName); serviceFileText.Replace("[controllerName]", controllerName);
File.WriteAllText($"src/app/{rootPath}/shared/services/{controllerServiceName}", serviceFileText.ToString()); File.WriteAllText($"src/app/{rootPath}/shared/services/{controllerServiceName}", serviceFileText.ToString());
}
var serviceIndexFileText = new StringBuilder(); var serviceIndexFileText = new StringBuilder();
foreach (var serviceIndexItem in serviceIndexList) foreach (var serviceIndexItem in serviceIndexList.Distinct())
{ {
serviceIndexFileText.AppendLine($"export * from './{serviceIndexItem}';"); serviceIndexFileText.AppendLine($"export * from './{serviceIndexItem}';");
} }
@ -261,7 +259,7 @@ namespace Volo.Abp.Cli.Commands
var modelIndexFileText = new StringBuilder(); var modelIndexFileText = new StringBuilder();
foreach (var modelIndexItem in modelIndexList) foreach (var modelIndexItem in modelIndexList.Distinct())
{ {
modelIndexFileText.AppendLine($"export * from './{modelIndexItem}';"); modelIndexFileText.AppendLine($"export * from './{modelIndexItem}';");
} }

Loading…
Cancel
Save