From 566c3641f260db2a699956babdd92e3b87349cc9 Mon Sep 17 00:00:00 2001 From: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com> Date: Sun, 4 Aug 2024 13:58:42 +0530 Subject: [PATCH] feat: switched from yargs-parser to commander --- package.json | 4 +-- src/hooks/dependencies.ts | 2 +- src/index.ts | 56 ++++++++++++++++++++++++++++++++------- yarn.lock | 10 +++---- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 0b37dbd..c970f5a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@types/node": "^18.11.18", "@types/yargs-parser": "^21.0.0", "chalk": "^5.3.0", + "commander": "^12.1.0", "esbuild": "^0.16.17", "eslint": "^8.55.0", "execa": "^8.0.1", @@ -43,7 +44,6 @@ "prettier": "^3.3.3", "tsx": "^4.7.1", "typescript": "^5.3.3", - "vitest": "^0.34.6", - "yargs-parser": "^21.1.1" + "vitest": "^0.34.6" } } diff --git a/src/hooks/dependencies.ts b/src/hooks/dependencies.ts index d2cd719..be411be 100644 --- a/src/hooks/dependencies.ts +++ b/src/hooks/dependencies.ts @@ -16,7 +16,7 @@ const knownPackageManagers: { [key: string]: string } = { yarn: 'yarn', } -const knownPackageManagerNames = Object.keys(knownPackageManagers) +export const knownPackageManagerNames = Object.keys(knownPackageManagers) const currentPackageManager = getCurrentPackageManager() // Deno and Netlify need no dependency installation step diff --git a/src/index.ts b/src/index.ts index 951643e..6a1aaeb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,13 +4,16 @@ import confirm from '@inquirer/confirm' import input from '@inquirer/input' import select from '@inquirer/select' import chalk from 'chalk' +import { Option, program, type Command } from 'commander' import { downloadTemplate } from 'giget' import { createSpinner } from 'nanospinner' -import yargsParser from 'yargs-parser' import { version } from '../package.json' import { projectDependenciesHook } from './hook' import { afterCreateHook } from './hooks/after-create' -import { registerInstallationHook } from './hooks/dependencies' +import { + knownPackageManagerNames, + registerInstallationHook, +} from './hooks/dependencies' const directoryName = 'templates' const config = { @@ -46,16 +49,49 @@ function mkdirp(dir: string) { } } -async function main() { - console.log(chalk.gray(`create-hono version ${version}`)) +program + .name('create-hono') + .version(version) + .arguments('[target]') + .addOption( + new Option('-y, --install', 'Install dependencies').argParser(Boolean), + ) + .addOption( + new Option('-p, --pm ', 'Package manager to use').choices( + knownPackageManagerNames, + ), + ) + .addOption( + new Option('-t, --template