From eb723f51127b494e296e1cf7666730754aac3f89 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Sat, 18 Nov 2023 17:06:39 +0100 Subject: [PATCH] hygen rust --- README.md | 2 +- _templates/riddle/new/cargo.ejs.t | 10 ++++++++++ _templates/riddle/new/index.js | 9 ++++++++- _templates/riddle/new/input.txt.t | 2 +- _templates/riddle/new/python.ejs.t | 2 +- _templates/riddle/new/readme.ejs.t | 2 +- _templates/riddle/new/rust.ejs.t | 9 +++++++++ _templates/riddle/new/test.txt.t | 2 +- package.json | 3 +++ 9 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 _templates/riddle/new/cargo.ejs.t create mode 100644 _templates/riddle/new/rust.ejs.t diff --git a/README.md b/README.md index b23233d..eb9a694 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ > New days are generated with [`hygen`](https://github.com/jondot/hygen). > -> `hygen riddle new --year 2021 --day 01` +> `bun run gen --year 2022 --day 1` diff --git a/_templates/riddle/new/cargo.ejs.t b/_templates/riddle/new/cargo.ejs.t new file mode 100644 index 0000000..169204c --- /dev/null +++ b/_templates/riddle/new/cargo.ejs.t @@ -0,0 +1,10 @@ +--- +inject: true +to: cargo.toml +before: "# INJECT HERE" +skip_if: <%= id %> +--- + +[[bin]] +name = "<%= id %>" +path = "<%= dir %>/rust/main.rs" diff --git a/_templates/riddle/new/index.js b/_templates/riddle/new/index.js index 8de68c8..26bbf3e 100644 --- a/_templates/riddle/new/index.js +++ b/_templates/riddle/new/index.js @@ -12,6 +12,13 @@ async function getInput(year, day) { module.exports = { params: async ({ args }) => { - return { ...args, input: await getInput(args.year, args.day) } + const day = args.day.toString().padStart(2, '0') // Padded + return { + ...args, + id: `${args.year}-${day}`, + dir: `./${args.year}/${day}`, + input: await getInput(args.year, parseInt(day)), + day, + } }, } diff --git a/_templates/riddle/new/input.txt.t b/_templates/riddle/new/input.txt.t index f662854..85b4622 100644 --- a/_templates/riddle/new/input.txt.t +++ b/_templates/riddle/new/input.txt.t @@ -1,5 +1,5 @@ --- -to: <%= year %>/<%= day %>/input.txt +to: <%= dir %>/input.txt unless_exists: true --- <%= input %> diff --git a/_templates/riddle/new/python.ejs.t b/_templates/riddle/new/python.ejs.t index 74941ad..58ffbd0 100644 --- a/_templates/riddle/new/python.ejs.t +++ b/_templates/riddle/new/python.ejs.t @@ -1,5 +1,5 @@ --- -to: <%= year %>/<%= day %>/python/main.py +to: <%= dir %>/python/main.py unless_exists: true --- #!/usr/bin/env python diff --git a/_templates/riddle/new/readme.ejs.t b/_templates/riddle/new/readme.ejs.t index 20cf874..a4f55b4 100644 --- a/_templates/riddle/new/readme.ejs.t +++ b/_templates/riddle/new/readme.ejs.t @@ -1,5 +1,5 @@ --- -to: <%= year %>/<%= day %>/README.md +to: <%= dir %>/README.md unless_exists: true --- diff --git a/_templates/riddle/new/rust.ejs.t b/_templates/riddle/new/rust.ejs.t new file mode 100644 index 0000000..f2e0e10 --- /dev/null +++ b/_templates/riddle/new/rust.ejs.t @@ -0,0 +1,9 @@ +--- +to: <%= dir %>/rust/main.rs +unless_exists: true +--- +fn main() { + // Part A + let contents = include_str!("../test.txt").trim(); + println!("A: {}", contents); +} diff --git a/_templates/riddle/new/test.txt.t b/_templates/riddle/new/test.txt.t index 916a64b..aacdcb4 100644 --- a/_templates/riddle/new/test.txt.t +++ b/_templates/riddle/new/test.txt.t @@ -1,4 +1,4 @@ --- -to: <%= year %>/<%= day %>/test.txt +to: <%= dir %>/test.txt unless_exists: true --- diff --git a/package.json b/package.json index eee4f57..a4d817a 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,7 @@ { + "scripts": { + "gen": "bun hygen riddle new" + }, "dependencies": { "axios": "^1.6.0", "hygen": "^6.2.11"