private static async Task ExecuteCodeGenerator()

in src/JetBrains.Space.Generator/Program.cs [146:195]


    private static async Task<int> ExecuteCodeGenerator(Func<Task<ApiModel?>> retrieveModel, Func<Task<DeploymentInfo?>> retrieveDeploymentInfo)
    {
        var stopwatch = new Stopwatch();
        stopwatch.Start();

        // Get data
        var apiModel = await retrieveModel();
        if (apiModel == null)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("ERROR: HTTP API model information is not available.");
            return -1;
        }
            
        var deploymentInfo = await retrieveDeploymentInfo();
        if (deploymentInfo == null || string.IsNullOrEmpty(deploymentInfo.Version))
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("ERROR: Deployment and version information is not available.");
            return -1;
        }
            
        // Remove old code
        var generatedCodePath = Path.GetFullPath(OutputPath);
        if (Directory.Exists(generatedCodePath))
        {
            Directory.Delete(generatedCodePath, recursive: true);
        }

        // Build code
        var codeGenerationContext = CodeGenerationContext.CreateFrom(apiModel, deploymentInfo);
        var csharpApiModelGenerator = new CSharpApiModelGenerator(codeGenerationContext);
        csharpApiModelGenerator.GenerateFiles(
            new CSharpDocumentWriter(
                new DirectoryInfo(Path.GetFullPath(OutputPath))),
            new CSharpDocumentWriter(
                new DirectoryInfo(Path.GetFullPath(SdkInfoOutputPath))));
            
        // Report
        stopwatch.Stop();
        Console.WriteLine($"Code generation completed in: {stopwatch.Elapsed}");
        Console.WriteLine($"  Number of DTO: {codeGenerationContext.GetDtos().Count()}");
        Console.WriteLine($"  Number of Enums: {codeGenerationContext.GetEnums().Count()}");
        Console.WriteLine($"  Number of Resources (top level): {codeGenerationContext.GetResources().Count()}");
            
        // Write version marker
        await File.WriteAllTextAsync("../../../../../version-info.txt", deploymentInfo.Version.Trim());
            
        return 0;
    }