Giter Club home page Giter Club logo

Comments (6)

dobromyslov avatar dobromyslov commented on June 3, 2024 7

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 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?

from nx-tools.

twittwer avatar twittwer commented on June 3, 2024 5

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"
    ]
  }
}

from nx-tools.

twittwer avatar twittwer commented on June 3, 2024 2

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?

from nx-tools.

twittwer avatar twittwer commented on June 3, 2024

@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.

from nx-tools.

dobromyslov avatar dobromyslov commented on June 3, 2024

@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.

from nx-tools.

manuelmeister avatar manuelmeister commented on June 3, 2024

Watchmode with json now works: compodoc/compodoc#1087

from nx-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.