"Setup template for Current Year (2020)"

This commit is contained in:
Joshua Seigler 2020-12-02 23:53:45 -05:00
parent 170e72f666
commit eb884ec643
6 changed files with 72 additions and 58 deletions

View file

@ -1,14 +1,12 @@
# Advent of Code Template
# Advent of Code 2020
Advent of Code Template using Node JS for Current Year.
My solutions for Advent of Code 2020.
## Setup
If using the Advent of Code Template repo; click [**`Use this template`**](https://github.com/johnbeech/advent-of-code-nodejs-template/generate) and set a new repository name.
Clone this repo, then run `npm install` to install dependencies.
If this a brand new repository, run: `node setup` to configure it for Current Year and check in the changes.
## Running

View file

@ -1,8 +1,8 @@
{
"name": "advent-of-code-template",
"logName": "Advent of Code Template",
"name": "advent-of-code-2020",
"logName": "Advent of Code 2020",
"version": "1.0.0",
"description": "Advent of Code Template using Node JS for Current Year.",
"description": "Advent of Code 2020 using Node JS for Current Year.",
"main": "run.js",
"scripts": {
"start": "npm run test && node run.js",

View file

@ -1,51 +0,0 @@
const path = require('path')
const { read, write, position, run } = require('promise-path')
const fromHere = position(__dirname)
const report = (...messages) => console.log(`[${require(fromHere('./package.json')).logName} / ${__filename.split(path.sep).pop().split('.js').shift()}]`, ...messages)
async function replaceInFile (filename, search, replace) {
const haystack = await read(filename, 'utf8')
const ashes = haystack.replace(search, replace)
return write(filename, ashes, 'utf8')
}
async function setup () {
const currentPath = fromHere('/')
const currentFolder = currentPath.split('/').reverse()[1]
report('Setting up template from:', currentFolder)
const currentYear = currentFolder.split('-').pop()
if (currentYear === 'template') {
console.error(' No current year provided.')
console.error(' Please re-run setup after renaming the repo, e.g.: advent-of-code-2020, advent-of-code-2021, advent-of-code-2022, etc.')
console.error('')
process.exit(0)
}
report('Replacing strings in templates')
await replaceInFile('README.md', 'If using the Advent of Code Template repo; click [**`Use this template`**](https://github.com/johnbeech/advent-of-code-nodejs-template/generate) and set a new repository name.\n', '')
await replaceInFile('README.md', 'If this a brand new repository, run: `node setup` to configure it for Current Year and check in the changes.\n', '')
await replaceInFile('package.json', /Advent of Code Template/g, `Advent of Code ${currentYear}`)
await replaceInFile('README.md', '# Advent of Code Template', `# Advent of Code ${currentYear}`)
await replaceInFile('package.json', 'Advent of Code Template using Node JS for Current Year.', `My solutions for Advent of Code ${currentYear}.`)
await replaceInFile('README.md', 'Advent of Code Template using Node JS for Current Year.', `My solutions for Advent of Code ${currentYear}.`)
await replaceInFile('package.json', 'advent-of-code-template', currentFolder)
report('Removing setup script')
await run(`rm ${fromHere('setup.js')}`)
report('Committing changes and pushing to remote')
await run('git add .')
await run(`git commit -m "Setup template for Current Year (${currentYear})"`)
await run('git push')
report(`All done! ${currentYear} setup and ready to go~`)
}
setup()

0
solutions/day3/input.txt Normal file
View file

View file

@ -0,0 +1,24 @@
const path = require('path')
const { read, position } = require('promise-path')
const fromHere = position(__dirname)
const report = (...messages) => console.log(`[${require(fromHere('../../package.json')).logName} / ${__dirname.split(path.sep).pop()}]`, ...messages)
async function run () {
const input = (await read(fromHere('input.txt'), 'utf8')).trim()
await solveForFirstStar(input)
await solveForSecondStar(input)
}
async function solveForFirstStar (input) {
const solution = 'UNSOLVED'
// report('Input:', input);
report('Solution 1:', solution)
}
async function solveForSecondStar (input) {
const solution = 'UNSOLVED'
report('Solution 2:', solution)
}
run()

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<title>Solution Viewer</title>
<style>
html, body { font-family: sans-serif; }
pre { border-radius: 0.5em; padding: 0.5em; background: #eee; }
</style>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="viewer">
<h1>Solution Viewer ({{ solutionTitle }})</h1>
<p>For interesting problems; this page can be used as a dynamic viewer.</p>
<h3><a href="./input.txt">input.txt</a></h3>
<pre><code>{{ inputText }}</code></pre>
<h3><a href="./solution.js">solution.js</a></h3>
<pre><code>{{ solutionText }}</code></pre>
</div>
<script>
const app = new Vue({
el: '#viewer',
data: () => {
return {
solutionText: '[Loading]',
inputText: '[Loading]'
}
},
computed: {
solutionTitle() {
const parts = (document.location + '').split('/')
return parts.reverse()[1]
}
},
async mounted () {
this.solutionText = (await axios.get('./solution.js')).data
this.inputText = (await axios.get('./input.txt')).data
}
})
</script>
</body>
</html>