chrislopresto / ember-freestyle

Create a component explorer for your Ember app
https://chrislopresto.github.io/ember-freestyle
MIT License
269 stars 83 forks source link

Automatic discovery of components to include in freestyle guide #176

Open lukemelia opened 6 years ago

lukemelia commented 6 years ago

This issue lays out a plan for adding automatic discovery of content for the styleguide.

This plan takes some inspiration from @Turbo87's blog post Autodiscovery for the Ember.js component playground but imagines a different approach then outlined in the post.

The goal is to reduce the friction and busy-work of adding and updating components to your freestyle guide. Specifically, it allows for colocating a "freestyle" component with the component is is demonstrating and removes the need to edit the main freestyle.hbs template, which otherwise can become unwieldy in large apps.

There are two parts of the plan:

  1. Build-time discovery via ember-cli hook
  2. Run-time generation with a component and service pair

There are also number of related ideas to improve the experience further.

Here are some details on the above, followed by a step-by-step plan:

1) Build-time discovery via ember-cli hook

ember-freestyle will discover components from app's file structure at build time. This will be implemented via the preprocessTree hook and a configurable set of path patterns for which matching files will be considered components to be included. Those component names will be written to a "manifest" module for consumption at run-time.

The proposed default file path patterns are:

TODO: What additional patterns, if any, are necessary to support:

The manifest module will be named -freestyle/discovered-components.js and export an array of the discovered component names.

2) Run-time generation with a component and service pair

The ember-freestyle service will be updated to import the manifest module that is generated at build time and expose it as a property named discoveredComponents on the service.

A new component will be provided by ember-freestyle to allow including these discovered components. It will looks like this in the generated freestyle.hbs template:

  {{freestyle-auto}}

This component will iterate over the discoveredComponents array from the service and use the component helper to output each component.

Related ideas

Detailed implementation steps:

Other ideas:

Turbo87 commented 6 years ago

@lukemelia the reason why we're not colocating the files is that we don't want to ship them with the production app, and having them in an in-repo-addon means that we can disable the addon for the production build. maybe I missed it, but that does not seem to be mentioned in the plan above? 🤔

lukemelia commented 6 years ago

@Turbo87 Thanks for that reminder! This is something I discussed with @chrislopresto but didn't make it in the doc. I have now updated.