diff --git a/packages/app/app/components/Commits.vue b/packages/app/app/components/Commits.vue index 4deb4416..8f8728c7 100644 --- a/packages/app/app/components/Commits.vue +++ b/packages/app/app/components/Commits.vue @@ -8,10 +8,14 @@ import { createJavaScriptRegexEngine } from "shiki/engine/javascript"; interface PackageInfo { name: string; installUrl: string; - installCommand: string; isOnNpm: boolean; } +type PackageManager = "npm" | "yarn" | "pnpm" | "bun"; + +const packageManagers: PackageManager[] = ["npm", "yarn", "pnpm", "bun"]; +const selectedPackageManager = ref("npm"); + interface RepoCommitsResponse { id: string; name: string; @@ -120,10 +124,23 @@ const colorMode = useColorMode(); const highlightCache = new Map(); -function highlightInstallCommand(code: string) { - if (props.withDev) { - code += " --dev"; - } +function getInstallCommand(pkg: PackageInfo) { + const descriptor = + selectedPackageManager.value === "yarn" + ? `${pkg.name}@${pkg.installUrl}.tgz` + : pkg.installUrl; + const installCommand: Record = { + npm: "npm i", + yarn: "yarn add", + pnpm: "pnpm add", + bun: "bun add", + }; + + return `${installCommand[selectedPackageManager.value]} ${descriptor}${props.withDev ? " -D" : ""}`; +} + +function highlightInstallCommand(pkg: PackageInfo) { + const code = getInstallCommand(pkg); if (!shiki) return ""; const theme = colorMode.value === "dark" ? "github-dark" : "github-light"; const cacheKey = `${theme}::${code}`; @@ -151,11 +168,8 @@ const copiedPackage = ref(null); let copyTimeoutId: ReturnType | null = null; function copyInstallCommand(pkg: PackageInfo) { - const text = props.withDev - ? `${pkg.installCommand} --dev` - : pkg.installCommand; - navigator.clipboard?.writeText(text); - copiedPackage.value = pkg.name; + navigator.clipboard?.writeText(getInstallCommand(pkg)); + copiedPackage.value = `${selectedPackageManager.value}:${pkg.name}`; if (copyTimeoutId) clearTimeout(copyTimeoutId); copyTimeoutId = setTimeout(() => { copiedPackage.value = null; @@ -412,6 +426,30 @@ async function goPrevPage() {
+
+
+ + {{ packageManager }} + +
+