Optiq
Optiq

Reputation: 3202

Is there a way to auto generate stories when generating components in NX?

(Scroll down to see update )

I set up an NX repo and setup storybook. My main app and my library both have a .storybook folder an the main AppComponents of both have a story. However when I try generating a component, no story generates. I generate my components by cding my way into the folder I want to generate it in and run

npx nx g @nx/angular:component new-component/new-component

This generates a new folder with my component files as expected. However it doesn't generate a .stories.ts file for the components. During setup I specified "yes" when asked if I wanted stories to be automatically generated.

I went into the main.ts file of the .storybook folders of both apps and added generateStories : true to the options object of the framework object, closed the project down and restarted it, which I do by running

npx nx run my-project:serve

I tried to generate a story for my new component manually by running

npx nx g @nx/angular:component-story --componentPath="path/to/component"

It failed telling me I needed to add the --projectPath property. I added that then it said I needed to add a --componentFileName property. It continued to complain and eventually threw an error saying

Could not read TS file (libs/apps/ingredient-manager/main-menu/main-menu.component.ts/main-menu.component.ts.ts)

which I don't know how it concluded to that being the path to my component because it's supposed to be

libs/apps/ingredient-manager/main-menu/main-menu.component.ts

so I don't know what I was entering incorrectly. But what do I need to do to just get the stories to generate upon creating a component?

Update After digging around and tinkering with my project.json files trying to get things to work I wound up discovering that if we run

nx g @nx/angular:stories myProjectName

it generates stories in that project for any component that doesn't have a story. Meaning we need to build out our components first then run that script. So that problem is solved, however I want to know if there's a property I can set somewhere in NX so a story will be generated with each component.

Upvotes: 0

Views: 37

Answers (0)

Related Questions