From f4bc47bc236a997e3a6787f0933e5f1096ac8f93 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Thu, 8 Dec 2022 10:15:42 -0500 Subject: [PATCH] hygen --- 2022/template/part1.js | 1 - 2022/template/part2.js | 1 - Taskfile.yaml | 6 ++++++ _templates/day/new/hello.ejs.t | 15 +++++++++++++++ _templates/day/new/part1.ejs | 6 ++++++ _templates/day/new/part2.ejs | 7 +++++++ _templates/day/new/prompt.js | 7 +++++++ .../test.js => _templates/day/new/test.ejs | 11 +++++++---- _templates/generator/help/index.ejs.t | 5 +++++ _templates/generator/new/hello.ejs.t | 18 ++++++++++++++++++ _templates/generator/with-prompt/hello.ejs.t | 18 ++++++++++++++++++ _templates/generator/with-prompt/prompt.ejs.t | 14 ++++++++++++++ _templates/init/repo/new-repo.ejs.t | 4 ++++ 13 files changed, 107 insertions(+), 6 deletions(-) delete mode 100644 2022/template/part1.js delete mode 100644 2022/template/part2.js create mode 100644 _templates/day/new/hello.ejs.t create mode 100644 _templates/day/new/part1.ejs create mode 100644 _templates/day/new/part2.ejs create mode 100644 _templates/day/new/prompt.js rename 2022/template/test.js => _templates/day/new/test.ejs (50%) create mode 100644 _templates/generator/help/index.ejs.t create mode 100644 _templates/generator/new/hello.ejs.t create mode 100644 _templates/generator/with-prompt/hello.ejs.t create mode 100644 _templates/generator/with-prompt/prompt.ejs.t create mode 100644 _templates/init/repo/new-repo.ejs.t diff --git a/2022/template/part1.js b/2022/template/part1.js deleted file mode 100644 index b509eb0..0000000 --- a/2022/template/part1.js +++ /dev/null @@ -1 +0,0 @@ -import * as R from "remeda"; diff --git a/2022/template/part2.js b/2022/template/part2.js deleted file mode 100644 index b509eb0..0000000 --- a/2022/template/part2.js +++ /dev/null @@ -1 +0,0 @@ -import * as R from "remeda"; diff --git a/Taskfile.yaml b/Taskfile.yaml index af75c42..eaa296d 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -6,6 +6,8 @@ vars: YEAR: 2022 DAY: sh: date '+%d' | perl -pe's/^0//' + DAY_FORMATTED: + sh: date '+%d' GREETING: Hello, World! tasks: @@ -25,6 +27,10 @@ tasks: cmds: - firefox https://adventofcode.com/{{.YEAR}}/day/{{.DAY}} + download: + cmds: + - aoc download -d {{.DAY}} -o -p 2022/{{.DAY_FORMATTED}}/puzzle.md -i 2022/{{.DAY_FORMATTED}}/input + default: cmds: - echo "{{.GREETING}}" diff --git a/_templates/day/new/hello.ejs.t b/_templates/day/new/hello.ejs.t new file mode 100644 index 0000000..095a04e --- /dev/null +++ b/_templates/day/new/hello.ejs.t @@ -0,0 +1,15 @@ +--- +to: app/hello.js +--- +const hello = ``` +Hello! +This is your first hygen template. + +Learn what it can do here: + +https://github.com/jondot/hygen +``` + +console.log(hello) + + diff --git a/_templates/day/new/part1.ejs b/_templates/day/new/part1.ejs new file mode 100644 index 0000000..97460f5 --- /dev/null +++ b/_templates/day/new/part1.ejs @@ -0,0 +1,6 @@ +--- +to: 2022/<%= day %>/part1.js +--- +import * as R from "remeda"; + +export default = () => {}; diff --git a/_templates/day/new/part2.ejs b/_templates/day/new/part2.ejs new file mode 100644 index 0000000..e59c761 --- /dev/null +++ b/_templates/day/new/part2.ejs @@ -0,0 +1,7 @@ +--- +to: 2022/<%= day %>/part2.js +--- +import * as R from "remeda"; + + +export default = () => {}; diff --git a/_templates/day/new/prompt.js b/_templates/day/new/prompt.js new file mode 100644 index 0000000..bfff832 --- /dev/null +++ b/_templates/day/new/prompt.js @@ -0,0 +1,7 @@ +module.exports = [ + { + type: 'input', + name: 'day', + message: "advent day?" + } +] diff --git a/2022/template/test.js b/_templates/day/new/test.ejs similarity index 50% rename from 2022/template/test.js rename to _templates/day/new/test.ejs index 07ae1e1..f82ac18 100644 --- a/2022/template/test.js +++ b/_templates/day/new/test.ejs @@ -1,17 +1,20 @@ +--- +to: 2022/<%= day %>/test.js +--- import { test, expect, describe } from "vitest"; import { expectSolution } from "../01/main.js"; -import { solutionPart1, puzzleInput } from "./part1.js"; -import { solutionPart2 } from "./part2.js"; +import part1, { sample, puzzleInput } from "./part1.js"; +import part2 from "./part2.js"; describe("part 1", () => { test.todo("solution", () => { - expectSolution(solutionPart1(puzzleInput)).toEqual("TODO"); + expectSolution(part1(puzzleInput)).toEqual("TODO"); }); }); describe("part 2", () => { test.todo("solution", () => { - expectSolution(solutionPart2(puzzleInput)).toEqual("TODO"); + expectSolution(part2(puzzleInput)).toEqual("TODO"); }); }); diff --git a/_templates/generator/help/index.ejs.t b/_templates/generator/help/index.ejs.t new file mode 100644 index 0000000..90a29af --- /dev/null +++ b/_templates/generator/help/index.ejs.t @@ -0,0 +1,5 @@ +--- +message: | + hygen {bold generator new} --name [NAME] --action [ACTION] + hygen {bold generator with-prompt} --name [NAME] --action [ACTION] +--- \ No newline at end of file diff --git a/_templates/generator/new/hello.ejs.t b/_templates/generator/new/hello.ejs.t new file mode 100644 index 0000000..5680d96 --- /dev/null +++ b/_templates/generator/new/hello.ejs.t @@ -0,0 +1,18 @@ +--- +to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t +--- +--- +to: app/hello.js +--- +const hello = ``` +Hello! +This is your first hygen template. + +Learn what it can do here: + +https://github.com/jondot/hygen +``` + +console.log(hello) + + diff --git a/_templates/generator/with-prompt/hello.ejs.t b/_templates/generator/with-prompt/hello.ejs.t new file mode 100644 index 0000000..ba6abc5 --- /dev/null +++ b/_templates/generator/with-prompt/hello.ejs.t @@ -0,0 +1,18 @@ +--- +to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t +--- +--- +to: app/hello.js +--- +const hello = ``` +Hello! +This is your first prompt based hygen template. + +Learn what it can do here: + +https://github.com/jondot/hygen +``` + +console.log(hello) + + diff --git a/_templates/generator/with-prompt/prompt.ejs.t b/_templates/generator/with-prompt/prompt.ejs.t new file mode 100644 index 0000000..76ea532 --- /dev/null +++ b/_templates/generator/with-prompt/prompt.ejs.t @@ -0,0 +1,14 @@ +--- +to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js +--- + +// see types of prompts: +// https://github.com/enquirer/enquirer/tree/master/examples +// +module.exports = [ + { + type: 'input', + name: 'message', + message: "What's your message?" + } +] diff --git a/_templates/init/repo/new-repo.ejs.t b/_templates/init/repo/new-repo.ejs.t new file mode 100644 index 0000000..08e7cff --- /dev/null +++ b/_templates/init/repo/new-repo.ejs.t @@ -0,0 +1,4 @@ +--- +setup: <%= name %> +force: true # this is because mostly, people init into existing folders is safe +---