Skip to content

Commit

Permalink
feat: new na command
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 1, 2022
1 parent 3a63f07 commit af19dc0
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ if the corresponding node manager is not present, this command will install it g

<br>

### `na` - agent alias

```bash
na

# npm
# yarn
# pnpm
```

```bash
na run foo

# npm run foo
# yarn run foo
# pnpm run foo
```

<br>

### Change Directory

```bash
Expand Down
3 changes: 3 additions & 0 deletions bin/na.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict'
require('../dist/na')
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"nr": "bin/nr.js",
"nu": "bin/nu.js",
"nx": "bin/nx.js",
"na": "bin/na.js",
"nun": "bin/nun.js"
},
"bugs": {
Expand All @@ -38,7 +39,7 @@
"nx": "esno src/nx.ts",
"nun": "esno src/nun.ts",
"dev": "esno src/ni.ts",
"build": "rimraf dist && tsup src/ni.ts src/nci.ts src/nr.ts src/nu.ts src/nx.ts src/nun.ts src/index.ts --format cjs,esm --dts",
"build": "rimraf dist && tsup src/ni.ts src/nci.ts src/nr.ts src/nu.ts src/nx.ts src/nun.ts src/na.ts src/index.ts --format cjs,esm --dts",
"release": "npx bumpp --commit --push --tag",
"lint": "eslint \"**/*.ts\"",
"lint:fix": "npm run lint -- --fix",
Expand Down
4 changes: 4 additions & 0 deletions src/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const npmRun = (agent: string) => (args: string[]) => {

export const AGENTS = {
'npm': {
'agent': 'npm {0}',
'run': npmRun('npm'),
'install': 'npm i {0}',
'frozen': 'npm ci',
Expand All @@ -18,6 +19,7 @@ export const AGENTS = {
'global_uninstall': 'npm uninstall -g {0}',
},
'yarn': {
'agent': 'yarn {0}',
'run': 'yarn run {0}',
'install': 'yarn install {0}',
'frozen': 'yarn install --frozen-lockfile',
Expand All @@ -30,6 +32,7 @@ export const AGENTS = {
'global_uninstall': 'yarn global remove {0}',
},
'yarn@berry': {
'agent': 'yarn {0}',
'run': 'yarn run {0}',
'install': 'yarn install {0}',
'frozen': 'yarn install --immutable',
Expand All @@ -43,6 +46,7 @@ export const AGENTS = {
'global_uninstall': 'npm uninstall -g {0}',
},
'pnpm': {
'agent': 'pnpm {0}',
'run': npmRun('pnpm'),
'install': 'pnpm i {0}',
'frozen': 'pnpm i --frozen-lockfile',
Expand Down
4 changes: 4 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ export const parseNun = <Runner>((agent, args) => {
export const parseNx = <Runner>((agent, args) => {
return getCommand(agent, 'execute', args)
})

export const parseNa = <Runner>((agent, args) => {
return getCommand(agent, 'agent', args)
})
4 changes: 4 additions & 0 deletions src/na.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { parseNa } from './commands'
import { runCli } from './runner'

runCli(parseNa)
15 changes: 15 additions & 0 deletions test/na/npm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from 'vitest'
import { parseNa } from '../../src/commands'

const agent = 'npm'
const _ = (arg: string, expected: string) => () => {
expect(
parseNa(agent, arg.split(' ').filter(Boolean)),
).toBe(
expected,
)
}

test('empty', _('', 'npm'))
test('foo', _('foo', 'npm foo'))
test('run test', _('run test', 'npm run test'))
15 changes: 15 additions & 0 deletions test/na/pnpm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from 'vitest'
import { parseNa } from '../../src/commands'

const agent = 'pnpm'
const _ = (arg: string, expected: string) => () => {
expect(
parseNa(agent, arg.split(' ').filter(Boolean)),
).toBe(
expected,
)
}

test('empty', _('', 'pnpm'))
test('foo', _('foo', 'pnpm foo'))
test('run test', _('run test', 'pnpm run test'))
15 changes: 15 additions & 0 deletions test/na/yarn.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from 'vitest'
import { parseNa } from '../../src/commands'

const agent = 'yarn'
const _ = (arg: string, expected: string) => () => {
expect(
parseNa(agent, arg.split(' ').filter(Boolean)),
).toBe(
expected,
)
}

test('empty', _('', 'yarn'))
test('foo', _('foo', 'yarn foo'))
test('run test', _('run test', 'yarn run test'))

0 comments on commit af19dc0

Please sign in to comment.