Skip to content

Commit 2a79823

Browse files
committed
chore: use shared input for languages
1 parent 686f7ad commit 2a79823

File tree

16 files changed

+2456
-2257
lines changed

16 files changed

+2456
-2257
lines changed
File renamed without changes.
File renamed without changes.

input/2022/day1.txt

Lines changed: 2237 additions & 0 deletions
Large diffs are not rendered by default.

javascript/.babelrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"presets": ["@babel/env"]
2+
"presets": ["@babel/env"],
3+
"plugins": [
4+
[
5+
"@babel/plugin-transform-runtime",
6+
{
7+
"regenerator": true
8+
}
9+
]
10+
]
311
}

javascript/_template/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Day _______
1+
# Advent of Code {{YEAR}} Day {{DAY}}

javascript/_template/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { example, data } from './input'
1+
import { example } from './input'
22

33
export const inputParser = (input) => input.split('\n')
44

javascript/_template/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
const { inputParser, part1, part2 } = require('./index.js')
2-
const { example, data } = require('./input.js')
2+
const { example, getInput } = require('./input.js')
33

44
test('part 1 example', () => {
55
expect(part1(inputParser(example))).toBe(0)
66
})
77

8-
test('part 1 data', () => {
9-
expect(part1(inputParser(data))).toBe(0)
8+
test('part 1 data', async () => {
9+
expect(part1(inputParser(await getInput()))).toBe(0)
1010
})
1111

1212
test('part 2 example', () => {
1313
expect(part2(inputParser(example))).toBe(0)
1414
})
1515

16-
test('part 2 data', () => {
17-
expect(part2(inputParser(data))).toBe(0)
16+
test('part 2 data', async () => {
17+
expect(part2(inputParser(await getInput()))).toBe(0)
1818
})

javascript/_template/input.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import fs from 'fs'
2+
13
export const example = ``
24

3-
export const data = ``
5+
export const getInput = async () => fs.readFileSync('../input/{{YEAR}}/{{DAY}}')

javascript/bin/generate.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# Make a new directory
4+
mkdir -p ./solutions/$YEAR/$DAY
5+
6+
# Copy the template files over
7+
cp -r ./_template/ ./solutions/$YEAR/$DAY/
8+
9+
# Replace the year template variable
10+
sed -i '' "s/{{YEAR}}/$YEAR/g" ./solutions/$YEAR/$DAY/README.md
11+
sed -i '' "s/{{YEAR}}/$YEAR/g" ./solutions/$YEAR/$DAY/input.js
12+
13+
# Replace the day template variable
14+
sed -i '' "s/{{DAY}}/$DAY/g" ./solutions/$YEAR/$DAY/README.md
15+
sed -i '' "s/{{DAY}}/$DAY/g" ./solutions/$YEAR/$DAY/input.js
16+
17+
echo "Generated code for Advent of Code $YEAR Day $DAY 🎄"

javascript/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
"license": "MIT",
1212
"private": false,
1313
"scripts": {
14-
"new": "mkdir -p ./solutions/$YEAR/$DAY && cp -r ./_template/ ./solutions/$YEAR/$DAY/",
14+
"new": "bin/generate.sh",
15+
"inject-year": "",
16+
"inject-date": "",
1517
"solve": "rollup -c ./rollup.config.js --silent && node ./dist/main.js $YEAR $DAY",
1618
"test": "jest ./solutions/$YEAR/$DAY"
1719
},
1820
"devDependencies": {
1921
"@babel/core": "^7.12.10",
22+
"@babel/plugin-transform-runtime": "^7.19.6",
2023
"@babel/preset-env": "^7.12.11",
2124
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
2225
"babel-preset-es2015": "^6.24.1",

0 commit comments

Comments
 (0)