@theguild/components
Version:
55 lines (54 loc) • 1.76 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { Pre, Tabs } from "nextra/components";
const PACKAGE_MANAGERS = ["yarn", "npm", "pnpm"];
const Add = {
yarn: "yarn add",
npm: "npm install",
pnpm: "pnpm add"
};
const Run = {
yarn: "yarn",
npm: "npm run",
pnpm: "pnpm"
};
const Install = {
yarn: "yarn",
npm: "npm install",
pnpm: "pnpm install"
};
const Init = {
yarn: "yarn init --yes",
npm: "npm init --yes",
pnpm: "pnpm init"
};
const Global = {
yarn: "yarn global add",
npm: "npm install --global",
pnpm: "pnpm add --global"
};
const LegacyPackageCmd = ({
packages
}) => {
const commands = useMemo(
() => PACKAGE_MANAGERS.map(
(pkgManager) => packages.map((pkg) => typeof pkg === "string" ? { name: pkg, cmd: "add" } : pkg).map((pkg) => {
switch (pkg.cmd) {
case "run":
return `${pkgManager === "npm" && pkg.isNpx ? "npx" : Run[pkgManager]} ${pkg.name}`;
case "install":
return `${Install[pkgManager]}${pkg.name ? ` ${pkg.name}` : ""}`;
case "init":
return Init[pkgManager];
default:
return `${pkg.isGlobal ? Global[pkgManager] : Add[pkgManager]} ${pkg.name}`;
}
}).join("\n")
),
[packages]
);
return /* @__PURE__ */ jsx(Tabs, { items: PACKAGE_MANAGERS, children: PACKAGE_MANAGERS.map((pkgManager, index) => /* @__PURE__ */ jsx(Tabs.Tab, { children: /* @__PURE__ */ jsx(Pre, { "data-filename": "Terminal", "data-copy": "", "data-language": "sh", "data-theme": "default", children: /* @__PURE__ */ jsx("code", { children: /* @__PURE__ */ jsx("span", { className: "line", children: commands[index] }) }) }) }, pkgManager)) });
};
export {
LegacyPackageCmd
};