Skip to content

Commit

Permalink
feat: basic nypm cli
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 9, 2023
1 parent c32fb32 commit d5656a5
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 12 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand All @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

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

76 changes: 76 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -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);
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"module": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"strict": true
"strict": true,
"resolveJsonModule": true
},
"include": [
"src"
]
"include": ["src"]
}

0 comments on commit d5656a5

Please sign in to comment.