From 66aed68fef8173282f943bf908e2c4c24f2257e0 Mon Sep 17 00:00:00 2001 From: hank Date: Mon, 10 Dec 2018 00:17:50 +0100 Subject: [PATCH 1/2] Add CLI - WIP --- bin/advent.js | 4 ++++ package.json | 4 ++++ src/cli.js | 41 +++++++++++++++++++++++++++++++++++++++++ src/init.js | 5 +++++ src/templates/day.js | 0 yarn.lock | 5 +++++ 6 files changed, 59 insertions(+) create mode 100755 bin/advent.js create mode 100644 src/cli.js create mode 100644 src/init.js create mode 100644 src/templates/day.js diff --git a/bin/advent.js b/bin/advent.js new file mode 100755 index 0000000..99f2a52 --- /dev/null +++ b/bin/advent.js @@ -0,0 +1,4 @@ +#!/usr/bin/env node +const cli = require('../src/cli'); + +cli(); diff --git a/package.json b/package.json index eb4a2f6..ce39ffc 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "lint": "eslint .", "test": "jest" }, + "bin": { + "advent": "./bin/advent.js" + }, "main": "index.js", "author": "Hank", "license": "MIT", @@ -16,6 +19,7 @@ "jest": "^23.6.0" }, "dependencies": { + "commander": "^2.19.0", "dotenv": "^6.1.0", "find-config": "^1.0.0", "node-fetch": "^2.3.0", diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 0000000..e82cd1b --- /dev/null +++ b/src/cli.js @@ -0,0 +1,41 @@ +const path = require('path'); +const { Command } = require('commander'); + +const init = require('./init'); + + +const main = (args = process.argv, program = new Command()) => { + const defaultNameTemplate = 'solve.js'; + const defaultTemplateFile = path.resolve(__dirname, 'templates', 'day.js'); + + program.on( + '--help', () => { + console.log('hej'); + }, + ); + + let action; + + program + .command('init ') + .description('Initalize a given day') + .option( + '-n, --name-template [template', + 'The template filename', + defaultNameTemplate, + ) + .option( + '-t, --template-file [filepath]', + 'The path to the template file', + defaultTemplateFile, + ) + .action((day, command) => { + action = init(); + }); + + program.parse(args); + + return action; +}; + +module.exports = main; diff --git a/src/init.js b/src/init.js new file mode 100644 index 0000000..254989a --- /dev/null +++ b/src/init.js @@ -0,0 +1,5 @@ +const init = config => { + return Promise.all([]); +}; + +module.exports = init; diff --git a/src/templates/day.js b/src/templates/day.js new file mode 100644 index 0000000..e69de29 diff --git a/yarn.lock b/yarn.lock index f0e3a84..0577307 100644 --- a/yarn.lock +++ b/yarn.lock @@ -728,6 +728,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" +commander@^2.19.0: + version "2.19.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" + integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== + commander@~2.17.1: version "2.17.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" From c87c96594b7bf12f77b0706ee4c929f0cba91588 Mon Sep 17 00:00:00 2001 From: hank Date: Sat, 16 Nov 2019 14:20:23 +0100 Subject: [PATCH 2/2] eslinting --- 2018/13/solve.js | 3 ++- 2018/16/opcodes.js | 2 ++ src/cli.js | 3 ++- src/init.js | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/2018/13/solve.js b/2018/13/solve.js index f3fb2c4..0dca0c0 100755 --- a/2018/13/solve.js +++ b/2018/13/solve.js @@ -6,11 +6,12 @@ const solve1 = () => { getRows() .then(data => console.log(findCollisionLocation(data))); }; +// eslint-disable-next-line no-unused-vars const solve2 = () => { getRows() .then(data => console.log((data))); }; solve1(); -//solve2(); +// solve2(); // 44,88 diff --git a/2018/16/opcodes.js b/2018/16/opcodes.js index c3b4bd3..7ce2f4f 100644 --- a/2018/16/opcodes.js +++ b/2018/16/opcodes.js @@ -79,6 +79,7 @@ const getOperations = (input) => { const registryBefore = getRegistryBefore(before); const [instruction, a, b, c] = getInstructions(inst); const registryAfter = getRegistryAfter(after); + // eslint-disable-next-line no-loop-func Object.entries(ops).forEach(([name, op]) => { const registry = applyOp(op, registryBefore, a, b, c); if (isEqual(registry, registryAfter)) { @@ -94,6 +95,7 @@ const getOperations = (input) => { const opCodes = {}; while (foundInstructions < 16) { + // eslint-disable-next-line no-loop-func Object.entries(opCandidates).forEach(([name, candidates]) => { if (candidates.length === 1) { const foundNum = candidates[0]; diff --git a/src/cli.js b/src/cli.js index e82cd1b..ad18bd1 100644 --- a/src/cli.js +++ b/src/cli.js @@ -18,7 +18,7 @@ const main = (args = process.argv, program = new Command()) => { program .command('init ') - .description('Initalize a given day') + .description('Initialize a given day') .option( '-n, --name-template [template', 'The template filename', @@ -30,6 +30,7 @@ const main = (args = process.argv, program = new Command()) => { defaultTemplateFile, ) .action((day, command) => { + console.log(day, command); action = init(); }); diff --git a/src/init.js b/src/init.js index 254989a..177709b 100644 --- a/src/init.js +++ b/src/init.js @@ -1,4 +1,5 @@ -const init = config => { +const init = (config) => { + console.log(config); return Promise.all([]); }; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy