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

Any news about Storydocs plugin? #19

Open
dobromyslov opened this issue Oct 14, 2020 · 6 comments · Fixed by #21 or #24
Open

Any news about Storydocs plugin? #19

dobromyslov opened this issue Oct 14, 2020 · 6 comments · Fixed by #21 or #24

Comments

@dobromyslov
Copy link

I see you've done a plugin for compodoc which is required for Storybook Docs addon to be used with Angular as described here https://github.com/storybookjs/storybook/tree/master/addons/docs/angular. And looks like there is no another easy way to generate storydocs from Angular directly according to this discussion storybookjs/storybook#8672.

There is a milestone for the storydoc nx plugin in the twittwer/nx-tools readme. Do you have any plans to create it?

@twittwer
Copy link
Owner

I had paused my plans when I recognized the major changes that were planned for nx's Storybook plugin (v6). As the update is now released it would be time to reevaluate my plans - especially if there is an interest 🙂
Do you have any input, wishes or expectations?

@dobromyslov
Copy link
Author

dobromyslov commented Oct 15, 2020

Storybook plugin for NX (https://nx.dev/latest/angular/plugins/storybook/overview) lacks of Storybook Essential addons support (https://storybook.js.org/docs/angular/essentials/introduction). NX by now uses only old the knobs addon which will be substituted by the Storybook Controls some day.

Some excerpts from NX:

Storybook v6 moves from "knobs" to args and controls when it comes to defining and manipulating your storybook component properties. Feel free to use the new args way of defining stories. More can be found on the official Storybook docs.

Note: Nx does not yet automatically generate stories that use the args syntax. The main reason is that args don't yet support being loaded via the iframe URL which is used in Nx to setup your Storybook based e2e tests. Once support is present in Storybook v6, we will provide a way to generate args & controls based stories. More on the progress here (storybookjs/storybook#12291)

Also here is the requested Controls query params support feature storybookjs/storybook#12728. I guess it will be released very soon. But it's not enough to migrate to autogenerated Controls.

And here is why:

  1. Storybook Controls automatic generation is based on Storybook Docs.
  2. Storybook Docs does not generate automatically for Angular. It requires compodoc generated JSON file.
  3. You have to manually regenerate compodoc on each components change with npm run docs:json. Excerpt from https://github.com/storybookjs/storybook/tree/master/addons/docs/angular:

Unfortunately, it's not currently possible to update this dynamically as you edit your components, but there's an open issue to support this with improvements to Compodoc.

  1. NX has support for compodoc with @twittwer/compodoc. But it also requires projectname:compodoc:json
    execution after any change in components occurs.
  2. compodoc does not support --watch when it's exported in JSON format. Stated in [FEATURE] Support --watch with --exportFormat json compodoc/compodoc#862. This issue was added to the 1.1.12 milestone but was closed on Jun 25, 2020 due to inactivity.

How I configure NX workspace for Angular with Storybook Controls and Storybook Docs and Compodoc:

  1. ng add @twittwer/compodoc
  2. ng generate @twittwer/compodoc:config projectname --workspaceDocs
  3. ng run projectname:compodoc:json
  4. ng add @nrwl/storybook
  5. ng generate @nrwl/angular:storybook-configuration projectname
  6. Install Storybook Essentials addons and configure them in the NX workspace storybook as described here https://www.npmjs.com/package/@storybook/addon-essentials
  7. Tune configuration for Storybook Docs as described here https://github.com/storybookjs/storybook/tree/master/addons/docs/angular
  8. Create a story and export default with defined component.
  9. ng run projectname:storybook
  10. Rerun on each component change: ng run projectname:compodoc:json
  11. NX Storybook plugin is running in watch mode and it automatically reloads new compodoc JSON file.

It's quite complicated to bootstrap this stack and rerun commands but it works at least.

While I was writing this workflow I was thinking about the root cause again...
And I noticed that maybe it would be enough just to improve NX Storybook plugin to make it responsible for rerun of projectname:compodoc:json.

What do you think?

@twittwer
Copy link
Owner

@dobromyslov Thx for the detailed answer 👍

(A) The original idea was to create a wrapper plugin that will add a single architect with storybook & compodoc options and internally executes the 2 builders in order

(B) The simplest solution can be a schematic in the compodoc plugin that adds a run-command architect to execute compodoc & storybook in order.

(C) The next step could be a custom build that requires separate architects for compodoc & storybook and executes them in parallel while using e.g. nodemon for compodoc to achieve an auto regeneration of the docs metadata.

Option B is the solution I use currently at work for the workspace wide storybook.
I know this options don't fix the initial setup, but it maybe a first step - What do you think?
I could try to get some sort of POC in the next days.

@dobromyslov
Copy link
Author

@twittwer those are rather good options. (B) combined Compodoc & Storybook command helps a little on first Storybook start. Then it's running and watching for changes. And (C) option is needed to get rid of manual compodoc refresh.

I tried to run ng run projectname:compodoc:json --watch and it does not work. Looks like either your plugin does not pass --watch parameter to the compodoc or compodoc itself does not run in watch mode when used with JSON output format. I've not figured it out yet.

@twittwer
Copy link
Owner

The watch option was not passed to compodoc but that wouldn't work for the json format anyway => compodoc/compodoc#862

I just published version 1.4.0. on the next channel with a watch option as a first POC.

It worked in my scenario with the following steps:

  1. Add a watch configuration to your compodoc architect
"configurations": {
  "json": {
    "exportFormat": "json"
  },
  "watch": {
    "exportFormat": "json",
    "watch": true
  }
}
  1. Add a storydoc architect with a run-command builder:
"storydoc": {
  "builder": "@nrwl/workspace:run-commands",
  "options": {
    "commands": [
      "nx run <project>:compodoc:watch",
      "nx run <project>:storybook"
    ]
  }
}

This was linked to pull requests Oct 29, 2020
@manuelmeister
Copy link

Watchmode with json now works: compodoc/compodoc#1087

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants