コード例 #1
0
ファイル: Program.cs プロジェクト: vhil/Leprechaun
        static void Main(string[] args)
        {
            // PARSE ARGS
            var argsParser = new CommandLineParser.CommandLineParser();
            var parsedArgs = new ConsoleArgs();

            argsParser.ExtractArgumentAttributes(parsedArgs);
            argsParser.ParseCommandLine(args);

            if (parsedArgs.Help)
            {
                argsParser.ShowUsage();
                Environment.Exit(-1);
            }

            var appRunTimer = new Stopwatch();

            appRunTimer.Start();

            var runner = new Runner();

            runner.Run(parsedArgs);

            appRunTimer.Stop();

            if (parsedArgs.NoExit)
            {
                System.Console.ReadKey();
            }
        }
コード例 #2
0
        private static LeprechaunConfigurationBuilder BuildConfiguration(ConsoleArgs args)
        {
            var config = new XmlDocument();

            config.Load(args.ConfigFilePath);

            var replacer = new ChainedVariablesReplacer(
                new ConfigurationNameVariablesReplacer(),
                new HelixConventionVariablesReplacer(),
                new ConfigPathVariableReplacer(Path.GetDirectoryName(args.ConfigFilePath)));

            var configObject = new LeprechaunConfigurationBuilder(replacer, config.DocumentElement["configurations"], config.DocumentElement["defaults"], config.DocumentElement["shared"], args.ConfigFilePath, new ConfigurationImportPathResolver(new ConsoleLogger()));

            // configure Rainbow
            RainbowSettings.Current = (RainbowSettings)configObject.Shared.Resolve <ILeprechaunRainbowSettings>();

            return(configObject);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            // PARSE ARGS
            var argsParser = new CommandLineParser.CommandLineParser();
            var parsedArgs = new ConsoleArgs();

            argsParser.ExtractArgumentAttributes(parsedArgs);
            argsParser.ParseCommandLine(args);

            if (parsedArgs.Help)
            {
                argsParser.ShowUsage();
                Environment.Exit(-1);
            }

            // RUN LEPRECHAUN
            if (!parsedArgs.NoSplash)
            {
                Ascii.Leprechaun();
            }

            var appRunTimer = new Stopwatch();

            appRunTimer.Start();

            var configuration = BuildConfiguration(parsedArgs);

            // start pre-compiling templates (for Roslyn provider anyway)
            // this lets C# be compiling in the background while we read the files to generate from disk
            // and saves time
            var preload = Task.Run(() =>
            {
                foreach (var config in configuration.Configurations)
                {
                    config.Resolve <ICodeGenerator>();
                }
            });

            // the orchestrator controls the overall codegen flow
            var orchestrator = configuration.Shared.Resolve <Orchestrator>();

            var metadata = GenerateMetadata(orchestrator, configuration);

            // make sure we're done preloading the compiled codegen templates
            preload.Wait();

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine($"Code generator has loaded in {appRunTimer.ElapsedMilliseconds}ms.");
            System.Console.ResetColor();

            GenerateCode(metadata);

            if (parsedArgs.Watch)
            {
                System.Console.WriteLine();
                System.Console.WriteLine("Leprechaun is now watching for file changes and rebuilding at need.");
                System.Console.WriteLine("Press Ctrl-C to exit.");
                Watcher.Watch(configuration, new ConsoleLogger(), () => GenerateWatch(orchestrator, configuration));
                var exit = new ManualResetEvent(false);
                exit.WaitOne();
            }

            appRunTimer.Stop();
            System.Console.WriteLine();
            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine($"Leprechaun has completed in {appRunTimer.ElapsedMilliseconds}ms.");
            System.Console.ResetColor();

            if (parsedArgs.NoExit)
            {
                System.Console.ReadKey();
            }
        }