diff --git a/README.md b/README.md index 815be21..094d1d3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,23 @@ nypm, detects package manager type and version and converts command into package ## CLI Usage -[TBA] +**Install dependencies:** + +```sh +npx nypm@latest i +``` + +**Add a dependency:** + +```sh +npx nypm@latest add defu +``` + +**Remove a dependency:** + +```sh +npx nypm@latest remove defu +``` ## API Usage diff --git a/package.json b/package.json index 0b20c9b..e03651a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,9 @@ "require": "./dist/index.cjs" } }, + "bin": { + "nypm": "./dist/cli.mjs" + }, "main": "./dist/index.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -25,12 +28,15 @@ "lint": "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test", "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test", "prepack": "unbuild", + "nypm": "jiti src/cli.ts", "release": "pnpm test && pnpm build && changelogen --release --push && pnpm publish", "test": "pnpm lint && pnpm test:types && vitest run --coverage", "test:types": "tsc --noEmit" }, "dependencies": { + "citty": "^0.1.3", "execa": "^8.0.1", + "pathe": "^1.1.1", "ufo": "^1.3.0" }, "devDependencies": { @@ -40,7 +46,6 @@ "eslint": "^8.49.0", "eslint-config-unjs": "^0.2.1", "jiti": "^1.20.0", - "pathe": "^1.1.1", "prettier": "^3.0.3", "std-env": "^3.4.3", "typescript": "^5.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 77af5f5..5ad26e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,9 +5,15 @@ settings: excludeLinksFromLockfile: false dependencies: + citty: + specifier: ^0.1.3 + version: 0.1.3 execa: specifier: ^8.0.1 version: 8.0.1 + pathe: + specifier: ^1.1.1 + version: 1.1.1 ufo: specifier: ^1.3.0 version: 1.3.0 @@ -31,9 +37,6 @@ devDependencies: jiti: specifier: ^1.20.0 version: 1.20.0 - pathe: - specifier: ^1.1.1 - version: 1.1.1 prettier: specifier: ^3.0.3 version: 3.0.3 @@ -1459,7 +1462,6 @@ packages: resolution: {integrity: sha512-tb6zTEb2BDSrzFedqFYFUKUuKNaxVJWCm7o02K4kADGkBDyyiz7D40rDMpguczdZyAN3aetd5fhpB01HkreNyg==} dependencies: consola: 3.2.3 - dev: true /clean-regexp@1.0.0: resolution: {integrity: sha512-GfisEZEJvzKrmGWkvfhgzcz/BllN1USeqD2V6tg14OAOgaCD2Z/PUEuxnAZ/nPvmaHRG7a8y77p1T/IRQ4D1Hw==} @@ -1506,7 +1508,6 @@ packages: /consola@3.2.3: resolution: {integrity: sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==} engines: {node: ^14.18.0 || >=16.10.0} - dev: true /convert-gitmoji@0.1.3: resolution: {integrity: sha512-t5yxPyI8h8KPvRwrS/sRrfIpT2gJbmBAY0TFokyUBy3PM44RuFRpZwHdACz+GTSPLRLo3s4qsscOMLjHiXBwzw==} @@ -3327,7 +3328,6 @@ packages: /pathe@1.1.1: resolution: {integrity: sha512-d+RQGp0MAYTIaDBIMmOfMwz3E+LOZnxx1HZd5R18mmCZY0QBlK0LDZfPc8FW8Ed2DlvsuE6PRjroDY+wg4+j/Q==} - dev: true /pathval@1.1.1: resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} diff --git a/src/cli.ts b/src/cli.ts new file mode 100755 index 0000000..b064541 --- /dev/null +++ b/src/cli.ts @@ -0,0 +1,76 @@ +#!/usr/bin/env node +import { defineCommand, runMain, ArgsDef } from "citty"; +import pkg from "../package.json"; +import { addDependency, installDependencies, removeDependency } from "./api"; + +const operationArgs = { + cwd: { + type: "string", + description: "Current working directory", + }, + workspace: { + type: "boolean", + description: "Add to workspace", + }, + silent: { + type: "boolean", + description: "Run in silent mode", + }, +} as const satisfies ArgsDef; + +const install = defineCommand({ + meta: { + description: "Install dependencies", + }, + args: { + ...operationArgs, + name: { + type: "positional", + description: "Dependency name", + required: false, + }, + dev: { + type: "boolean", + alias: "D", + description: "Add as dev dependency", + }, + }, + run: async ({ args }) => { + await (args.name + ? addDependency(args.name, args) + : installDependencies(args)); + }, +}); + +const remove = defineCommand({ + meta: { + description: "Remove dependencies", + }, + args: { + name: { + type: "positional", + description: "Dependency name", + required: true, + }, + ...operationArgs, + }, + run: async ({ args }) => { + await removeDependency(args.name, args); + }, +}); + +const main = defineCommand({ + meta: { + name: pkg.name, + version: pkg.version, + description: pkg.description, + }, + subCommands: { + install, + i: install, + add: install, + remove, + }, +}); + +runMain(main); diff --git a/tsconfig.json b/tsconfig.json index d079baa..df2134b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,9 +4,8 @@ "module": "ESNext", "moduleResolution": "Node", "esModuleInterop": true, - "strict": true + "strict": true, + "resolveJsonModule": true }, - "include": [ - "src" - ] + "include": ["src"] }