Skip to content

Commit

Permalink
Set up ts-node project
Browse files Browse the repository at this point in the history
  • Loading branch information
bverhoeven committed Dec 1, 2021
1 parent b60eb14 commit 1744723
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
env: {
node: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
rules: {
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
ignorePatterns: ['node_modules/', 'dist/'],
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
package-lock.json
18 changes: 18 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"printWidth": 100,
"semi": false,
"singleQuote": true,
"overrides": [
{
"files": [
"*.yaml",
"*.yml"
],
"options": {
"tabWidth": 2
}
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Advent of Code 2021

## Getting started:

```
npm install
```

## Running solutions:

```
npm start -w day-<x>
```

```
npm start -w day-1
```
7 changes: 7 additions & 0 deletions __template__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getInputAsLines, getTestInputAsLines } from '../shared/input'

const partOne = undefined
const partTwo = undefined

console.log('Part one:', partOne)
console.log('Part two:', partTwo)
Empty file added __template__/input.txt
Empty file.
5 changes: 5 additions & 0 deletions __template__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"start": "ts-node index.ts"
}
}
Empty file added __template__/test_input.txt
Empty file.
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "aoc2021",
"version": "1.0.0",
"description": "Advent of Code 2021",
"scripts": {
"start": "echo \"Specify a workspace, e.g: npm start -w day-1\" && exit 1",
"format": "prettier -w '**/*.ts'"
},
"workspaces": [
"./day-*"
],
"author": "Bas Verhoeven",
"license": "ISC",
"devDependencies": {
"@types/node": "^16.11.11",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"prettier": "^2.5.0",
"ts-node": "^10.4.0",
"typescript": "^4.5.2"
}
}
13 changes: 13 additions & 0 deletions shared/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readFileSync } from 'node:fs'

export function getInput(filename = 'input.txt'): string {
return readFileSync(filename, 'utf8').trim()
}

export function getInputAsLines(filename = 'input.txt'): string[] {
return getInput(filename).split('\n')
}

export function getTestInputAsLines(filename = 'test_input.txt'): string[] {
return getInputAsLines(filename)
}

0 comments on commit 1744723

Please sign in to comment.