private LeprechaunConfigurationBuilder BuildConfiguration(IRuntimeArgs args) { XmlDocument config = new XmlDocument(); args.ConfigFilePath = EnsureAbsoluteConfigPath(args.ConfigFilePath); if (Path.GetExtension(args.ConfigFilePath) == ".json") { config = JsonConvert.DeserializeXmlNode(File.ReadAllText(args.ConfigFilePath)); } else { config.Load(args.ConfigFilePath); } var replacer = GetVariablesReplacer(args); XmlElement configsElement = config.DocumentElement["configurations"]; XmlElement baseConfigElement = config.DocumentElement["defaults"]; XmlElement sharedConfigElement = config.DocumentElement["shared"]; var configObject = new LeprechaunConfigurationBuilder(replacer, configsElement, baseConfigElement, sharedConfigElement, args.ConfigFilePath, new ConfigurationImportPathResolver(new ConsoleLogger())); return(configObject); }
private IContainerDefinitionVariablesReplacer GetVariablesReplacer(IRuntimeArgs args) { return(new ChainedVariablesReplacer( new ConfigurationNameVariablesReplacer(), new HelixConventionVariablesReplacer(), new ConfigPathVariableReplacer(Path.GetDirectoryName(args.ConfigFilePath)))); }
public void Run(IRuntimeArgs parsedArgs) { // 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 <IOrchestrator>(); var metadata = GenerateMetadata(orchestrator, configuration); // make sure we're done preloading the compiled codegen templates preload.Wait(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Code generator has loaded in {appRunTimer.ElapsedMilliseconds}ms."); Console.ResetColor(); GenerateCode(metadata); if (parsedArgs.Watch) { IWatcher watcher = configuration.Shared.Resolve <IWatcher>(); if (watcher == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to watch because no IWatcher was defined!"); } else { Console.WriteLine(); Console.WriteLine("Leprechaun is now watching for file changes and rebuilding at need."); Console.WriteLine("Press Ctrl-C to exit."); watcher.Watch(configuration, new ConsoleLogger(), () => GenerateWatch(orchestrator, configuration)); var exit = new ManualResetEvent(false); exit.WaitOne(); } } appRunTimer.Stop(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Leprechaun has completed in {appRunTimer.ElapsedMilliseconds}ms."); Console.ResetColor(); }