Skip to content

Commit

Permalink
feat: adds the remove command type
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzolewis committed May 24, 2024
1 parent 3f267f5 commit 43ee408
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/content/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PackageManagers from '../../components/PackageManagers.astro'
## Features

- Support for various package managers: [npm](https://www.npmjs.com), [yarn](https://yarnpkg.com), [pnpm](https://pnpm.io), [bun](https://bun.sh) & [ni](https://github.com/antfu/ni).
- Support for various types of command: [`add`](/usage/#add), [`create`](/usage/#create), [`exec`](/usage/#exec) & [`run`](/usage/#run).
- Support for various types of command: [`add`](/usage/#add), [`create`](/usage/#create), [`exec`](/usage/#exec), [`run`](/usage/#run) & [`remove`](/usage/#remove).
- Synced tabs between each instance on the same page.
- Customizable output with [extra arguments](/usage/#extra-arguments), [comments](/usage/#comment) & [prefixes](/usage/#prefix).

Expand Down
14 changes: 14 additions & 0 deletions docs/src/content/docs/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ The code above generates the following commands:

<PackageManagers type="run" args="dev" />

### `remove`

The `pkg` prop is used to specify the name of the package to remove.

```mdx title="src/content/docs/example.mdx" 'type="remove"'
import { PackageManagers } from 'starlight-package-managers'

<PackageManagers type="remove" pkg="@astrojs/starlight" />
```

The code above generates the following commands:

<PackageManagers type="remove" pkg="@astrojs/starlight" />

## Extra arguments

You can provide extra arguments to any command using the `args` prop.
Expand Down
7 changes: 6 additions & 1 deletion packages/starlight-package-managers/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@ const commands: Commands = {
devOption: '-D',
exec: 'npx',
run: 'npm run',
remove: 'npm uninstall',
},
yarn: {
add: 'yarn add',
create: 'yarn create',
devOption: '-D',
exec: 'yarn',
run: 'yarn run',
remove: 'yarn remove',
},
pnpm: {
add: 'pnpm add',
create: 'pnpm create',
devOption: '-D',
exec: 'pnpm',
run: 'pnpm run',
remove: 'pnpm remove',
},
bun: {
add: 'bun add',
devOption: '-d',
exec: 'bunx',
run: 'bun run',
remove: 'bun remove',
},
ni: {
add: 'ni',
devOption: '-D',
exec: 'nlx',
run: 'nr',
remove: 'nun',
},
}

Expand Down Expand Up @@ -93,7 +98,7 @@ export function getCommand(
return command
}

export type CommandType = 'add' | 'create' | 'exec' | 'run'
export type CommandType = 'add' | 'create' | 'exec' | 'run' | 'remove'

export interface CommandOptions {
args?: string
Expand Down
10 changes: 10 additions & 0 deletions packages/starlight-package-managers/tests/unit/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ yarn create astro`,
pnpm create astro`,
])
})

test("should generate the 'remove' command", () => {
expect(getCommands('remove', 'astro', {})).toEqual([
'npm uninstall astro',
'yarn remove astro',
'pnpm remove astro',
'bun remove astro',
'nun astro',
])
})
})

describe('exec', () => {
Expand Down

0 comments on commit 43ee408

Please sign in to comment.