Skip to content

Commit

Permalink
feat: Support object style path
Browse files Browse the repository at this point in the history
close #353
  • Loading branch information
farnabaz committed Feb 28, 2022
1 parent fa53c0f commit eeb66ae
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions playground/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default {
storybook: {
addons: [],
stories: [
{
directory: '~/stories-2',
titlePrefix: '[OBJ]',
files: '*.stories.*',
},
'~/stories/**/*.stories.@(ts|js)',
'~/components/**/*.stories.mdx'
],
Expand Down
11 changes: 11 additions & 0 deletions playground/stories-2/configuration-object.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
title: "With a configuration object"
}

export const withConfigurationObject = () => {
return `<p>
This story is registered using configuration object.
<br />
See: https://storybook.js.org/docs/vue/configure/overview/#with-a-configuration-object
</p>`
}
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,21 @@ async function nuxtStorybookOptions (nuxt, options) {
await nuxt.callHook('storybook:config', nuxtStorybookConfig)

nuxtStorybookConfig.stories = nuxtStorybookConfig.stories.filter(
story => !exclude.some(e => story.match(e))
story => !exclude.some(e => story.directory ? story.directory.match(e) : story.match(e))
)
}

nuxtStorybookConfig.stories = nuxtStorybookConfig.stories.map(story => upath.normalize(story
const normalize = (_path:string) => upath.normalize(_path
.replace(/^~~/, path.relative(nuxtStorybookConfig.configDir, options.rootDir))
.replace(/^~/, path.relative(nuxtStorybookConfig.configDir, srcDir)))
)

nuxtStorybookConfig.stories = nuxtStorybookConfig.stories.map((story) => {
if (story.directory) {
story.directory = normalize(story.directory)
return story
}
return normalize(story)
})

return nuxtStorybookConfig
}
2 changes: 1 addition & 1 deletion storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stories = [<%= options.stories.map(s => `'${s}'`).join(",") %>]
const stories = <%= JSON.stringify(options.stories) %>
const addons = [<%= options.addons.map(s => devalue(s)).join(",") %>,{
name: '@storybook/addon-postcss',
options: {
Expand Down

0 comments on commit eeb66ae

Please sign in to comment.