private static int GenerateSharedCode(string inputPath, string outputBasePath) { if (!File.Exists(inputPath)) { Console.Error.WriteLine("Input path is not an existing file."); return(ExitFailure); } if (!Directory.Exists(outputBasePath)) { Console.Error.WriteLine("Output path base is not an existing directory."); return(ExitFailure); } var input = LoadFromString <List <ConstantCollection> >(File.ReadAllText(inputPath)); foreach (ConstantCollection col in input) { col.SourcePath = inputPath; // This isn't set by YamlDotNet, so it's added manually foreach (Dictionary <string, string> outputInfo in col.Outputs) { IOutputFile output = OutputFactory.CreateByType(outputInfo, col); string filePath = Path.Combine(outputBasePath, output.GetPath()); using (StreamWriter writer = new StreamWriter(filePath)) { Console.WriteLine("Writing file '{0}'", filePath); writer.Write(output.GetContent()); } } } return(ExitSuccess); }
private static int GenerateSharedCode(string inputPath, string outputBasePath) { var inputFiles = inputPath.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(path => path.Trim()); var errors = new StringBuilder(); foreach (var inputFile in inputFiles) { if (!File.Exists(inputPath)) { _ = errors.AppendLine($"File {inputFile} does not exist."); } } if (errors.Length > 0) { Console.Error.WriteLine(errors.ToString()); return(ExitFailure); } if (!Directory.Exists(outputBasePath)) { Console.Error.WriteLine("Output path base is not an existing directory."); return(ExitFailure); } var collections = new List <ConstantCollection>(); foreach (var inputFile in inputFiles) { var inputFileContent = File.ReadAllText(inputFile); var deserializedInput = LoadFromString <List <ConstantCollection> >(inputFileContent); deserializedInput.ForEach(collection => collection.SourcePath = inputFile); collections.AddRange(deserializedInput); } foreach (var collection in collections) { ReplaceVariablesWithValues(collection.StringConstants); foreach (Dictionary <string, string> outputInfo in collection.Outputs) { var output = OutputFactory.CreateByType(outputInfo, collection); var filePath = Path.Combine(outputBasePath, output.GetPath()); using (var writer = new StreamWriter(filePath)) { Console.WriteLine($"Writing file '{filePath}'"); writer.Write(output.GetContent()); } } } GenerateSupportedPlatformsReadmeFile(outputBasePath); return(ExitSuccess); }