Skip to content

Commit 5206e7d

Browse files
committed
Add new day script and update README for environment setup
1 parent c65820b commit 5206e7d

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.env

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@ To run:
1212
bun run index.js
1313
```
1414

15+
## Start new day script
16+
17+
To create a new day's structure and download the input automatically:
18+
19+
1. Create a `.env` file in the root directory and add your Advent of Code session cookie:
20+
21+
```env
22+
AOC_SESSION=your_session_cookie_here
23+
```
24+
25+
2. Run the setup script with the day number:
26+
27+
```bash
28+
./new_day.sh <day_number>
29+
```
30+
1531
This project was created using `bun init` in bun v1.0.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

new_day.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# Usage: ./new_day.sh <day_number>
4+
5+
YEAR=2025
6+
DAY=$1
7+
8+
# Load .env file if it exists
9+
BASE_DIR=$(dirname "$0")
10+
ENV_FILE="$BASE_DIR/.env"
11+
if [ -f "$ENV_FILE" ]; then
12+
export $(grep -v '^#' "$ENV_FILE" | xargs)
13+
fi
14+
15+
if [ -z "$DAY" ]; then
16+
echo "Usage: $0 <day>"
17+
exit 1
18+
fi
19+
20+
PADDED_DAY=$(printf "%02d" $DAY)
21+
22+
# Define paths
23+
TEMPLATE_DIR="$BASE_DIR/src/$YEAR/day00"
24+
TARGET_DIR="$BASE_DIR/src/$YEAR/day$PADDED_DAY"
25+
26+
# Check if target directory exists
27+
if [ -d "$TARGET_DIR" ]; then
28+
echo "Directory $TARGET_DIR already exists."
29+
else
30+
echo "Creating $TARGET_DIR..."
31+
mkdir -p "$TARGET_DIR"
32+
33+
# Copy template files
34+
cp "$TEMPLATE_DIR/part1.ts" "$TARGET_DIR/"
35+
cp "$TEMPLATE_DIR/part2.ts" "$TARGET_DIR/"
36+
cp "$TEMPLATE_DIR/test.spec.ts" "$TARGET_DIR/"
37+
# Create empty input.txt if not downloading
38+
touch "$TARGET_DIR/input.txt"
39+
40+
# Update test.spec.ts with the correct day
41+
sed -i '' "s/Day x/Day $DAY/g" "$TARGET_DIR/test.spec.ts"
42+
fi
43+
44+
# Open problem page
45+
URL="https://adventofcode.com/$YEAR/day/$DAY"
46+
echo "Opening $URL..."
47+
open "$URL"
48+
49+
# Download input
50+
INPUT_URL="https://adventofcode.com/$YEAR/day/$DAY/input"
51+
INPUT_FILE="$TARGET_DIR/input.txt"
52+
53+
# Check for AOC_SESSION environment variable
54+
if [ -n "$AOC_SESSION" ]; then
55+
echo "Downloading input to $INPUT_FILE..."
56+
curl -s --cookie "session=$AOC_SESSION" "$INPUT_URL" > "$INPUT_FILE"
57+
else
58+
echo "AOC_SESSION env var not set. Cannot download input automatically."
59+
echo "To enable auto-download, set AOC_SESSION in .env file."
60+
open "$INPUT_URL"
61+
fi
62+
63+
echo "Done ✅ Day $DAY ready in $TARGET_DIR"
64+

0 commit comments

Comments
 (0)