-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathInstall.vue
More file actions
275 lines (251 loc) · 10.7 KB
/
Install.vue
File metadata and controls
275 lines (251 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<script setup lang="ts">
import type { JsrPackageInfo } from '#shared/types/jsr'
import type { PackageManagerId } from '~/utils/install-command'
const props = defineProps<{
packageName: string
requestedVersion?: string | null
jsrInfo?: JsrPackageInfo | null
typesPackageName?: string | null
executableInfo?: { hasExecutable: boolean; primaryCommand?: string } | null
createPackageInfo?: { packageName: string } | null
}>()
const { selectedPM, showTypesInInstall, copied, copyInstallCommand } = useInstallCommand(
() => props.packageName,
() => props.requestedVersion ?? null,
() => props.jsrInfo ?? null,
() => props.typesPackageName ?? null,
)
// Generate install command parts for a specific package manager
function getInstallPartsForPM(pmId: PackageManagerId) {
return getInstallCommandParts({
packageName: props.packageName,
packageManager: pmId,
version: props.requestedVersion,
jsrInfo: props.jsrInfo,
})
}
// Generate run command parts for a specific package manager
function getRunPartsForPM(pmId: PackageManagerId, command?: string) {
return getRunCommandParts({
packageName: props.packageName,
packageManager: pmId,
jsrInfo: props.jsrInfo,
command,
isBinaryOnly: false,
})
}
// Generate create command parts for a specific package manager
function getCreatePartsForPM(pmId: PackageManagerId) {
if (!props.createPackageInfo) return []
const pm = packageManagers.find(p => p.id === pmId)
if (!pm) return []
const createPkgName = props.createPackageInfo.packageName
let shortName: string
if (createPkgName.startsWith('@')) {
const slashIndex = createPkgName.indexOf('/')
const name = createPkgName.slice(slashIndex + 1)
shortName = name.startsWith('create-') ? name.slice('create-'.length) : name
} else {
shortName = createPkgName.startsWith('create-')
? createPkgName.slice('create-'.length)
: createPkgName
}
return [...pm.create.split(' '), shortName]
}
// Generate @types install command parts for a specific package manager
function getTypesInstallPartsForPM(pmId: PackageManagerId) {
if (!props.typesPackageName) return []
const pm = packageManagers.find(p => p.id === pmId)
if (!pm) return []
const devFlag = pmId === 'bun' ? '-d' : '-D'
const pkgSpec = pmId === 'deno' ? `npm:${props.typesPackageName}` : props.typesPackageName
return [pm.label, pm.action, devFlag, pkgSpec]
}
// Full run command for copying (uses current selected PM)
function getFullRunCommand(command?: string) {
return getRunCommand({
packageName: props.packageName,
packageManager: selectedPM.value,
jsrInfo: props.jsrInfo,
command,
})
}
// Full create command for copying (uses current selected PM)
function getFullCreateCommand() {
return getCreatePartsForPM(selectedPM.value).join(' ')
}
// Copy handlers
const { copied: runCopied, copy: copyRun } = useClipboard({ copiedDuring: 2000 })
const copyRunCommand = (command?: string) => copyRun(getFullRunCommand(command))
const { copied: createCopied, copy: copyCreate } = useClipboard({ copiedDuring: 2000 })
const copyCreateCommand = () => copyCreate(getFullCreateCommand())
</script>
<template>
<div class="relative group">
<!-- Terminal-style install command -->
<div class="bg-bg-subtle border border-border rounded-lg overflow-hidden">
<div class="flex gap-1.5 px-3 pt-2 sm:px-4 sm:pt-3">
<span class="w-2.5 h-2.5 rounded-full bg-fg-subtle" />
<span class="w-2.5 h-2.5 rounded-full bg-fg-subtle" />
<span class="w-2.5 h-2.5 rounded-full bg-fg-subtle" />
</div>
<div class="px-3 pt-2 pb-3 sm:px-4 sm:pt-3 sm:pb-4 space-y-1 overflow-x-auto">
<!-- Install command - render all PM variants, CSS controls visibility -->
<div
v-for="pm in packageManagers"
:key="`install-${pm.id}`"
:data-pm-cmd="pm.id"
class="flex items-center gap-2 group/installcmd min-w-0"
>
<span class="text-fg-subtle font-mono text-sm select-none shrink-0">$</span>
<code class="font-mono text-sm min-w-0"
><span
v-for="(part, i) in getInstallPartsForPM(pm.id)"
:key="i"
:class="i === 0 ? 'text-fg' : 'text-fg-muted'"
>{{ i > 0 ? ' ' : '' }}{{ part }}</span
></code
>
<button
type="button"
class="px-2 py-0.5 font-mono text-xs text-fg-muted bg-bg-subtle/80 border border-border rounded transition-colors duration-200 opacity-0 group-hover/installcmd:opacity-100 hover:(text-fg border-border-hover) active:scale-95 focus-visible:opacity-100 focus-visible:outline-accent/70"
:aria-label="$t('package.get_started.copy_command')"
@click.stop="copyInstallCommand"
>
<span aria-live="polite">{{ copied ? $t('common.copied') : $t('common.copy') }}</span>
</button>
</div>
<!-- @types package install - render all PM variants when types package exists -->
<template v-if="typesPackageName && showTypesInInstall">
<div
v-for="pm in packageManagers"
:key="`types-${pm.id}`"
:data-pm-cmd="pm.id"
class="flex items-center gap-2 min-w-0"
>
<span class="text-fg-subtle font-mono text-sm select-none shrink-0">$</span>
<code class="font-mono text-sm min-w-0"
><span
v-for="(part, i) in getTypesInstallPartsForPM(pm.id)"
:key="i"
:class="i === 0 ? 'text-fg' : 'text-fg-muted'"
>{{ i > 0 ? ' ' : '' }}{{ part }}</span
></code
>
<NuxtLink
:to="`/package/${typesPackageName}`"
class="text-fg-subtle hover:text-fg-muted text-xs transition-colors focus-visible:outline-accent/70 rounded"
:title="$t('package.get_started.view_types', { package: typesPackageName })"
>
<span class="i-carbon:arrow-right rtl-flip w-3 h-3 align-middle" aria-hidden="true" />
<span class="sr-only">View {{ typesPackageName }}</span>
</NuxtLink>
</div>
</template>
<!-- Run command (only if package has executables) - render all PM variants -->
<template v-if="executableInfo?.hasExecutable">
<!-- Comment line -->
<div class="flex items-center gap-2 pt-1">
<span class="text-fg-subtle font-mono text-sm select-none"
># {{ $t('package.run.locally') }}</span
>
</div>
<div
v-for="pm in packageManagers"
:key="`run-${pm.id}`"
:data-pm-cmd="pm.id"
class="flex items-center gap-2 group/runcmd"
>
<span class="text-fg-subtle font-mono text-sm select-none">$</span>
<code class="font-mono text-sm"
><span
v-for="(part, i) in getRunPartsForPM(pm.id, executableInfo?.primaryCommand)"
:key="i"
:class="i === 0 ? 'text-fg' : 'text-fg-muted'"
>{{ i > 0 ? ' ' : '' }}{{ part }}</span
></code
>
<button
type="button"
class="px-2 py-0.5 font-mono text-xs text-fg-muted bg-bg-subtle/80 border border-border rounded transition-colors duration-200 opacity-0 group-hover/runcmd:opacity-100 hover:(text-fg border-border-hover) active:scale-95 focus-visible:opacity-100 focus-visible:outline-accent/70"
@click.stop="copyRunCommand(executableInfo?.primaryCommand)"
>
{{ runCopied ? $t('common.copied') : $t('common.copy') }}
</button>
</div>
</template>
<!-- Create command (for packages with associated create-* package) - render all PM variants -->
<template v-if="createPackageInfo">
<!-- Comment line -->
<div class="flex items-center gap-2 pt-1">
<span class="text-fg-subtle font-mono text-sm select-none"
># {{ $t('package.create.title') }}</span
>
<TooltipApp
:text="$t('package.create.view', { packageName: createPackageInfo.packageName })"
>
<NuxtLink
:to="`/package/${createPackageInfo.packageName}`"
class="inline-flex items-center justify-center min-w-6 min-h-6 -m-1 p-1 text-fg-muted hover:text-fg text-xs transition-colors focus-visible:outline focus-visible:outline-accent/70 rounded"
>
<span class="i-carbon:information w-3 h-3" aria-hidden="true" />
<span class="sr-only">{{
$t('package.create.view', { packageName: createPackageInfo.packageName })
}}</span>
</NuxtLink>
</TooltipApp>
</div>
<div
v-for="pm in packageManagers"
:key="`create-${pm.id}`"
:data-pm-cmd="pm.id"
class="flex items-center gap-2 group/createcmd"
>
<span class="text-fg-subtle font-mono text-sm select-none">$</span>
<code class="font-mono text-sm"
><span
v-for="(part, i) in getCreatePartsForPM(pm.id)"
:key="i"
:class="i === 0 ? 'text-fg' : 'text-fg-muted'"
>{{ i > 0 ? ' ' : '' }}{{ part }}</span
></code
>
<button
type="button"
class="px-2 py-0.5 font-mono text-xs text-fg-muted bg-bg-subtle/80 border border-border rounded transition-colors duration-200 opacity-0 group-hover/createcmd:opacity-100 hover:(text-fg border-border-hover) active:scale-95 focus-visible:opacity-100 focus-visible:outline-accent/70"
:aria-label="$t('package.create.copy_command')"
@click.stop="copyCreateCommand"
>
<span aria-live="polite">{{
createCopied ? $t('common.copied') : $t('common.copy')
}}</span>
</button>
</div>
</template>
</div>
</div>
</div>
</template>
<style>
/*
* Package manager command visibility based on data-pm attribute on <html>.
* All variants are rendered; CSS shows only the selected one.
*/
/* Hide all variants by default when preference is set */
:root[data-pm] [data-pm-cmd] {
display: none;
}
/* Show only the matching package manager command */
:root[data-pm='npm'] [data-pm-cmd='npm'],
:root[data-pm='pnpm'] [data-pm-cmd='pnpm'],
:root[data-pm='yarn'] [data-pm-cmd='yarn'],
:root[data-pm='bun'] [data-pm-cmd='bun'],
:root[data-pm='deno'] [data-pm-cmd='deno'],
:root[data-pm='vlt'] [data-pm-cmd='vlt'] {
display: flex;
}
/* Fallback: when no data-pm is set (SSR initial), show npm as default */
:root:not([data-pm]) [data-pm-cmd]:not([data-pm-cmd='npm']) {
display: none;
}
</style>