--- /** * Package-manager command tabs (pnpm first), synced site-wide. * * Each prop adds one line, rendered in prop order below: * * ```mdx * * * * * * ``` * * `script` is a whole shell block, comments and other commands included, with * `{run}` standing for the manager's runner for an installed binary (`pnpm`, * `bun`, `npx`, `yarn`) and `{dlx}` for downloading and running a package * (`pnpx`, `bunx`, `npx`, `yarn dlx`). * Use it when a block mixes package commands with `curl`, `git` or output. */ import { Code, TabItem, Tabs } from "@astrojs/starlight/components"; interface Props { /** Initialize a package.json. */ init?: boolean; /** With `init`: create and enter this directory first. */ dir?: string; /** Dependencies to install. */ add?: string; /** Dev dependencies to install. */ dev?: string; /** Dependencies to uninstall. */ remove?: string; /** A package binary and its arguments, e.g. `alchemy deploy`. */ run?: string; /** A shell block where `{run}` is replaced by each manager's runner. */ script?: string; } const { init, dir, add, dev, remove, run, script } = Astro.props; const managers = [ { name: "pnpm", icon: "pnpm", init: "pnpm init", add: "pnpm add", dev: "pnpm add -D", remove: "pnpm remove", run: "pnpm", dlx: "pnpx", }, { name: "bun", icon: "bun", init: "bun init -y", add: "bun add", dev: "bun add -d", remove: "bun remove", run: "bun", dlx: "bunx", }, { name: "npm", icon: "npm", init: "npm init -y", add: "npm install", dev: "npm install -D", remove: "npm uninstall", run: "npx", dlx: "npx", }, { name: "yarn", icon: "seti:yarn", init: "yarn init -y", add: "yarn add", dev: "yarn add -D", remove: "yarn remove", run: "yarn", dlx: "yarn dlx", }, ] as const; const commands = (pm: (typeof managers)[number]) => [ init && (dir ? `mkdir ${dir} && cd ${dir} && ${pm.init}` : pm.init), add && `${pm.add} ${add}`, dev && `${pm.dev} ${dev}`, remove && `${pm.remove} ${remove}`, run && `${pm.run} ${run}`, script && script.replaceAll("{run}", pm.run).replaceAll("{dlx}", pm.dlx), ] .filter(Boolean) .join("\n"); --- { managers.map((pm) => ( )) }