Exemplo n.º 1
0
        public bool Run(
            string projectAssembly,
            string sourceDirectory,
            IList <string> sourceFiles,
            IList <string> generationList,
            IWriter writer,
            TextFormatter textFormatter,
            IDictionary <string, string> typeOverrideMap
            )
        {
            var overallStopwatch = Stopwatch.StartNew();
            var stopwatch        = Stopwatch.StartNew();

            GlobalLogger.Info($"=== Consolidate Source Files");
            var sourceFilesAsText = GetSourceFilesAsSingleTextString(
                sourceDirectory,
                sourceFiles
                );

            GlobalLogger.Info($"=== Consolidated Source Files | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generated AST");
            var ast = new TypeScriptAST(
                sourceFilesAsText,
                "source-combined.ts"
                );

            GlobalLogger.Info($"=== Generated AST | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");
            var notGeneratedClassNames = new List <string>();

            var generatedStatements = new List <GeneratedStatement>();

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Cached Entity Object");
            var cachedEntityObject = GenerateCachedEntityObject.GenerateClassStatement();

            generatedStatements.Add(
                new GeneratedStatement(
                    cachedEntityObject,
                    GenerateCachedEntityObject.GenerateString()
                    )
                );
            GlobalLogger.Info($"=== Generated Cached Entity Object | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Class Statements");
            var generatedClassStatements = GenerateClassFromList(
                ast,
                projectAssembly,
                generationList,
                notGeneratedClassNames,
                typeOverrideMap,
                new List <ClassStatement> {
                cachedEntityObject
            }
                );

            generatedClassStatements.Remove(cachedEntityObject);
            GlobalLogger.Info($"=== Generated Class Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Statements");
            foreach (var generatedStatement in generatedClassStatements)
            {
                generatedStatements.Add(
                    new GeneratedStatement(
                        generatedStatement,
                        GenerateClassStatementString.Generate(
                            generatedStatement,
                            textFormatter
                            )
                        )
                    );
            }
            GlobalLogger.Info($"=== Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generating Shimmed Classes");
            foreach (var notGeneratedInterfaceName in notGeneratedClassNames)
            {
                if (!JavaScriptProvidedApiIdentifier.Identify(notGeneratedInterfaceName, out _))
                {
                    var classShim = GenerateClassShim.GenerateClassStatement(
                        notGeneratedInterfaceName
                        );
                    generatedStatements.Add(
                        new GeneratedStatement(
                            classShim,
                            textFormatter.Format(
                                GenerateClassShim.GenerateString(
                                    classShim
                                    )
                                )
                            )
                        );
                    GlobalLogger.Info($"=== Generated Shimmed Class: {notGeneratedInterfaceName}");
                }
            }
            GlobalLogger.Info($"=== Generated Shimmed Classes | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            // Write Generated Statements to Passed in Writer
            stopwatch.Restart();
            GlobalLogger.Info($"=== Writing Generated Statements");
            writer.Write(
                generatedStatements
                );
            GlobalLogger.Info($"=== Finished Writing Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            GlobalLogger.Success($"=== Finished Run | ElapsedTime: {overallStopwatch.ElapsedMilliseconds}ms");

            return(true);
        }
Exemplo n.º 2
0
        private static int GenerateSources(
            IList <string> source,
            IList <string> classToGenerate,
            string projectAssembly           = "Generated.WASM",
            string projectGenerationLocation = "_generated",
            bool force = false
            )
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();
                ValidateArguments(
                    source,
                    classToGenerate,
                    projectAssembly,
                    projectGenerationLocation
                    );
                GlobalLogger.Info($"projectAssembly: {projectAssembly}");
                GlobalLogger.Info($"projectGenerationLocation: {projectGenerationLocation}");

                GlobalLogger.Info($"classToGenerate.Length: {classToGenerate.Count}");
                foreach (var classToGenerateItem in classToGenerate)
                {
                    GlobalLogger.Info($"classToGenerateItem: {classToGenerateItem}");
                }

                GlobalLogger.Info($"sourceFile.Length: {source.Count}");
                foreach (var sourceFileItem in source)
                {
                    GlobalLogger.Info($"sourceFile: {sourceFileItem}");
                }

                projectGenerationLocation = Path.Combine(
                    ".",
                    projectGenerationLocation
                    );

                var sourceDirectory = Path.Combine(
                    ".",
                    SOURCE_FILES_DIRECTORY_NAME
                    );
                var sourceFiles = CopyAndDownloadSourceFiles(
                    source
                    );
                var generationList = classToGenerate;

                // Check for already Generated Source.
                var projectAssemblyDirectory = Path.Combine(
                    projectGenerationLocation,
                    projectAssembly
                    );
                if (Directory.Exists(
                        projectAssemblyDirectory
                        ))
                {
                    if (!force)
                    {
                        GlobalLogger.Error(
                            $"Project Assembly Directory was not empty: {projectAssemblyDirectory}"
                            );
                        GlobalLogger.Error(
                            $"Use --force to replace directory."
                            );
                        return(502);
                    }

                    GlobalLogger.Warning(
                        $"Deleting existing projectAssemblyDirectory: {projectAssemblyDirectory}"
                        );
                    Directory.Delete(
                        projectAssemblyDirectory,
                        true
                        );
                }

                var textFormatter = new NoFormattingTextFormatter();
                var writer        = new ProjectWriter(
                    projectGenerationLocation,
                    projectAssembly
                    );

                new GenerateInteropSource().Run(
                    projectAssembly,
                    sourceDirectory,
                    sourceFiles,
                    generationList,
                    writer,
                    textFormatter,
                    new Dictionary <string, string>
                {
                    { "BABYLON.PointerInfoBase | type", "int" }
                }
                    );
                stopwatch.Stop();
                GlobalLogger.Success($"Took {stopwatch.ElapsedMilliseconds}ms to Generate Source Project.");

                return(0);
            }
            catch (ArgumentException ex)
            {
                GlobalLogger.Error(
                    $"Argument failure: {ex.ParamName} -> {ex.Message}"
                    );
                return(404);
            }
            catch (InvalidSourceFileException ex)
            {
                GlobalLogger.Error(
                    $"Invalid Source File Exception: {ex.Message}"
                    );
                return(501);
            }
        }