Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to official storybook nuxt module #2244

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
74df3cb
chore: migrate to official storybook nuxt module
tobiasdiez Sep 29, 2023
f7cc0d4
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Oct 3, 2023
5909dbb
upgrade @storybook-vue/nuxt
tobiasdiez Oct 3, 2023
b8dbc53
update @storybook-vue/nuxt
tobiasdiez Oct 3, 2023
a82e2c5
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Apr 9, 2024
f93fc2f
fix merge mistake
tobiasdiez Apr 9, 2024
cbe8a9b
update lock file
tobiasdiez Apr 9, 2024
2899ec0
install dependencies
tobiasdiez Apr 9, 2024
37a47f2
update main config
tobiasdiez Apr 9, 2024
e3c4ca7
add storybook dependency
tobiasdiez Apr 9, 2024
2483a6e
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Jul 13, 2024
2a1e4be
update storybook module
tobiasdiez Jul 13, 2024
64b5847
chore: remove external-iframe
tobiasdiez Jul 13, 2024
1ea7ea8
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 11, 2024
c6c6f91
use nightly
tobiasdiez Aug 11, 2024
f5102d8
disable vue stories for now
tobiasdiez Aug 11, 2024
e185884
update storybook
tobiasdiez Aug 11, 2024
d1b6a6a
dedupe
tobiasdiez Aug 11, 2024
916d060
update lock file
tobiasdiez Aug 11, 2024
646c746
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 11, 2024
c54d38b
migrate to v8
tobiasdiez Aug 11, 2024
8b5485c
Update Storybook imports to use @storybook-vue/nuxt
tobiasdiez Aug 11, 2024
bbb762a
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 12, 2024
4d5cf6e
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 12, 2024
308a399
add chromatic config
tobiasdiez Aug 12, 2024
e535481
build storybook even if tests fail
tobiasdiez Aug 12, 2024
8012bca
readd runtime compiler
tobiasdiez Aug 12, 2024
4ac2be6
fix storybook build
tobiasdiez Aug 12, 2024
3a0fb07
remove another workaround
tobiasdiez Aug 12, 2024
dd3cfc4
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 12, 2024
3b44aa4
publish storybook always
tobiasdiez Aug 12, 2024
c2cb577
update chromatic
tobiasdiez Aug 12, 2024
d7bc175
remove only changed in chromatic
tobiasdiez Aug 12, 2024
b125f06
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 13, 2024
75d5a08
improve ci
tobiasdiez Aug 13, 2024
0968791
update deps
tobiasdiez Aug 14, 2024
6b6a799
try to fix ts
tobiasdiez Aug 14, 2024
b97d641
fix ts
tobiasdiez Aug 14, 2024
40a7fd4
update vue-addon
tobiasdiez Aug 20, 2024
3e79ca3
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Aug 20, 2024
853423f
remove unnedded nuxt module
tobiasdiez Aug 21, 2024
3739566
Merge remote-tracking branch 'origin/main' into storybook-module
tobiasdiez Dec 28, 2024
d2e017b
remove vue runtime compiler configuration from nuxt config
tobiasdiez Dec 28, 2024
931aa38
fix linter
tobiasdiez Dec 28, 2024
75c0fb8
update storybook
tobiasdiez Dec 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,11 @@ jobs:
TEST_URL: http://localhost:3000

- name: Build Storybook
run: |
pnpm nuxi generate
pnpm storybook:build
cp .output/public/_storybook/external-iframe/index.html storybook-static/iframe.html
mkdir -p storybook-static/_storybook/external-iframe
cp -r .output/public/_nuxt storybook-static
if: always()
run: pnpm storybook:build

- name: Publish and test Storybook
if: always()
uses: chromaui/action@64a9c0ca3bfb724389b0d536e544f56b7b5ff5b3 # v11
with:
projectToken: 'b3787adf2fa5'
Expand Down
82 changes: 4 additions & 78 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,16 @@
import type { StorybookConfig } from '@storybook/vue3-vite'
import { mergeConfig } from 'vite'
import type { StorybookConfig } from '@nuxtjs/storybook'

const config: StorybookConfig = {
// Need to specify stories as workaround for https://github.com/storybookjs/storybook/issues/20761
stories: ['../components/*.stories.@(vue|ts)'],
core: {
// @ts-expect-error - need to update storybook types
disableTelemetry: true,
},
addons: ['storybook-vue-addon', '@chromatic-com/storybook'],
framework: {
name: '@storybook/vue3-vite',
name: '@storybook-vue/nuxt',
options: {},
},
addons: ['storybook-vue-addon'],
async viteFinal(config) {
const nuxtViteConfig = (await startNuxtAndGetViteConfig()).viteConfig
// Need to remove storybook-vue-addon since it will be inserted by the storybook-vue-addon plugin
// TODO: Would be better if we would check there that the plugin is not already added
config.plugins = config.plugins.filter((plugin) => {
if (
plugin !== null &&
typeof plugin === 'object' &&
'name' in plugin &&
plugin.name === 'storybook-vue-addon'
) {
return false
}
return true
})
return mergeConfig(
{
resolve: nuxtViteConfig.resolve,
optimizeDeps: nuxtViteConfig.optimizeDeps,
plugins: nuxtViteConfig.plugins,
define: nuxtViteConfig.define,
},
config,
)
},
}

