-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: revamp code generation and input handling
- Loading branch information
1 parent
5664ae7
commit 894c751
Showing
12 changed files
with
776 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
{ | ||
"presets": ["@babel/env"] | ||
"presets": ["@babel/env"], | ||
"plugins": [ | ||
[ | ||
"@babel/plugin-transform-runtime", | ||
{ | ||
"regenerator": true | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# Day _______ | ||
# Advent of Code {{YEAR}} Day {{DAY}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
import { example, data } from './input' | ||
export const parseInput = (input) => input.split('\n') | ||
|
||
export const inputParser = (input) => input.split('\n') | ||
|
||
const parsedData = inputParser(input) | ||
|
||
export const part1 = (input = parsedData) => { | ||
export const part1 = (input) => { | ||
return | ||
} | ||
|
||
export const part2 = (input = parsedData) => { | ||
export const part2 = (input) => { | ||
return | ||
} | ||
|
||
export default { | ||
part1, | ||
part2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
const { inputParser, part1, part2 } = require('./index.js') | ||
const { example, data } = require('./input.js') | ||
const { parseInput, part1, part2 } = require('./index.js') | ||
const { getExampleInput, getInput } = require('./input.js') | ||
|
||
test('part 1 example', () => { | ||
expect(part1(inputParser(example))).toBe(0) | ||
test('part 1 example', async () => { | ||
expect(part1(parseInput(await getExampleInput()))).toBe(0) | ||
}) | ||
|
||
test('part 1 data', () => { | ||
expect(part1(inputParser(data))).toBe(0) | ||
test('part 1 data', async () => { | ||
expect(part1(parseInput(await getInput()))).toBe(0) | ||
}) | ||
|
||
test('part 2 example', () => { | ||
expect(part2(inputParser(example))).toBe(0) | ||
test('part 2 example', async () => { | ||
expect(part2(parseInput(await getExampleInput()))).toBe(0) | ||
}) | ||
|
||
test('part 2 data', () => { | ||
expect(part2(inputParser(data))).toBe(0) | ||
test('part 2 data', async () => { | ||
expect(part2(parseInput(await getInput()))).toBe(0) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
export const example = `` | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
export const data = `` | ||
export const getExampleInput = async () => | ||
fs | ||
.readFileSync( | ||
path.resolve(process.env.NODE_PATH, 'inputs/{{YEAR}}/{{DAY}}/example.txt') | ||
) | ||
.toString() | ||
|
||
export const getInput = async () => | ||
fs | ||
.readFileSync( | ||
path.resolve(process.env.NODE_PATH, 'inputs/{{YEAR}}/{{DAY}}/input.txt') | ||
) | ||
.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
# Make solution directory | ||
mkdir -p ./solutions/$YEAR/$DAY | ||
|
||
# Make input files | ||
mkdir -p ./inputs/$YEAR/$DAY | ||
touch ./inputs/$YEAR/$DAY/input.txt | ||
touch ./inputs/$YEAR/$DAY/example.txt | ||
|
||
# Copy the template files over | ||
cp -r ./_template/ ./solutions/$YEAR/$DAY/ | ||
|
||
# Replace the year template variable | ||
sed -i '' "s/{{YEAR}}/$YEAR/g" ./solutions/$YEAR/$DAY/README.md | ||
sed -i '' "s/{{YEAR}}/$YEAR/g" ./solutions/$YEAR/$DAY/input.js | ||
|
||
# Replace the day template variable | ||
sed -i '' "s/{{DAY}}/$DAY/g" ./solutions/$YEAR/$DAY/README.md | ||
sed -i '' "s/{{DAY}}/$DAY/g" ./solutions/$YEAR/$DAY/input.js | ||
|
||
echo "Generated code for Advent of Code $YEAR Day $DAY π" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.