From 607fee9934410ec1c1583a2ffff43bde6efb61d3 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Tue, 18 Jul 2023 19:39:17 +0200 Subject: [PATCH] feat: migrate to `unjs/citty` (#284) --- package.json | 3 +-- pnpm-lock.yaml | 13 +++---------- src/cli.ts | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 23f39fa0..3a4fdb2d 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@rollup/plugin-replace": "^5.0.2", "@rollup/pluginutils": "^5.0.2", "chalk": "^5.3.0", + "citty": "^0.1.2", "consola": "^3.2.3", "defu": "^6.1.2", "esbuild": "^0.18.14", @@ -44,7 +45,6 @@ "magic-string": "^0.30.1", "mkdist": "^1.3.0", "mlly": "^1.4.0", - "mri": "^1.2.0", "pathe": "^1.1.1", "pkg-types": "^1.0.3", "pretty-bytes": "^6.1.1", @@ -54,7 +54,6 @@ "untyped": "^1.3.2" }, "devDependencies": { - "@types/mri": "^1.1.1", "@types/node": "^20.4.2", "@vitest/coverage-v8": "^0.33.0", "changelogen": "^0.5.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8278ed07..94fe94db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,6 +22,9 @@ dependencies: chalk: specifier: ^5.3.0 version: 5.3.0 + citty: + specifier: ^0.1.2 + version: 0.1.2 consola: specifier: ^3.2.3 version: 3.2.3 @@ -49,9 +52,6 @@ dependencies: mlly: specifier: ^1.4.0 version: 1.4.0 - mri: - specifier: ^1.2.0 - version: 1.2.0 pathe: specifier: ^1.1.1 version: 1.1.1 @@ -75,9 +75,6 @@ dependencies: version: 1.3.2 devDependencies: - '@types/mri': - specifier: ^1.1.1 - version: 1.1.1 '@types/node': specifier: ^20.4.2 version: 20.4.2 @@ -740,10 +737,6 @@ packages: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} dev: true - /@types/mri@1.1.1: - resolution: {integrity: sha512-nJOuiTlsvmClSr3+a/trTSx4DTuY/VURsWGKSf/eeavh0LRMqdsK60ti0TlwM5iHiGOK3/Ibkxsbr7i9rzGreA==} - dev: true - /@types/node@20.4.2: resolution: {integrity: sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==} dev: true diff --git a/src/cli.ts b/src/cli.ts index cab1a232..233e36dc 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,18 +1,33 @@ #!/usr/bin/env node +import { defineCommand, runMain } from "citty"; import { resolve } from "pathe"; -import mri from "mri"; +import { name, version, description } from "../package.json"; import { build } from "./build"; -async function main() { - const args = mri(process.argv.splice(2)); - const rootDir = resolve(process.cwd(), args._[0] || "."); - await build(rootDir, args.stub).catch((error) => { - console.error(`Error building ${rootDir}: ${error}`); - throw error; - }); -} - -main().catch((error) => { - console.error(error); - process.exit(1); +const main = defineCommand({ + meta: { + name, + version, + description, + }, + args: { + dir: { + type: "positional", + description: "The directory to build", + required: false, + }, + stub: { + type: "boolean", + description: "Stub build", + }, + }, + async run({ args }) { + const rootDir = resolve(process.cwd(), args.dir || "."); + await build(rootDir, args.stub).catch((error) => { + console.error(`Error building ${rootDir}: ${error}`); + throw error; + }); + }, }); + +runMain(main);