// https://github.com/nuxt/nuxt/issues/14534
// From: https://github.com/danielroe/nuxt-vitest/blob/main/packages/nuxt-vitest/src/config.ts
async function startNuxtAndGetViteConfig(rootDir = process.cwd()) {
// Use dynamic import as a workaround for https://github.com/storybookjs/storybook/issues/23972
const { buildNuxt, loadNuxt, tryUseNuxt } = await import('@nuxt/kit')
let nuxt = tryUseNuxt()
let nuxtAlreadyRunnnig = true
if (!nuxt) {
nuxtAlreadyRunnnig = false
nuxt = await loadNuxt({
cwd: rootDir,
dev: false,
overrides: {
ssr: false,
app: {
rootId: 'nuxt-test',
},
},
})
}

const promise = new Promise<{ nuxt; viteConfig }>((resolve, reject) => {
nuxt.hook('vite:extendConfig', (viteConfig, { isClient }) => {
if (isClient) {
resolve({ nuxt, viteConfig })
if (!nuxtAlreadyRunnnig) {
throw new Error('_stop_')
}
}
})

// TODO: Need better handling if Nuxt is already running
// we don't really want to build nuxt again,
// or at least shutdown the second build after vite:extendConfig is called
buildNuxt(nuxt).catch((err) => {
if (!err.toString().includes('_stop_')) {
reject(err)
}
})
}).finally(() => {
if (!nuxtAlreadyRunnnig) {
nuxt.close()
}
})

return promise
}

export default config
3 changes: 3 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
tags: ['autodocs'],
}
4 changes: 4 additions & 0 deletions chromatic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"projectId": "Project:61142988527d34003b1e783d",
"zip": true
}
1 change: 0 additions & 1 deletion components/JabRefLogo.stories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import JabRefLogo from './JabrefLogo.vue'
</script>

<template>
<!-- @vue-expect-error: wrong ts of vue-stories -->
<Stories
title="JabRef Logo"
:component="JabRefLogo"
Expand Down
1 change: 0 additions & 1 deletion components/n-button.stories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { NButton } from 'naive-ui'
</script>
<template>
<!-- @vue-expect-error: wrong ts of vue-stories -->
<Stories
title="n-button"
:component="NButton"
Expand Down
6 changes: 4 additions & 2 deletions components/t-alert.stories.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TAlert } from '@variantjs/vue'

export default {
component: TAlert,

Check warning on line 6 in components/t-alert.stories.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an error typed value
title: 't-alert',
args: {
show: true,
Expand All @@ -10,13 +11,14 @@
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }

Check warning on line 17 in components/t-alert.stories.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an `any` value
},
template: '<t-alert v-bind="args">{{args.message}}</t-alert>',
})
export const Default = Template.bind({})

Check warning on line 21 in components/t-alert.stories.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an error typed value

Check warning on line 21 in components/t-alert.stories.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe call of an `error` type typed value
export const Error = Template.bind({})
Error.args = {
variant: 'error',
Expand Down
6 changes: 4 additions & 2 deletions components/t-checkbox.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TCheckbox } from '@variantjs/vue'

export default {
Expand All @@ -9,7 +10,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-dropdown.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TDropdown } from '@variantjs/vue'

export default {
Expand All @@ -9,7 +10,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-input-group.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TInputGroup } from '@variantjs/vue'

export default {
Expand All @@ -11,7 +12,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-input.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TInput } from '@variantjs/vue'

export default {
Expand All @@ -9,7 +10,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-nuxtlink.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TButton } from '@variantjs/vue'

export default {
Expand All @@ -9,7 +10,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-select.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TSelect } from '@variantjs/vue'

export default {
Expand All @@ -10,7 +11,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-table.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import TTable from '~/components/TTable.vue'

export default {
Expand All @@ -13,7 +14,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-tag.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TTag } from '@variantjs/vue'

export default {
Expand All @@ -10,7 +11,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
6 changes: 4 additions & 2 deletions components/t-textarea.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/vue3'
// @ts-expect-error: not sure why nuxi typecheck fails for this
import type { Meta, StoryFn } from '@nuxtjs/storybook'
import { TTextarea } from '@variantjs/vue'

export default {
Expand All @@ -9,7 +10,8 @@ export default {
},
} as Meta

const Template: Story = (args) => ({
// @ts-expect-error: story missing arg types
const Template: StoryFn = (args) => ({
setup() {
return { args }
},
Expand Down
11 changes: 0 additions & 11 deletions global.ts

This file was deleted.

Loading
Loading