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..e7a6a31 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('-i, --install', 'Install dependencies').argParser(Boolean), + ) + .addOption( + new Option('-p, --pm ', 'Package manager to use').choices( + knownPackageManagerNames, + ), + ) + .addOption( + new Option('-t, --template