public static void ExecuteAllRecipesAndGenerateWebsite(string cookbookProjectFolder) { Console.WriteLine("Deleting old cookbook files..."); string outputFolder = Path.Combine(cookbookProjectFolder, "CookbookOutput"); if (Directory.Exists(outputFolder)) { Directory.Delete(outputFolder, recursive: true); } Directory.CreateDirectory(outputFolder); string jsonFilePath = Path.Combine(outputFolder, "recipes.json"); string imageFolderPath = Path.Combine(outputFolder, "images"); Directory.CreateDirectory(imageFolderPath); Console.WriteLine($"Generating Images..."); RecipeImages.Generate(imageFolderPath); Console.WriteLine($"Generating JSON..."); string json = RecipeJson.Generate(cookbookProjectFolder); File.WriteAllText(jsonFilePath, json); Console.WriteLine($"Reading JSON..."); RecipeSource[] recipes = RecipeJson.GetRecipes(jsonFilePath).Values.Select(x => x).ToArray(); Console.WriteLine($"Generating website..."); Website.Generate(outputFolder, recipes); Console.WriteLine($"SAVED IN: {outputFolder}"); }
private static void GenerateEverything(string outputImageFolder, string outputJsonFile, string cookbookFolder) { Stopwatch sw = Stopwatch.StartNew(); Console.WriteLine($"Generating images: {outputImageFolder}"); RecipeImages.Generate(outputImageFolder); Console.WriteLine($"Generating source: {outputJsonFile}"); RecipeJson.Generate(cookbookFolder, outputJsonFile); Console.WriteLine($"Finished in {sw.Elapsed.TotalSeconds:F3} seconds"); }
public void Test_Generate_Cookbook() { Console.WriteLine($"Generating cookbook in:\n{OUTPUT_FOLDER}"); // DELETE OLD COOKBOOK if (Directory.Exists(OUTPUT_FOLDER)) { Directory.Delete(OUTPUT_FOLDER, recursive: true); } Directory.CreateDirectory(OUTPUT_FOLDER); // GENERATE IMAGES Console.WriteLine($"Generating PNGs..."); Stopwatch sw = Stopwatch.StartNew(); IRecipe[] imageRecipes = RecipeImages.Generate(Path.Join(OUTPUT_FOLDER, "images")); Console.WriteLine($"Generated {imageRecipes.Length} PNGs in {sw.Elapsed.TotalSeconds:F4} sec"); // GENERATE JSON Console.Write($"Generating JSON..."); sw.Restart(); RecipeSource[] sourceRecipes = RecipeJson.Generate(COOKBOOK_PROJECT_FOLDER, JSON_FILE); Console.WriteLine($" {sw.Elapsed.TotalSeconds:F4} sec"); // READ JSON BACK Console.Write($"Validating JSON..."); sw.Restart(); List <string> readIDs = new(); using JsonDocument document = JsonDocument.Parse(File.ReadAllText(JSON_FILE)); string version = document.RootElement.GetProperty("version").GetString(); string generated = document.RootElement.GetProperty("generated").GetString(); foreach (JsonElement recipeElement in document.RootElement.GetProperty("recipes").EnumerateArray()) { string id = recipeElement.GetProperty("id").GetString(); string category = recipeElement.GetProperty("category").GetString(); string title = recipeElement.GetProperty("title").GetString(); string description = recipeElement.GetProperty("description").GetString(); string code = recipeElement.GetProperty("code").GetString(); readIDs.Add(id); } Console.WriteLine($" {sw.Elapsed.TotalSeconds:F4} sec"); // VALIDATE Assert.AreEqual(imageRecipes.Length, sourceRecipes.Length); Assert.AreEqual(sourceRecipes.Length, readIDs.Count); }
public void Test_Json_IsValid() { string jsonFilePath = Path.GetFullPath("cookbook-valid-test.json"); IRecipe[] recipes = Locate.GetRecipes(); string json = RecipeJson.Generate(COOKBOOK_PROJECT_FOLDER); File.WriteAllText(jsonFilePath, json); Dictionary <string, RecipeSource> readRecipes = RecipeJson.GetRecipes(new FileInfo(jsonFilePath)); Console.WriteLine($"Read {readRecipes.Count} recipes from JSON"); Assert.AreEqual(recipes.Length, readRecipes.Count); }
public static RecipeSource[] Generate(string cookbookProjectFolder, string outputFolder, bool regenerate = false) { string jsonFilePath = Path.Combine(outputFolder, "recipes.json"); string imageFolderPath = Path.Combine(outputFolder, "images"); if (regenerate) { if (Directory.Exists(imageFolderPath)) { Directory.Delete(imageFolderPath, recursive: true); } Directory.CreateDirectory(imageFolderPath); Console.WriteLine($"Generating Images: {imageFolderPath}"); RecipeImages.Generate(imageFolderPath); Console.WriteLine($"Generating JSON ..."); string json = RecipeJson.Generate(cookbookProjectFolder); File.WriteAllText(jsonFilePath, json); } Console.WriteLine($"Reading JSON ..."); return(RecipeJson.GetRecipes(new FileInfo(jsonFilePath)).Values.Select(x => x).ToArray()); }