From df609c1bae6d6761ff0eb71bcdbfea1eb1dc6cc1 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:53 -0400 Subject: [PATCH] feat: patch README calendar with link to solution --- 2021/README.md | 2 ++ 2021/lib/mix/tasks/advent_of_code.gen.solution.ex | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/2021/README.md b/2021/README.md index c6318ec..937e179 100644 --- a/2021/README.md +++ b/2021/README.md @@ -36,3 +36,5 @@ A behaviour for a solution to a puzzle. Must define a `solve/2` callback. ## [`AdventOfCode.PuzzleCase`](./test/support/puzzle_case.ex) Case template defining an `assert_solution/2` helper. + + diff --git a/2021/lib/mix/tasks/advent_of_code.gen.solution.ex b/2021/lib/mix/tasks/advent_of_code.gen.solution.ex index 8b9151a..8d32c3b 100644 --- a/2021/lib/mix/tasks/advent_of_code.gen.solution.ex +++ b/2021/lib/mix/tasks/advent_of_code.gen.solution.ex @@ -48,6 +48,16 @@ defmodule Mix.Tasks.AdventOfCode.Gen.Solution do create_file(part_test_file, part_test_contents) end + day_regex = ~r/\W(#{day})\W/ + readme_file = "README.md" + readme_contents = File.read!("README.md") + + readme_contents = + "#{String.replace(readme_contents, day_regex, "[\\1]")}\n[#{day}]: ./#{day_file}\n" + + File.write!(readme_file, readme_contents) + Mix.shell().info([:green, "* updating ", :reset, "README.md"]) + _ -> Mix.raise("Unknown arguments.") end @@ -58,8 +68,6 @@ defmodule Mix.Tasks.AdventOfCode.Gen.Solution do @moduledoc """ Day <%= @day %> """ - - end defmodule <%= inspect(@mod) %>.Part1 do