예제 #1
0
        private void GenerateClient(ProtoFile ast, CybtansConfig config, GenerationStep step, StepClientOptions option)
        {
            var output = Path.Combine(config.Path, option.Output);

            switch (option.Framework)
            {
            case "ts":
            case "react":
            case "typescript":
            {
                TypescriptGenerator tsGenerator = new TypescriptGenerator(new TypescriptOptions
                    {
                        ModelOptions = new TsOutputOption {
                            OutputPath = output
                        },
                        ClientOptions = new TsOutputOption
                        {
                            OutputPath = output,
                            Framework  = ""
                        }
                    });

                tsGenerator.GenerateCode(ast);
            }
            break;

            case "ng":
            case "angular":
            {
                TypescriptGenerator tsGenerator = new TypescriptGenerator(new TypescriptOptions
                    {
                        ModelOptions = new TsOutputOption {
                            OutputPath = output
                        },
                        ClientOptions = new TsOutputOption
                        {
                            OutputPath = output,
                            Framework  = TsOutputOption.FRAMEWORK_ANGULAR
                        }
                    });

                tsGenerator.GenerateCode(ast);
            }
            break;
            }
        }
예제 #2
0
        public bool Generate(CybtansConfig config, GenerationStep step)
        {
            if (!CanGenerate(step.Type))
            {
                return(false);
            }

            var options = new GenerationOptions()
            {
                ProtoOutputFilename = Path.Combine(config.Path, step.ProtoFile),
                AssemblyFilename    = Path.Combine(config.Path, step.AssemblyFile),
                Imports             = step.Imports,
                ServiceName         = config.Service,
                ServiceDirectory    = Path.Combine(config.Path, step.Output),
            };

            GenerateProto(options);

            return(true);
        }
예제 #3
0
 public bool Generate(CybtansConfig config, GenerationStep step)
 {
     return(false);
 }
예제 #4
0
        public bool Generate(CybtansConfig config, GenerationStep step)
        {
            if (!CanGenerate(step.Type))
            {
                return(false);
            }

            var options = new GenerationOptions()
            {
                ModelOptions = new TypeGeneratorOption()
                {
                    OutputPath = Path.Combine(config.Path, step.Models?.Output ?? $"{step.Output}/{config.Service}.Models"),
                    Namespace  = step.Models?.Namespace
                },
                ServiceOptions = new TypeGeneratorOption()
                {
                    OutputPath = Path.Combine(config.Path, step.Services?.Output ?? $"{step.Output}/{config.Service}.Services/Generated"),
                    Namespace  = step.Services?.Namespace
                },
                ControllerOptions = new WebApiControllerGeneratorOption()
                {
                    OutputPath = Path.Combine(config.Path, step.Controllers?.Output ?? $"{step.Output}/{config.Service}.RestApi/Controllers/Generated"),
                    Namespace  = step.Controllers?.Namespace
                },
                ClientOptions = new TypeGeneratorOption()
                {
                    OutputPath = Path.Combine(config.Path, step.CSharpClients?.Output ?? $"{step.Output}/{config.Service}.Clients"),
                    Namespace  = step.CSharpClients?.Namespace
                }
            };

            if (!string.IsNullOrEmpty(step.Gateway) || step.GatewayOptions != null)
            {
                options.ApiGatewayOptions = new ApiGateWayGeneratorOption
                {
                    OutputPath = Path.Combine(config.Path, step.GatewayOptions?.Output ?? step.Gateway),
                    Namespace  = step.GatewayOptions?.Namespace ?? $"{config.Service}.Controllers"
                };
            }

            var protoFile = Path.Combine(config.Path, step.ProtoFile);

            if (step.SearchPath == null)
            {
                step.SearchPath = Path.GetDirectoryName(protoFile);
            }

            if (string.IsNullOrEmpty(step.SearchPath))
            {
                step.SearchPath = Environment.CurrentDirectory;
            }

            var fileResolverFactory = new SearchPathFileResolverFactory(new string[] { step.SearchPath });

            Console.WriteLine($"Compiling {protoFile}");

            Proto3Generator generator = new Proto3Generator(fileResolverFactory);

            var(ast, scope) = generator.LoadFromFile(protoFile);

            MicroserviceGenerator microserviceGenerator = new MicroserviceGenerator(options);

            microserviceGenerator.GenerateCode(ast, scope);
            try
            {
                Console.ForegroundColor = ConsoleColor.Green;

                Console.WriteLine("CSharp generated succesfully");

                if (step.Typecript != null)
                {
                    GenerateTypecriptCode(ast, Path.Combine(config.Path, step.Typecript.Output), step.Typecript.Framework);

                    Console.WriteLine($"Typescript generated succesfully");
                }

                if (step.Clients != null)
                {
                    foreach (var option in step.Clients)
                    {
                        GenerateClient(ast, config, step, option);
                        Console.WriteLine($"{option.Framework} client generated succesfully");
                    }
                }
            }

            finally
            {
                Console.ResetColor();
            }

            return(true);
        }