Skip to content

Commit

Permalink
feat: add detect command
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 3, 2024
1 parent 0309498 commit 8fe78d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"citty": "^0.1.6",
"consola": "^3.2.3",
"execa": "^8.0.1",
"pathe": "^1.1.2",
"ufo": "^1.4.0"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/cli.ts
Expand Up @@ -2,6 +2,9 @@
import { defineCommand, runMain, ArgsDef } from "citty";
import { name, version, description } from "../package.json";
import { addDependency, installDependencies, removeDependency } from "./api";
import { detectPackageManager } from "./package-manager";
import { resolve } from "pathe";
import { consola } from "consola";

const operationArgs = {
cwd: {
Expand Down Expand Up @@ -64,6 +67,29 @@ const remove = defineCommand({
},
});

const detect = defineCommand({
meta: {
description: "Detect the current package manager",
},
args: {
cwd: {
type: "string",
description: "Current working directory",
},
},
run: async ({ args }) => {
const cwd = resolve(args.cwd || ".");
const packageManager = await detectPackageManager(cwd);
if (!packageManager) {
consola.error(`Cannot detect package manager in \`${cwd}\``);
return process.exit(1);
}
consola.log(
`Detected package manager in \`${cwd}\`: \`${packageManager.name}@${packageManager.version}\``,
);
},
});

const main = defineCommand({
meta: {
name,
Expand All @@ -75,6 +101,7 @@ const main = defineCommand({
i: install,
add: install,
remove,
detect,
},
});

Expand Down

0 comments on commit 8fe78d1

Please sign in to comment.