From 10f93fa3064e27991d2c9f1b9e1bcf22e150c703 Mon Sep 17 00:00:00 2001 From: Teofanis Papadopulos Date: Mon, 5 Dec 2022 22:10:13 +0000 Subject: [PATCH 1/5] add vscodeSettings Prompt during setup --- src/prompts/initPrompt.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/prompts/initPrompt.ts b/src/prompts/initPrompt.ts index 3340ce7..0fabbff 100644 --- a/src/prompts/initPrompt.ts +++ b/src/prompts/initPrompt.ts @@ -80,6 +80,14 @@ const initPrompt = () => { ], initial: 0, }, + { + type: "toggle", + name: "vscodeSettings", + message: "(Optional) Would you like to include the default launch.json configuration ? ", + initial: false, + active: "yes", + inactive: "no", + } ], { onCancel }, ) From 1589e8ae106f3434685cd96c6e0ce99bc281e8f6 Mon Sep 17 00:00:00 2001 From: Teofanis Papadopulos Date: Mon, 5 Dec 2022 22:10:35 +0000 Subject: [PATCH 2/5] extend the Setup type to include the vscode Settings --- src/types/common.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/common.ts b/src/types/common.ts index da41392..5bbfd12 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -6,6 +6,7 @@ export type Setup = { author: string semicolons: boolean strict: boolean + vscodeSettings: boolean } type DayConfig = { From 7e3872e0fa91f21aa0cd48c80cba229c2fd74b50 Mon Sep 17 00:00:00 2001 From: Teofanis Papadopulos Date: Mon, 5 Dec 2022 22:20:06 +0000 Subject: [PATCH 3/5] create a launchJSON script --- src/configs/launchJSON.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/configs/launchJSON.ts diff --git a/src/configs/launchJSON.ts b/src/configs/launchJSON.ts new file mode 100644 index 0000000..6a039e2 --- /dev/null +++ b/src/configs/launchJSON.ts @@ -0,0 +1,28 @@ +import type { Setup } from "../types/common" + +const launchJSON = ({ packageManager }: Setup) => { + return { + "configurations": [ + { + "name": "Advent of Code Runner: Start", + "type": "node", + "request": "launch", + "trace": "true", + "runtimeExecutable": packageManager, + "runtimeArgs": ["start", "${input:day}"], + "console": "integratedTerminal" + } + ], + "inputs": [ + { + "id": "day", + "type": "promptString", + "description": "Enter the day number", + "default": "1" + } + ] + } + +} + +export default launchJSON From 216f78e497748c0b6d112eefe72ee97d7fd14f29 Mon Sep 17 00:00:00 2001 From: Teofanis Papadopulos Date: Mon, 5 Dec 2022 22:20:22 +0000 Subject: [PATCH 4/5] call launchJSON during the init --- src/actions/init.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/actions/init.ts b/src/actions/init.ts index 508a9b6..83c2d3a 100644 --- a/src/actions/init.ts +++ b/src/actions/init.ts @@ -9,6 +9,7 @@ import copy from "../io/copy.js" import packageJSON from "../configs/packageJSON.js" import tsconfigJSON from "../configs/tsconfigJSON.js" import prettierJSON from "../configs/prettierJSON.js" +import launchJSON from "../configs/launchJSON.js" import gitignoreTXT from "../configs/gitignoreTXT.js" import prettierignoreTXT from "../configs/prettierignoreTXT.js" import runnerJSON from "../configs/runnerJSON.js" @@ -69,6 +70,12 @@ const init = async () => { save(dir, "tsconfig.json", tsconfigJSON(setup)) } + if(setup.vscodeSettings) { + const vscodeSettingsDir = path.join(dir, ".vscode"); + fs.mkdirSync(vscodeSettingsDir, { recursive: true }) + save(vscodeSettingsDir, "launch.json", launchJSON(setup)) + } + const templatesDir = path.resolve( dirname, "..", From a4d8489fbc642de748dc6237a9fcfcdc181493f0 Mon Sep 17 00:00:00 2001 From: Teofanis Papadopulos Date: Mon, 5 Dec 2022 22:22:55 +0000 Subject: [PATCH 5/5] style: run `format` script --- src/actions/dev.ts | 2 -- src/actions/init.ts | 4 ++-- src/cli.ts | 2 +- src/configs/launchJSON.ts | 33 ++++++++++++++++----------------- src/prompts/initPrompt.ts | 5 +++-- src/version.ts | 2 +- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/actions/dev.ts b/src/actions/dev.ts index 91e8741..4afaeea 100644 --- a/src/actions/dev.ts +++ b/src/actions/dev.ts @@ -67,8 +67,6 @@ const showInfo = () => { console.log() } - - const send = async (config: Config, dayNum: number, part: 1 | 2) => { console.log(`\nPart ${part}:`) const dayData = diff --git a/src/actions/init.ts b/src/actions/init.ts index 83c2d3a..7247b15 100644 --- a/src/actions/init.ts +++ b/src/actions/init.ts @@ -70,8 +70,8 @@ const init = async () => { save(dir, "tsconfig.json", tsconfigJSON(setup)) } - if(setup.vscodeSettings) { - const vscodeSettingsDir = path.join(dir, ".vscode"); + if (setup.vscodeSettings) { + const vscodeSettingsDir = path.join(dir, ".vscode") fs.mkdirSync(vscodeSettingsDir, { recursive: true }) save(vscodeSettingsDir, "launch.json", launchJSON(setup)) } diff --git a/src/cli.ts b/src/cli.ts index e17e8ed..b3f0235 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -38,7 +38,7 @@ switch (String(command || "").toLowerCase()) { } case "update:readme": { updateReadme() - break; + break } default: { console.log("Command not supported") diff --git a/src/configs/launchJSON.ts b/src/configs/launchJSON.ts index 6a039e2..31a6367 100644 --- a/src/configs/launchJSON.ts +++ b/src/configs/launchJSON.ts @@ -2,27 +2,26 @@ import type { Setup } from "../types/common" const launchJSON = ({ packageManager }: Setup) => { return { - "configurations": [ + configurations: [ { - "name": "Advent of Code Runner: Start", - "type": "node", - "request": "launch", - "trace": "true", - "runtimeExecutable": packageManager, - "runtimeArgs": ["start", "${input:day}"], - "console": "integratedTerminal" - } + name: "Advent of Code Runner: Start", + type: "node", + request: "launch", + trace: "true", + runtimeExecutable: packageManager, + runtimeArgs: ["start", "${input:day}"], + console: "integratedTerminal", + }, ], - "inputs": [ + inputs: [ { - "id": "day", - "type": "promptString", - "description": "Enter the day number", - "default": "1" - } - ] + id: "day", + type: "promptString", + description: "Enter the day number", + default: "1", + }, + ], } - } export default launchJSON diff --git a/src/prompts/initPrompt.ts b/src/prompts/initPrompt.ts index 0fabbff..59ae0fa 100644 --- a/src/prompts/initPrompt.ts +++ b/src/prompts/initPrompt.ts @@ -83,11 +83,12 @@ const initPrompt = () => { { type: "toggle", name: "vscodeSettings", - message: "(Optional) Would you like to include the default launch.json configuration ? ", + message: + "(Optional) Would you like to include the default launch.json configuration ? ", initial: false, active: "yes", inactive: "no", - } + }, ], { onCancel }, ) diff --git a/src/version.ts b/src/version.ts index 440d85f..9e533e9 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,2 +1,2 @@ /* This file is auto-generated - do not modify */ -export default "1.9.5" \ No newline at end of file +export default "1.9.5"