Skip to content

Commit

Permalink
refactor(devtools): use unbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Oct 19, 2024
1 parent 6fdbc5f commit f8f98d1
Show file tree
Hide file tree
Showing 35 changed files with 43 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- name: Prepare
run: pnpm run dev:prepare

- name: Devtools prepare
run: pnpm run devtools:prepare

- name: Lint
run: pnpm run lint

Expand All @@ -60,9 +63,6 @@ jobs:
- name: Test
run: pnpm run test

- name: Devtools prepare
run: pnpm run devtools:prepare

- name: Build
run: pnpm run build

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
src/devtools/.component-meta/
.component-meta/
component-meta.*

# Nuxt dev/build outputs
.output
Expand Down
4 changes: 4 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
// Include devtools runtime files
{ input: './src/devtools/runtime', builder: 'mkdist', outDir: 'dist/devtools/runtime' }
],
replace: {
'process.env.DEV': 'false'
},
Expand Down
2 changes: 1 addition & 1 deletion devtools/app/components/CollapseContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ onMounted(() => {
</script>

<template>
<div>
<div class="border rounded border-[var(--ui-border)]">
<div
ref="wrapper"
:class="['overflow-hidden', collapsed && overflow ? 'max-h-48' : 'max-h-none']"
Expand Down
5 changes: 3 additions & 2 deletions devtools/app/components/ComponentPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const code = computed(() => {
if (!props.component) return
const propsTemplate = Object.entries(props.props ?? {})?.map(([key, value]: [string, any]) => {
const defaultValue: any = props.component?.meta?.props.find(prop => prop.name === key)?.default
if (defaultValue === value) return
if (value === true) return kebabCase(key)
if (value === false) return
if (value === false && defaultValue === true) return `:${kebabCase(key)}="false"`
if (!value) return
if (props.component?.defaultVariants?.[key] === value) return
if (props.component?.meta?.props.find(prop => prop.name === key && prop.default === value)) return
if (typeof value === 'number') return `:${kebabCase(key)}="${value}"`
if (Array.isArray(value)) return value.length ? `:${kebabCase(key)}="${genArrayFromRaw(value, undefined, { preserveTypes: true })}"` : undefined
if (typeof value === 'object') return `:${kebabCase(key)}="${genObjectFromValues(value)}"`
Expand Down
5 changes: 2 additions & 3 deletions devtools/app/components/inputs/ArrayInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ function addArrayItem() {

<template>
<div>
<div v-for="value, index in modelValue" :key="index" class="relative border border-[var(--ui-border)] rounded-md mt-4">
<div v-for="value, index in modelValue" :key="index" class="relative">
<ComponentPropInput
:model-value="value"
:meta="{ schema: itemSchema }"
class="border-b last:border-b-0 border-[var(--ui-border)]"
/>

<UPopover>
<UButton variant="ghost" color="neutral" icon="i-heroicons-ellipsis-vertical" class="absolute top-1 right-1" />
<UButton variant="ghost" color="neutral" icon="i-heroicons-ellipsis-vertical" class="absolute top-4 right-1" />
<template #content>
<UButton
variant="ghost"
Expand Down
2 changes: 1 addition & 1 deletion devtools/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default defineNuxtConfig({
mdc: {
highlight: {
theme: {
light: 'material-theme-lighter',
light: 'material-theme',
default: 'material-theme',
dark: 'material-theme-palenight'
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"docs:prepare": "nuxt-component-meta docs",
"docs:typecheck": "nuxi typecheck docs",
"devtools": "NUXT_UI_DEVTOOLS_LOCAL=true nuxi dev playground",
"devtools:build": "nuxi generate devtools && cp -r src/devtools dist/devtools",
"devtools:build": "nuxi generate devtools",
"devtools:prepare": "nuxt-component-meta playground --outputDir ../src/devtools/.component-meta/",
"devtools:typecheck": "nuxi typecheck devtools",
"lint": "eslint .",
Expand Down
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { resolve } = createResolver(import.meta.url)
export default defineNuxtConfig({
devtools: { enabled: true },

modules: ['../src/module'],
modules: ['../dist/module'],

future: {
compatibilityVersion: 4
Expand Down
5 changes: 0 additions & 5 deletions src/devtools/examples/ContainerExample.vue

This file was deleted.

5 changes: 0 additions & 5 deletions src/devtools/examples/ContextMenuExample.vue

This file was deleted.

5 changes: 0 additions & 5 deletions src/devtools/examples/TooltipExample.vue

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function devtoolsMetaPlugin({ resolve }: { resolve: Resolver['resolve'] }
server.middlewares.use('/__nuxt_ui__/devtools/api/component-meta', async (_req, res) => {
res.setHeader('Content-Type', 'application/json')
try {
const componentMeta = await import(resolve('./devtools/.component-meta/component-meta.mjs'))
const componentMeta = await import('./.component-meta/component-meta')
const meta = defu(
Object.entries(componentMeta.default).reduce((acc, [key, value]: [string, any]) => {
if (!key.startsWith('U')) return acc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useColorMode, useRoute } from '#imports'
const route = useRoute()
const component = route.query?.example
? defineAsyncComponent(() => import(`./examples/${route.query.example}.vue`))
: route.params?.slug && defineAsyncComponent(() => import(`../runtime/components/${pascalCase(route.params.slug as string)}.vue`))
: route.params?.slug && defineAsyncComponent(() => import(`../../runtime/components/${pascalCase(route.params.slug as string)}.vue`))
const state = reactive<{ slots?: any, props?: any }>({})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="flex flex-col gap-4">
<UCard class="w-96">
<template #header>
<Placeholder class="h-8" />
<div class="bg-[var(--ui-bg-accented)]/40 h-8" />
</template>
<Placeholder class="h-32" />
<div class="bg-[var(--ui-bg-accented)]/40 h-32" />
<template #footer>
<Placeholder class="h-8" />
<div class="bg-[var(--ui-bg-accented)]/40 h-8" />
</template>
</UCard>
</div>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<UCollapsible class="w-48">
<UButton label="Open Collapse" block />
<template #content>
<Placeholder class="h-60" />
<div class="bg-[var(--ui-bg-accented)]/40 h-60" />
</template>
</UCollapsible>
</template>
5 changes: 5 additions & 0 deletions src/devtools/runtime/examples/ContainerExample.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<UContainer>
<div class="bg-[var(--ui-bg-accented)]/40 h-60 aspect-video w-72" />
</UContainer>
</template>
5 changes: 5 additions & 0 deletions src/devtools/runtime/examples/ContextMenuExample.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<UContextMenu>
<div class="bg-[var(--ui-bg-accented)]/40 h-60 w-72" />
</UContextMenu>
</template>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<UModal>
<UButton label="Open Modal" />
<template #content>
<Placeholder class="h-72 w-full" />
<div class="h-72" />
</template>
</UModal>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<UPopover>
<UButton label="Open Collapse" />
<template #content>
<Placeholder class="h-24 w-60" />
<div class="bg-[var(--ui-bg-accented)]/40 h-24 w-60" />
</template>
</UPopover>
</template>
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/devtools/runtime/examples/TooltipExample.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<UTooltip>
<div class="bg-[var(--ui-bg-accented)]/40 size-20" />
</UTooltip>
</template>
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sirv from 'sirv'
import { setupDevtoolsClient } from './devtools/rpc'
import { getPort } from 'get-port-please'
import { pick } from './runtime/utils'
import { devtoolsMetaPlugin } from './devtools/devtoolsMetaPlugin'
import { devtoolsMetaPlugin } from './devtools/meta'

export type * from './runtime/types'

Expand Down Expand Up @@ -187,7 +187,7 @@ export default defineNuxtModule<ModuleOptions>({
pages.unshift({
name: 'ui-devtools',
path: '/__nuxt_ui__/components/:slug',
file: resolve('./devtools/DevtoolsRenderer.vue')
file: resolve('./devtools/runtime/DevtoolsRenderer.vue')
// https://github.com/nuxt/nuxt/pull/29366
// meta: {
// isolate: true
Expand Down

0 comments on commit f8f98d1

Please sign in to comment.