Skip to content

Commit

Permalink
feat(components): package managers
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Nov 23, 2024
1 parent c12bb0f commit e537b44
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 102 deletions.
4 changes: 3 additions & 1 deletion components/content/CodeGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<script setup lang="ts">
import Tabs from './Tabs.vue';
const { inStack = false } = defineProps<{
const { inStack = false, sync } = defineProps<{
inStack?: boolean;
sync?: string;
}>();
const _slots = useSlots();
Expand All @@ -17,6 +18,7 @@ function render() {
{
variant: 'card',
inStack,
sync,
},
() => slots,
);
Expand Down
32 changes: 32 additions & 0 deletions components/content/PmInstall.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<MDC :value="md" class="[&:not(:first-child)]:mt-5" />
</template>

<script setup lang="ts">
const {
inStack = false,
name,
sync = '_pm',
saveDev = false,
noSync,
} = defineProps<{
inStack?: boolean;
name?: string;
sync?: string;
saveDev?: boolean;
noSync?: boolean;
}>();
const md = `
::code-group{${inStack ? 'in-stack' : ''} ${noSync ? '' : `sync="${sync}"`}}
${
usePm().packageManagers.value.map((pm) => {
const code = name
? `${pm.command}${pm.install}${saveDev ? pm.saveDev : ''}${name}`
: `${pm.command}${pm.installEmpty}`;
return `\`\`\`bash [${pm.name}]\n${code}\n\`\`\`\n`;
}).join('\n')
}
::
`;
</script>
28 changes: 28 additions & 0 deletions components/content/PmRun.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<MDC :value="md" class="[&:not(:first-child)]:mt-5" />
</template>

<script setup lang="ts">
const {
inStack = false,
script,
sync = '_pm',
noSync,
} = defineProps<{
inStack?: boolean;
script: string;
sync?: string;
noSync?: boolean;
}>();
const md = `
::code-group{${inStack ? 'in-stack' : ''} ${noSync ? '' : `sync="${sync}"`}}
${
usePm().packageManagers.value.map((pm) => {
const code = `${pm.command}${pm.run}${script}`;
return `\`\`\`bash [${pm.name}]\n${code}\n\`\`\`\n`;
}).join('\n')
}
::
`;
</script>
28 changes: 28 additions & 0 deletions components/content/PmX.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<MDC :value="md" class="[&:not(:first-child)]:mt-5" />
</template>

<script setup lang="ts">
const {
inStack = false,
command,
sync = '_pm',
noSync,
} = defineProps<{
inStack?: boolean;
command: string;
sync?: string;
noSync?: boolean;
}>();
const md = `
::code-group{${inStack ? 'in-stack' : ''} ${noSync ? '' : `sync="${sync}"`}}
${
usePm().packageManagers.value.map((pm) => {
const code = `${pm.x}${command}`;
return `\`\`\`bash [${pm.name}]\n${code}\n\`\`\`\n`;
}).join('\n')
}
::
`;
</script>
7 changes: 2 additions & 5 deletions components/content/TabsInner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,8 @@ const activeTabIndex = computed<number>({
if (sync === undefined || syncScopeIndex.value === -1)
return activeTabIndexData.value;
for (const slot of slotsData) {
if (syncState.value[syncScopeIndex.value]?.value === slot.label)
return slot.index;
}
return activeTabIndexData.value;
return slotsData.find(x => x.label === syncState.value[syncScopeIndex.value]?.value)?.index
|| activeTabIndexData.value;
},
set(index: number) {
if (sync === undefined) {
Expand Down
2 changes: 2 additions & 0 deletions composables/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const defaultConfig: DefaultConfig = {
icon: 'lucide:square-pen',
placement: ['docsFooter'],
},
pm: ['npm', 'pnpm', 'bun', 'yarn'],
codeIcon: {
'package.json': 'vscode-icons:file-type-node',
'tsconfig.json': 'vscode-icons:file-type-tsconfig',
Expand Down Expand Up @@ -90,6 +91,7 @@ const defaultConfig: DefaultConfig = {
'npx': 'vscode-icons:file-type-npm',
'yarn': 'vscode-icons:file-type-yarn',
'bun': 'vscode-icons:file-type-bun',
'deno': 'vscode-icons:file-type-deno',
'yml': 'vscode-icons:file-type-yaml',
'json': 'vscode-icons:file-type-json',
'terminal': 'lucide:terminal',
Expand Down
58 changes: 58 additions & 0 deletions composables/usePm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const packageManagersCode: {
name: 'npm' | 'pnpm' | 'bun' | 'yarn';
command: string;
install: string;
installEmpty: string;
run: string;
x: string;
saveDev: string;
}[] = [
{
name: 'npm',
command: 'npm ',
install: 'i ',
installEmpty: 'install',
run: 'run ',
x: 'npx ',
saveDev: '-D ',
},
{
name: 'pnpm',
command: 'pnpm ',
install: 'i ',
installEmpty: 'install',
run: 'run ',
x: 'pnpm dlx ',
saveDev: '-D ',
},
{
name: 'bun',
command: 'bun ',
install: 'add ',
installEmpty: 'install',
run: 'run ',
x: 'bun x ',
saveDev: '-d ',
},
{
name: 'yarn',
command: 'yarn ',
install: 'add ',
installEmpty: 'install',
run: 'run ',
x: 'yarn dlx ',
saveDev: '-D ',
},
];

export function usePm() {
const { pm } = useConfig().value.main;

const packageManagers = computed(
() => packageManagersCode.filter(x => pm.includes(x.name)),
);

return {
packageManagers,
};
}
42 changes: 3 additions & 39 deletions content/1.getting-started/2.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,19 @@ icon: 'lucide:play'
::steps
### Get Starter Template

::code-group
```bash [npm]
npx nuxi@latest init <project-name> -t github:ZTL-UwU/shadcn-docs-nuxt-starter
```
```bash [pnpm]
pnpm dlx nuxi@latest init <project-name> -t github:ZTL-UwU/shadcn-docs-nuxt-starter
```
```bash [bun]
bunx nuxi@latest init <project-name> -t github:ZTL-UwU/shadcn-docs-nuxt-starter
```
::
:pm-x{command="nuxi@latest init <project-name> -t github:ZTL-UwU/shadcn-docs-nuxt-starter"}

::alert
Alternatively, you can clone or download the template from the [GitHub repo](https://github.com/ZTL-UwU/shadcn-docs-nuxt-starter).
::

### Install Dependencies

::code-group
```bash [npm]
npm install
```
```bash [pnpm]
pnpm install
```
```bash [bun]
bun install
```
```bash [yarn]
yarn install
```
::
:pm-install

### Development Server

::code-group
```bash [npm]
npm run dev -- -o
```
```bash [pnpm]
pnpm dev -o
```
```bash [bun]
bun run dev -o
```
```bash [yarn]
yarn dev --open
```
::
:pm-run{script="dev"}

::alert{type="success" icon="lucide:circle-check"}
Well done! A browser window should automatically open for http://localhost:3000.
Expand Down
60 changes: 34 additions & 26 deletions content/2.components/2.docs/code-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,48 @@ badges:
::code-group
::div{label="Preview" class="md:p-4"}
::code-group
```bash [npm]
npm run dev
```vue [app.vue]
<template>
<div>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</div>
</template>
```

