diff --git a/packages/nuxt-module/src/config.ts b/packages/nuxt-module/src/config.ts new file mode 100644 index 00000000..84320c67 --- /dev/null +++ b/packages/nuxt-module/src/config.ts @@ -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) + const previewFile = resolve(configDir, 'preview' + extension) +} + +function generateMainConfig({ useTypescript }) { + 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 +} diff --git a/packages/nuxt-module/src/storybook.ts b/packages/nuxt-module/src/storybook.ts index bcb4afce..63900d88 100644 --- a/packages/nuxt-module/src/storybook.ts +++ b/packages/nuxt-module/src/storybook.ts @@ -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') @@ -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,