Skip to content

Commit

Permalink
add generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Dec 1, 2024
1 parent 005edfb commit c7ad56f
Show file tree
Hide file tree
Showing 7 changed files with 2,040 additions and 27 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
"postinstall": "husky"
},
"devDependencies": {
"@turbo/gen": "^2.3.3",
"@types/node": "^22.9.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"tsx": "^4.19.2",
"turbo": "^2.3.3",
"typescript": "^5.6.3"
},
"workspaces": [
Expand Down
97 changes: 97 additions & 0 deletions turbo/generators/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { PlopTypes } from "@turbo/gen";

export default function generator(plop: PlopTypes.NodePlopAPI): void {
plop.setGenerator('Typescript', {
description: 'Generate Typescript AoC day skeleton',
prompts: [
{
type: 'input',
name: 'year',
message: 'Enter year in which you want to create day skeleton',
default: (new Date()).getFullYear(),
},
{
type: 'input',
name: 'day',
message: 'Enter day which you are working on',
default: (new Date()).getDate().toString().padStart(2, '0')
},
{
type: 'list',
name: 'withTestRuns',
message: 'Do you want to include test runs skeleton?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false },
],
default: true
}
],
actions: [
{
type: 'add',
path: '{{ turbo.paths.root }}/{{ year }}/d{{ day }}/main.ts',
templateFile: 'templates/typescript/main.ts',
},
{
type: 'add',
path: '{{ turbo.paths.root }}/{{ year }}/d{{ day }}/input.txt',
templateFile: 'templates/typescript/input.txt',
},
{
type: 'add',
path: '{{ turbo.paths.root }}/{{ year }}/d{{ day }}/test-runs/0.txt',
templateFile: 'templates/typescript/test-runs/0.txt',
skip: ({ withTestRuns }: { withTestRuns: boolean }) => {
if (withTestRuns) {
return false
}

return 'Test runs skipped'
}
}
]
})

// plop.setGenerator("example", {
// description:
// "An example Turborepo generator - creates a new file at the root of the project",
// prompts: [
// {
// type: "input",
// name: "file",
// message: "What is the name of the new file to create?",
// validate: (input: string) => {
// if (input.includes(".")) {
// return "file name cannot include an extension";
// }
// if (input.includes(" ")) {
// return "file name cannot include spaces";
// }
// if (!input) {
// return "file name is required";
// }
// return true;
// },
// },
// {
// type: "list",
// name: "type",
// message: "What type of file should be created?",
// choices: [".md", ".txt"],
// },
// {
// type: "input",
// name: "title",
// message: "What should be the title of the new file?",
// },
// ],
// actions: [
// {
// type: "add",
// path: "{{ turbo.paths.root }}/{{ dashCase file }}{{ type }}",
// templateFile: "templates/turborepo-generators.hbs",
// },
// ],
// });
}
3 changes: 3 additions & 0 deletions turbo/generators/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Empty file.
18 changes: 18 additions & 0 deletions turbo/generators/templates/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { readFileSync } from 'node:fs'

import { testRuns, solutionRuns } from '../util/aoc'

const part1 = (data: string): number => {
return 0
}

const part2 = (data: string): number => {
return 0
}

const reader = (file: string): string => {
return readFileSync(file, 'utf-8').trim()
}

testRuns('{{ day }}', reader, part1, part2)
solutionRuns('{{ day }}', reader, part1, part2)
Empty file.
Loading

0 comments on commit c7ad56f

Please sign in to comment.