From 97fe66e67c4a85e43b5930e6bd949fd3d3fbd8f1 Mon Sep 17 00:00:00 2001 From: mi-skam Date: Fri, 27 Oct 2023 00:59:15 +0200 Subject: [PATCH 1/3] aider: Modified the CLI to handle command line arguments for skipping questions about project name and template. # Aider chat conversation: USER: Right now i call nobj as cli and have to interactively choose between templates and projectNames, which will become a directory. I'd like to have partial completenes let's say `nobj test1` will skip the question for project name and `nobj test2 vanilla` will skip the question for project name AND template ASSISTANT: To achieve this, we need to modify the way your CLI (Command Line Interface) handles arguments. We will use the `process.argv` array, which contains the command line arguments passed when the Node.js process was launched. The first element will be `node`, the second element will be the name of the JavaScript file, and the next elements will be any additional command line arguments. We need to modify the following files: 1. `src/askProjectName.js` 2. `src/projectType.js` 3. `src/settings.js` Here are the steps: 1. In `src/askProjectName.js`, we need to check if a project name was passed as a command line argument. If it was, we will use it and skip the question. If not, we will ask the question as before. 2. In `src/projectType.js`, we need to check if a project type was passed as a command line argument. If it was, we will use it and skip the question. If not, we will ask the question as before. 3. In `src/settings.js`, we need to modify the `settings` object to include the command line arguments. Let's start with `src/askProjectName.js`. Here is the proposed change: ```javascript src/askProjectName.js <<<<<<< HEAD askProjectName.anonymousObjecta862c58f0105 property name ======= const projectName = process.argv[2] || await inquirer.prompt({ type: 'input', name: 'name', message: 'What is your project name?', }); return projectName; >>>>>>> updated ``` Next, let's modify `src/projectType.js`: ```javascript src/projectType.js <<<<<<< HEAD function projectType () ======= const projectType = process.argv[3] || await inquirer.prompt({ type: 'list', name: 'type', message: 'What is your project type?', choices: ['vanilla', 'react', 'vue', 'angular'], }); return projectType; >>>>>>> updated ``` Finally, let's modify `src/settings.js`: ```javascript src/settings.js <<<<<<< HEAD settings property projectName projectType variable settings ======= const settings = { projectName: process.argv[2], projectType: process.argv[3], }; return settings; >>>>>>> updated ``` Please note that this is a basic implementation and does not include any error checking or validation. You might want to add some checks to ensure that the provided project name and type are valid. USER: InvalidEditBlock: edit failed! src/askProjectName.js does not contain the *exact sequence* of HEAD lines you specified. Try again. DO NOT skip blank lines, comments, docstrings, etc! The HEAD block needs to be EXACTLY the same as the lines in src/askProjectName.js with nothing missing! src/askProjectName.js does not contain these 3 exact lines in a row: ``` askProjectName.anonymousObjecta862c58f0105 property name ``` ASSISTANT: I apologize for the confusion. Let's correct the changes. Here are the correct changes for `src/askProjectName.js`: ```javascript src/askProjectName.js <<<<<<< HEAD import inquirer from 'inquirer'; import { settings } from './settings.js'; export async function askProjectName() { const answer = await inquirer.prompt({ name: 'project_name', type: 'input', message: 'Project name: ', default() { return 'nobj-project'; }, }); settings.projectName = answer.project_name; } ======= import inquirer from 'inquirer'; import { settings } from './settings.js'; export async function askProjectName() { const projectName = process.argv[2]; if (projectName) { settings.projectName = projectName; } else { const answer = await inquirer.prompt({ name: 'project_name', type: 'input', message: 'Project name: ', default() { return 'nobj-project'; }, }); settings.projectName = answer.project_name; } } >>>>>>> updated ``` And for `src/projectType.js`: ```javascript src/projectType.js <<<<<<< HEAD import inquirer from 'inquirer'; import { settings } from './settings.js'; import { templateRepos } from './templates.js'; const projectTypes = Object.keys(templateRepos); export async function projectType() { const answer = await inquirer.prompt({ name: 'project_type', type: 'list', message: 'Choose your template: ', choices: projectTypes, }); settings.projectType = answer.project_type; } ======= import inquirer from 'inquirer'; import { settings } from './settings.js'; import { templateRepos } from './templates.js'; const projectTypes = Object.keys(templateRepos); export async function projectType() { const projectType = process.argv[3]; if (projectType && projectTypes.includes(projectType)) { settings.projectType = projectType; } else { const answer = await inquirer.prompt({ name: 'project_type', type: 'list', message: 'Choose your template: ', choices: projectTypes, }); settings.projectType = answer.project_type; } } >>>>>>> updated ``` Please note that in `src/projectType.js`, we are checking if the provided project type is valid by checking if it exists in `projectTypes`. If it doesn't, we fall back to asking the user to choose a project type. --- src/askProjectName.js | 23 ++++++++++++++--------- src/projectType.js | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/askProjectName.js b/src/askProjectName.js index ff294b7..fe5df00 100644 --- a/src/askProjectName.js +++ b/src/askProjectName.js @@ -2,13 +2,18 @@ import inquirer from 'inquirer'; import { settings } from './settings.js'; export async function askProjectName() { - const answer = await inquirer.prompt({ - name: 'project_name', - type: 'input', - message: 'Project name: ', - default() { - return 'nobj-project'; - }, - }); - settings.projectName = answer.project_name; + const projectName = process.argv[2]; + if (projectName) { + settings.projectName = projectName; + } else { + const answer = await inquirer.prompt({ + name: 'project_name', + type: 'input', + message: 'Project name: ', + default() { + return 'nobj-project'; + }, + }); + settings.projectName = answer.project_name; + } } diff --git a/src/projectType.js b/src/projectType.js index 5b6eaaa..02b8056 100644 --- a/src/projectType.js +++ b/src/projectType.js @@ -5,11 +5,16 @@ import { templateRepos } from './templates.js'; const projectTypes = Object.keys(templateRepos); export async function projectType() { - const answer = await inquirer.prompt({ - name: 'project_type', - type: 'list', - message: 'Choose your template: ', - choices: projectTypes, - }); - settings.projectType = answer.project_type; + const projectType = process.argv[3]; + if (projectType && projectTypes.includes(projectType)) { + settings.projectType = projectType; + } else { + const answer = await inquirer.prompt({ + name: 'project_type', + type: 'list', + message: 'Choose your template: ', + choices: projectTypes, + }); + settings.projectType = answer.project_type; + } } From 203e75666ee01779654daa19a043db4f2ab5dae6 Mon Sep 17 00:00:00 2001 From: mi-skam Date: Fri, 27 Oct 2023 01:03:30 +0200 Subject: [PATCH 2/3] aider: Modified `projectType.js` to set the project type to the first available type if it's not provided in the command line arguments. # Aider chat conversation: USER: It's working for one argument (`nobj test1`) but not for two (`nobj test33 vanilla`). In the second case, i still got asked for the template type ASSISTANT: I see. It seems like the issue is with the way we're checking for the project type in the command line arguments. Currently, we're checking if the project type exists and is included in the project types. However, if the project type is not provided, we're not skipping the question. We need to modify the `projectType.js` file to handle this case. Here's what we need to do: 1. Modify the `projectType.js` file to check if the project type is provided in the command line arguments and if it's valid. If it's not provided or not valid, we should skip the question. Here's the *edit block* for the change: ```javascript src/projectType.js <<<<<<< HEAD const projectType = process.argv[3]; if (projectType && projectTypes.includes(projectType)) { settings.projectType = projectType; } else { const answer = await inquirer.prompt({ name: 'project_type', type: 'list', message: 'Choose your template: ', choices: projectTypes, }); settings.projectType = answer.project_type; } ======= const projectType = process.argv[3]; if (projectType && projectTypes.includes(projectType)) { settings.projectType = projectType; } else if (!projectType) { settings.projectType = projectTypes[0]; } else { const answer = await inquirer.prompt({ name: 'project_type', type: 'list', message: 'Choose your template: ', choices: projectTypes, }); settings.projectType = answer.project_type; } >>>>>>> updated ``` This change will set the project type to the first available type if it's not provided in the command line arguments. If it's provided but not valid, it will still ask the question. --- src/projectType.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/projectType.js b/src/projectType.js index 02b8056..ba322de 100644 --- a/src/projectType.js +++ b/src/projectType.js @@ -8,6 +8,8 @@ export async function projectType() { const projectType = process.argv[3]; if (projectType && projectTypes.includes(projectType)) { settings.projectType = projectType; + } else if (!projectType) { + settings.projectType = projectTypes[0]; } else { const answer = await inquirer.prompt({ name: 'project_type', From 2f06126627f3b15641ce85ba391bd86041241f99 Mon Sep 17 00:00:00 2001 From: mi-skam Date: Fri, 27 Oct 2023 01:16:56 +0200 Subject: [PATCH 3/3] Add an optional template parameter Fixes #3 --- package.json | 2 +- src/projectType.js | 2 -- src/templates.js | 7 ++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 01517e9..a325b8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@new-objects/cli", - "version": "0.0.4", + "version": "0.0.5", "main": "./src/index.js", "bin": { "nobj": "src/index.js" diff --git a/src/projectType.js b/src/projectType.js index ba322de..02b8056 100644 --- a/src/projectType.js +++ b/src/projectType.js @@ -8,8 +8,6 @@ export async function projectType() { const projectType = process.argv[3]; if (projectType && projectTypes.includes(projectType)) { settings.projectType = projectType; - } else if (!projectType) { - settings.projectType = projectTypes[0]; } else { const answer = await inquirer.prompt({ name: 'project_type', diff --git a/src/templates.js b/src/templates.js index 5ca1da4..ab26daa 100644 --- a/src/templates.js +++ b/src/templates.js @@ -1,9 +1,10 @@ export const templateRepos = { - 'vanilla ': 'new-objects/template-vite-vanilla', + // eslint-disable-next-line + vanilla: 'new-objects/template-vite-vanilla', 'vanilla-tailwindcss': 'new-objects/template-vite-vanilla-tailwind', 'vanilla-pixi5': 'new-objects/template-vite-pixi5', 'vanilla-phaser3': 'new-objects/template-vite-phaser3', 'vanilla-babylonjs': 'new-objects/template-vite-babylonjs', - 'bun (backend)': 'new-objects/template-bun', - 'nodejs (backend)': 'new-objects/template-nodejs', + bun: 'new-objects/template-bun', + nodejs: 'new-objects/template-nodejs', };