```bash [pnpm]
pnpm dev
```

```bash [yarn]
yarn dev
```

```bash [bun]
bun run dev
```vue [pages/index.vue]
<template>
<div>
<h1>Welcome to the homepage</h1>
<AppAlert>
This is an auto-imported component
</AppAlert>
</div>
</template>
```
::
::

```mdc [Code]
::code-group
```bash [npm]
npm run dev
```vue [app.vue]
<template>
<div>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</div>
</template>
```
```bash [pnpm]
pnpm dev
```
```bash [yarn]
yarn dev
```
```bash [bun]
bun run dev
```vue [pages/index.vue]
<template>
<div>
<h1>Welcome to the homepage</h1>
<AppAlert>
This is an auto-imported component
</AppAlert>
</div>
</template>
```
::
```
Expand Down
50 changes: 50 additions & 0 deletions content/2.components/2.docs/pm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Package Manager
icon: lucide:package
description: ''
badges:
- value: Source
icon: lucide:code
to: https://github.com/ZTL-UwU/shadcn-docs-nuxt/blob/main/components/content/PmInstall.vue
target: _blank
- value: 0.8.0
---

::code-group
::div{label="Preview" class="md:p-4"}
#### Install
:pm-install{name="shadcn-docs-nuxt"}
:pm-install{name="shadcn-docs-nuxt" save-dev}
:pm-install
:pm-install{name="-g nuxi@latest"}

#### Run
:pm-run{script="dev"}
:pm-run{script="build --watch -o"}

#### X
:pm-x{command="nuxi@latest init <project-name>"}

#### No Sync
:pm-x{command="nuxi@latest init <project-name>" no-sync}
::
```mdc [Code]
#### Install
:pm-install{name="shadcn-docs-nuxt"}
:pm-install{name="shadcn-docs-nuxt" save-dev}
:pm-install
:pm-install{name="-g nuxi@latest"}
#### Run
:pm-run{script="dev"}
:pm-run{script="build --watch -o"}
#### X
:pm-x{command="nuxi@latest init <project-name>"}
#### No Sync
:pm-x{command="nuxi@latest init <project-name>" no-sync}
```
::

The package managers shown can be configured in [`main.pm`](/api/configuration/shadcn-docs#main).
Loading

0 comments on commit e537b44

Please sign in to comment.