starlight-package-managers 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,37 @@
1
1
  ---
2
2
  import { Code, Tabs, TabItem } from '@astrojs/starlight/components'
3
+ import type { ComponentProps } from 'astro/types'
3
4
 
4
- import { type CommandType, getCommand, type CommandOptions, getSupportedPkgManagers, type PackageManager } from './pkg'
5
+ import {
6
+ type CommandOptions,
7
+ type CommandType,
8
+ getCommand,
9
+ getSupportedPkgManagers,
10
+ type PackageManager,
11
+ getIcon,
12
+ } from './pkg'
5
13
 
6
14
  export type PackageManagersProps = Props
7
15
 
8
16
  interface Props extends CommandOptions {
9
17
  frame?: 'none' | 'terminal'
18
+ icons?: boolean
10
19
  pkg?: string | undefined
11
20
  pkgManagers?: PackageManager[]
12
21
  title?: string | undefined
13
22
  type?: CommandType
14
23
  }
15
24
 
16
- const { frame = 'terminal', pkg, pkgManagers, title = undefined, type = 'add', ...options } = Astro.props
25
+ const { frame = 'terminal', icons = true, pkg, pkgManagers, title = undefined, type = 'add', ...options } = Astro.props
17
26
  const singlePkgManager = pkgManagers?.length === 1 ? pkgManagers[0] : undefined
18
27
  const ecFrame = frame === 'terminal' ? 'terminal' : 'code'
28
+
29
+ function getTabItemProps(pkgManager: PackageManager) {
30
+ const props: ComponentProps<typeof TabItem> = { label: pkgManager }
31
+ const icon = getIcon(pkgManager) as ComponentProps<typeof TabItem>['icon']
32
+ if (icons && icon) props.icon = icon
33
+ return props
34
+ }
19
35
  ---
20
36
 
21
37
  {
@@ -25,7 +41,7 @@ const ecFrame = frame === 'terminal' ? 'terminal' : 'code'
25
41
  <starlight-package-managers>
26
42
  <Tabs>
27
43
  {getSupportedPkgManagers(type, pkgManagers).map((pkgManager) => (
28
- <TabItem label={pkgManager}>
44
+ <TabItem {...getTabItemProps(pkgManager)}>
29
45
  <Code code={getCommand(pkgManager, type, pkg, options)} lang="sh" {title} frame={ecFrame} />
30
46
  </TabItem>
31
47
  ))}
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
  <h1>starlight-package-managers 🗃</h1>
3
3
  <p>Quickly display npm related commands for multiple package managers in your Starlight documentation site.</p>
4
4
  <p>
5
- <a href="https://github.com/HiDeoo/vercel-env-push/assets/494699/12a27480-f3ff-470f-a108-e1bf73cd9146" title="Demo of starlight-package-managers">
6
- <img alt="Demo of starlight-package-managers" src="https://github.com/HiDeoo/vercel-env-push/assets/494699/12a27480-f3ff-470f-a108-e1bf73cd9146" width="520" />
5
+ <a href="https://github.com/HiDeoo/starlight-package-managers/assets/494699/5666eb82-4e80-4ce9-ac07-3f711e51062c" title="Demo of starlight-package-managers">
6
+ <img alt="Demo of starlight-package-managers" src="https://github.com/HiDeoo/starlight-package-managers/assets/494699/5666eb82-4e80-4ce9-ac07-3f711e51062c" width="520" />
7
7
  </a>
8
8
  </p>
9
9
  </div>
@@ -20,7 +20,7 @@
20
20
 
21
21
  ## Getting Started
22
22
 
23
- Want to get started immediately? Check out the [getting started guide](https://starlight-package-managers.vercel.app/guides/getting-started/) or a [live demo](https://starlight-package-managers.vercel.app/demo/).
23
+ Want to get started immediately? Check out the [getting started guide](https://starlight-package-managers.vercel.app/getting-started/) or a [live demo](https://starlight-package-managers.vercel.app/demo/).
24
24
 
25
25
  ## Description
26
26
 
@@ -61,9 +61,9 @@ By this one:
61
61
  ## Features
62
62
 
63
63
  - 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).
64
- - Support for various types of command: [`add`](https://starlight-package-managers.vercel.app/guides/usage/#add), [`create`](https://starlight-package-managers.vercel.app/guides/usage/#create), [`exec`](https://starlight-package-managers.vercel.app/guides/usage/#exec) & [`run`](https://starlight-package-managers.vercel.app/guides/usage/#run).
64
+ - Support for various types of command: [`add`](https://starlight-package-managers.vercel.app/usage/#add), [`create`](https://starlight-package-managers.vercel.app/usage/#create), [`exec`](https://starlight-package-managers.vercel.app/usage/#exec) & [`run`](https://starlight-package-managers.vercel.app/usage/#run).
65
65
  - Synced tabs between each instance on the same page.
66
- - Customizable output with [extra arguments](https://starlight-package-managers.vercel.app/guides/usage/#extra-arguments), [comments](https://starlight-package-managers.vercel.app/guides/usage/#comment) & [prefixes](https://starlight-package-managers.vercel.app/guides/usage/#prefix).
66
+ - Customizable output with [extra arguments](https://starlight-package-managers.vercel.app/usage/#extra-arguments), [comments](https://starlight-package-managers.vercel.app/usage/#comment) & [prefixes](https://starlight-package-managers.vercel.app/usage/#prefix).
67
67
 
68
68
  ## Documentation
69
69
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-package-managers",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "description": "Quickly display npm related commands for multiple package managers in your Starlight documentation site.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -10,14 +10,14 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "devDependencies": {
13
- "@astrojs/starlight": "0.17.0",
13
+ "@astrojs/starlight": "0.21.0",
14
14
  "@playwright/test": "1.36.2",
15
- "astro": "4.2.6",
15
+ "astro": "4.3.7",
16
16
  "vitest": "0.33.0"
17
17
  },
18
18
  "peerDependencies": {
19
- "@astrojs/starlight": ">=0.17.0",
20
- "astro": ">=4.0.0"
19
+ "@astrojs/starlight": ">=0.21.0",
20
+ "astro": ">=4.2.7"
21
21
  },
22
22
  "engines": {
23
23
  "node": ">=18.14.1"
package/pkg.ts CHANGED
@@ -38,10 +38,22 @@ const commands: Commands = {
38
38
  },
39
39
  }
40
40
 
41
+ const icons: Record<PackageManager, string | undefined> = {
42
+ npm: 'seti:npm',
43
+ yarn: 'seti:yarn',
44
+ pnpm: 'pnpm',
45
+ bun: 'bun',
46
+ ni: undefined,
47
+ }
48
+
41
49
  export function getSupportedPkgManagers(type: CommandType, userPkgManagers: PackageManager[] | undefined) {
42
50
  return (userPkgManagers ?? defaultPkgManagers).filter((pkgManager) => commands[pkgManager][type] !== undefined)
43
51
  }
44
52
 
53
+ export function getIcon(pkgManager: PackageManager) {
54
+ return icons[pkgManager]
55
+ }
56
+
45
57
  export function getCommand(
46
58
  pkgManager: PackageManager,
47
59
  type: CommandType,