public override async Task GenerateProxyAsync(GenerateProxyArgs args) { CheckWorkDirectory(args.WorkDirectory); var output = Path.Combine(args.WorkDirectory, DefaultOutput, $"{args.Module}-proxy.js"); if (!args.Output.IsNullOrWhiteSpace()) { output = args.Output.EndsWith(".js") ? Path.Combine(args.WorkDirectory, args.Output) : Path.Combine(args.WorkDirectory, Path.GetDirectoryName(args.Output), $"{args.Module}-proxy.js"); } if (args.CommandName == RemoveProxyCommand.Name) { RemoveProxy(args, output); return; } var applicationApiDescriptionModel = await GetApplicationApiDescriptionModelAsync(args); var script = RemoveInitializedEventTrigger(_jQueryProxyScriptGenerator.CreateScript(applicationApiDescriptionModel)); Directory.CreateDirectory(Path.GetDirectoryName(output)); using (var writer = new StreamWriter(output)) { await writer.WriteAsync(script); } Logger.LogInformation($"Create {GetLoggerOutputPath(output, args.WorkDirectory)}"); }
private void RemoveProxy(GenerateProxyArgs args, string filePath) { if (File.Exists(filePath)) { File.Delete(filePath); } Logger.LogInformation($"Delete {GetLoggerOutputPath(filePath, args.WorkDirectory)}"); }
public override async Task GenerateProxyAsync(GenerateProxyArgs args) { CheckAngularJsonFile(); await CheckNgSchematicsAsync(); var schematicsCommandName = args.CommandName == RemoveProxyCommand.Name ? "proxy-remove" : "proxy-add"; var prompt = args.ExtraProperties.ContainsKey("p") || args.ExtraProperties.ContainsKey("prompt"); var defaultValue = prompt ? null : "__default"; var module = defaultValue; if (args.ExtraProperties.ContainsKey("t") || args.ExtraProperties.ContainsKey("module")) { module = args.Module; } var apiName = args.ApiName ?? defaultValue; var source = args.Source ?? defaultValue; var target = args.Target ?? defaultValue; var url = args.Url ?? defaultValue; var commandBuilder = new StringBuilder("npx ng g @abp/ng.schematics:" + schematicsCommandName); if (module != null) { commandBuilder.Append($" --module {module}"); } if (apiName != null) { commandBuilder.Append($" --api-name {apiName}"); } if (source != null) { commandBuilder.Append($" --source {source}"); } if (target != null) { commandBuilder.Append($" --target {target}"); } if (url != null) { commandBuilder.Append($" --url {url}"); } _cmdhelper.RunCmd(commandBuilder.ToString()); }
protected virtual async Task <ApplicationApiDescriptionModel> GetApplicationApiDescriptionModelAsync(GenerateProxyArgs args) { Check.NotNull(args.Url, nameof(args.Url)); var client = CliHttpClientFactory.CreateClient(); var apiDefinitionResult = await client.GetStringAsync(CliUrls.GetApiDefinitionUrl(args.Url)); var apiDefinition = JsonSerializer.Deserialize <ApplicationApiDescriptionModel>(apiDefinitionResult); var moduleDefinition = apiDefinition.Modules.FirstOrDefault(x => string.Equals(x.Key, args.Module, StringComparison.CurrentCultureIgnoreCase)).Value; if (moduleDefinition == null) { throw new CliUsageException($"Module name: {args.Module} is invalid"); } var apiDescriptionModel = ApplicationApiDescriptionModel.Create(); apiDescriptionModel.AddModule(moduleDefinition); return(apiDescriptionModel); }
public abstract Task GenerateProxyAsync(GenerateProxyArgs args);