/// <see cref="IGeneratorMode"/> public override bool Initialize(string path, string[] args) { // File mode requires a minimum of 3 arguments _path = path; if (args.Length < 2) { return(false); } // Second argument is parser var ext = Path.GetExtension(_path); Parsers[ext] = ParserFactory.Resolve(args[0]); // Load generators GeneratorFactory.Initialize(new[] { Assembly.GetExecutingAssembly() }); // All following arguments are the active generators for (var i = 1; i < args.Length; i++) { Generators.Add(GeneratorFactory.Resolve(args[i])); } return(true); }
/// <see cref="IGeneratorMode"/> public override bool Initialize(string path, string[] args) { _directory = path; // Look for the config var configPath = Path.Combine(_directory, "cgbr.json"); if (!File.Exists(configPath)) { Console.WriteLine("Project mode requires a config."); return(false); } // Read and parse config var configText = File.ReadAllText(configPath); var config = JsonConvert.DeserializeObject <CgbrConfiguration>(configText); // Load extension parsers var assemblies = ResolveAssemblies(config.Extensions); GeneratorFactory.Initialize(assemblies); // Parser mappings foreach (var mapping in config.Mappings) { Parsers[mapping.Extension] = ParserFactory.Resolve(mapping.Parser); } // Generators foreach (var localGenerator in config.LocalGenerators.Where(gen => gen.IsEnabled)) { Generators.Add(GeneratorFactory.Resolve(localGenerator.Name)); } foreach (var globalGenerator in config.GlobalGenerators.Where(gen => gen.IsEnabled)) { Generators.Add(GeneratorFactory.Resolve(globalGenerator.Name)); } return(true); }