Skip to content
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
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: CI
on:
push:
branches:
- master
- main

pull_request:
branches:
- master
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -22,4 +22,6 @@ jobs:
node-version: 18.x

- run: npm install
- run: npm run lint && npm run build
- run: npm run lint && npm run lint-es
- run: npm test
- run: npm run build
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</p>

<p align="center">
Run script auto-detect node_module manager npm, pnpm, yarn. bun
Run script auto-detect package manager: npm, yarn, pnpm, bun, upm
</p>

<p align="center">
Expand All @@ -21,35 +21,81 @@
npm install -g run-script-cli
```

## 🔍 Detection

The package manager is detected from the `packageManager` field in `package.json`, then from lockfiles (`upm.lock`, `bun.lock(b)`, `pnpm-lock.yaml`, `yarn.lock`, `package-lock.json`), searching up from the current directory. If nothing is found you'll be asked to choose one.

## 🚀 Commands

- Run

```bash
# Run script with select
# Select a script to run (type to filter by name or description)
nr

# Run script a specific script
# Run a specific script
nr dev

# Pass extra args to the script (`--` is added automatically for npm)
nr dev --port 3000

# Rerun the last script of this project
nr -

# Monorepo: select a workspace package, then a script
nr -w
nr -w build
```

- Install

```bash
# Install script
# Install dependencies
ni

# Install a package
ni react
ni -D vitest
```

- Clean install (for CI)

```bash
# npm ci / pnpm install --frozen-lockfile / ...
nci
```

- Uninstall

```bash
# Uninstall script
nu react
```

- Execute a package without installing it

```bash
# npx / pnpm dlx / bunx / upx
nlx cowsay hello
```

| Command | npm | yarn | pnpm | bun | upm |
| ------------ | --------------------- | -------------------------------- | -------------------------------- | ------------------------------- | ------------------------------- |
| `nr dev` | `npm run dev` | `yarn run dev` | `pnpm run dev` | `bun run dev` | `upm run dev` |
| `ni` | `npm install` | `yarn install` | `pnpm install` | `bun install` | `upm install` |
| `ni react` | `npm install react` | `yarn add react` | `pnpm add react` | `bun add react` | `upm add react` |
| `nci` | `npm ci` | `yarn install --frozen-lockfile` | `pnpm install --frozen-lockfile` | `bun install --frozen-lockfile` | `upm install --frozen-lockfile` |
| `nu react` | `npm uninstall react` | `yarn remove react` | `pnpm remove react` | `bun remove react` | `upm remove react` |
| `nlx cowsay` | `npx cowsay` | `npx cowsay` | `pnpm dlx cowsay` | `bunx cowsay` | `upx cowsay` |

## 🧩 API

```ts
import { detectAgent, getCommand } from 'run-script-cli';

const agent = detectAgent(process.cwd()); // 'npm' | 'yarn' | 'pnpm' | 'bun' | 'upm' | undefined
getCommand('pnpm', 'add', ['react']); // ['pnpm', 'add', 'react']
```

## Preview

<p align='center'>
Expand Down
3 changes: 3 additions & 0 deletions bin/nci.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict';
import('../dist/nci.mjs');
3 changes: 3 additions & 0 deletions bin/nlx.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict';
import('../dist/nlx.mjs');
2 changes: 1 addition & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineBuildConfig } from 'unbuild';

export default defineBuildConfig({
entries: ['src/nr', 'src/ni', 'src/nu'],
entries: ['src/index', 'src/nr', 'src/ni', 'src/nu', 'src/nlx', 'src/nci'],
clean: true,
declaration: true,

Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"bin": {
"nr": "./bin/nr.mjs",
"ni": "./bin/ni.mjs",
"nu": "./bin/nu.mjs"
"nu": "./bin/nu.mjs",
"nlx": "./bin/nlx.mjs",
"nci": "./bin/nci.mjs"
},
"files": [
"bin",
Expand All @@ -33,16 +35,16 @@
"lint": "tsc --noEmit",
"lint-es": "eslint --ext .ts,.tsx src --color",
"start": "esno src/nr.ts",
"test": "vitest",
"test": "vitest run",
"verify-commit": "verify-commit-msg",
"prepare": "git-scm-hooks",
"changelog": "npx changeloggithub@latest --all true && git add CHANGELOG.md && git commit -m 'chore: update CHANGELOG.md'",
"release": "bumpp -r && npm run changelog"
},
"author": "hunghg255",
"devDependencies": {
"@clack/prompts": "1.0.0",
"@hunghg255/eslint-config-ts": "^0.0.8",
"@skarab/detect-package-manager": "^1.0.0",
"@types/node": "^18.19.3",
"bumpp": "^9.2.1",
"esno": "^0.16.3",
Expand All @@ -53,7 +55,6 @@
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"unprompts": "^1.0.11",
"verify-commit-msg": "^0.0.10",
"vitest": "^0.34.6"
},
Expand All @@ -65,12 +66,16 @@
"npm",
"yarn",
"pnpm",
"bun",
"upm",
"run",
"script",
"cli",
"nr",
"ni",
"nu"
"nu",
"nlx",
"nci"
],
"homepage": "https://github.com/hunghg255/run-script-cli",
"repository": {
Expand Down
Loading
Loading