Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic nypm cli #95

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4",
"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
20 changes: 10 additions & 10 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"]
}