Skip to content

Commit

Permalink
fix!: improve handling of module options (#518)
Browse files Browse the repository at this point in the history
* fix: improve handling of module options

* fix name of env variable
  • Loading branch information
tobiasdiez committed Apr 10, 2024
1 parent 0d97f94 commit 3b805f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 43 deletions.
54 changes: 14 additions & 40 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,26 @@ import { setupStorybook } from './storybook'

export interface ModuleOptions {
/**
* StorybookAPI URL
* @default import.meta.env.STORYBOOK_URL
* @example 'http://localhost:6006'
* @type string
*/
url?: string

/**
* StorybookVersion
* @default 'v8'
* @type string
* @example 'v8'
* The route where the Storybook application will be available in development mode.
*
* @default '/_storybook'
*/
version?: 'v7' | 'v8'

/**
* StorybookCookie Name
* @default 'storybook_jwt'
* @type string
*/
cookieName?: string
route: string

/**
* Add Storybook in Nuxt Devtools
* The port where the Storybook application server will be started.
*
* Please read the instructions on https://storybook.nuxtjs.org/devtools
*
* @default false
*/
devtools?: boolean

/**
* Storybook Route
* @default '/__storybook_route'
* @default 6006
*/
storybookRoute?: string
port: number

/**
* Storybook Port
* @default 6006
* @type number
* The host where the Storybook application server will be started.
*
* @default Environment variable 'STORYBOOK_HOST' or 'http://localhost'
* @example 'http://localhost'
*/
port?: number
host: string
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -58,12 +35,9 @@ export default defineNuxtModule<ModuleOptions>({
},
},
defaults: {
url: import.meta.env.STORYBOOK_URL || 'http://localhost:6006',
storybookRoute: '/__storybook_route',
host: import.meta.env.STORYBOOK_HOST || 'http://localhost:6006',
route: '/_storybook',
port: 6006,
version: 'v8',
cookieName: 'sb_session',
devtools: false,
},
async setup(options, nuxt) {

Expand Down
7 changes: 4 additions & 3 deletions src/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import type { Nuxt } from 'nuxt/schema'
import { getPort } from 'get-port-please'
import { extendViteConfig } from '@nuxt/kit'
import { logger } from '@nuxt/kit'
import type { ModuleOptions } from './module'


export async function setupStorybook(options: any, nuxt: Nuxt) {
const STORYBOOK_ROUTE = options.storybookRoute || '/__storybook_route'
export async function setupStorybook(options: ModuleOptions, nuxt: Nuxt) {
const STORYBOOK_ROUTE = options.route
const STORYBOOK_PORT = await getPort({ ports: [options.port || 6006, 6007, 6008, 6009, 6010]})
const STORYBOOK_HOST = options.storybookHost || 'http://localhost'
const STORYBOOK_HOST = options.host
const STORYBOOK_URL = + STORYBOOK_HOST + STORYBOOK_PORT == 80 ? '' : `:${STORYBOOK_PORT}`

const projectDir = resolve(nuxt.options.rootDir)
Expand Down

0 comments on commit 3b805f4

Please sign in to comment.