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

feat: load main and preview storybook config from nuxt config #660

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions packages/nuxt-module/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { resolve } from 'node:path'

export function generateConfigFiles(configDir: string) {
const isTsProject = isTypescriptProject()
const extension = isTsProject ? '.ts' : '.js'
const mainFile = resolve(configDir, 'main' + extension)

Check failure on line 6 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, ubuntu-latest)

'mainFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 6 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, macos-latest)

'mainFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 6 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, ubuntu-latest)

'mainFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 6 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, macos-latest)

'mainFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 6 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, windows-latest)

'mainFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 6 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, windows-latest)

'mainFile' is assigned a value but never used. Allowed unused vars must match /^_/u
const previewFile = resolve(configDir, 'preview' + extension)

Check failure on line 7 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, ubuntu-latest)

'previewFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, macos-latest)

'previewFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, ubuntu-latest)

'previewFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, macos-latest)

'previewFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, windows-latest)

'previewFile' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, windows-latest)

'previewFile' is assigned a value but never used. Allowed unused vars must match /^_/u
}

function generateMainConfig({ useTypescript }) {

Check failure on line 10 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, ubuntu-latest)

'generateMainConfig' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, macos-latest)

'generateMainConfig' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, ubuntu-latest)

'generateMainConfig' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, macos-latest)

'generateMainConfig' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (18, windows-latest)

'generateMainConfig' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in packages/nuxt-module/src/config.ts

View workflow job for this annotation

GitHub Actions / ci (20, windows-latest)

'generateMainConfig' is defined but never used. Allowed unused vars must match /^_/u
const preamble = useTypescript
? ``
: `
/** @type { import('storybook-vue').StorybookConfig } */
const config = {
`
return (
preamble +
`
stories: [
'../components/**/*.mdx',
'../components/**/*.stories.@(js|jsx|ts|tsx|mdx)',
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@chromatic-com/storybook',
],
framework: {
name: '@storybook-vue/nuxt',
options: {},
},
docs: {
autodocs: 'tag',
},
}
export default config
`
)
}

function isTypescriptProject() {
return true
}
9 changes: 8 additions & 1 deletion packages/nuxt-module/src/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from '@storybook/core-common'
import { buildDevStandalone, withTelemetry } from '@storybook/core-server'
import storybookPackageJson from '@storybook/core-server/package.json'
import { generateConfigFiles } from './config'
import fs from 'node:fs'

const buildLogger = logger.withTag('build')

Expand Down Expand Up @@ -51,10 +53,15 @@ export async function setupStorybook(options: ModuleOptions, nuxt: Nuxt) {
})

const projectDir = resolve(nuxt.options.rootDir)
let configDir = resolve(projectDir, './.storybook')
if (!fs.existsSync(configDir)) {
configDir = resolve(nuxt.options.buildDir, './.storybook')
generateConfigFiles(configDir)
}

const storybookOptions = {
port: storybookServerPort,
configDir: resolve(projectDir, './.storybook'),
configDir: configDir,
configType: 'DEVELOPMENT',
cache: storybookCache,
packageJson: storybookPackageJson as PackageJson,
Expand Down
Loading