aocrunner icon indicating copy to clipboard operation
aocrunner copied to clipboard

Templated file names and contents

Open mgwalker opened this issue 3 years ago • 0 comments

This PR updates the logic for creating a new day from templates by replacing {{AOC_DAY}} in filenames and in the content of files with the AoC day number (padded to two characters). I put the code directly in the dev.js file rather than creating a new file to handle the templating because it's so straightforward, but if you wanted to add more template replacements in the future, a separate file might be easier to reason about.

This is useful for me because I do some of my AoC puzzles in multiple languages, but I like to keep them all together. For consistency, I name them like day07.js, day07.py, etc. This change to the template allows me to very easily get this sort of file structure:

 aoc2017
|__ src
|____ day07
|______ index.js
        day07.js
        day07.py

And my index.js can correctly import my solution file; e.g.:

import run from "aocrunner";
import { part1, part2 } from "./day07.js";

run({
  part1: { solution: part1 },
  part2: { solution: part2 },
  trimTestInputs: true,
});

Previously I have used aocrunner to copy the files, and then manually rename them and update the import, but allowing the template functionality to also handle filenames and contents would be a blessing! 😄

mgwalker avatar Dec 31 '21 15:12 mgwalker