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

Publish Nunjucks templates to NPM #265

Open
james-nash opened this issue May 19, 2019 · 1 comment
Open

Publish Nunjucks templates to NPM #265

james-nash opened this issue May 19, 2019 · 1 comment
Labels
buildit-website CONSUMER: Indicates that this is required by the Buildit website infrastructure CATEGORY: Infrastructure related - e.g. updates to build process, tests, tooling, etc. 🌟 enhancement TYPE: Indicates new feature requests

Comments

@james-nash
Copy link

Is your feature request related to a problem? Please describe.
We maintain a set of HTML templates (written in Nunjucks) for our pattern library. Those same templates could be useful for downstream consumers such as the Buildit website, so we should publish them as an @buildit/gravity-ui-nunjucks NPM package.

A while ago we decided to work towards that by:

  1. Converting to a Lerna monorepo, so that we could have code for multiple NPM packages in one repo
  2. Split out the templates + pattern library code into its own package
  3. Setup the necessary conversions and builds to publish the templates to the NPM package repo

This issue is to cover the last and final step.

Describe the solution you'd like
First off, it's best to wait for the migration to Fractal (#264) to complete, since that affects the structure of the templates.

Once that's in place, we'll need to figure out how to make the templates usable without Fractal (which has it's own @.. shorthand naming scheme for importing/including other templates). Possible options are:

  • Export copies of the templates and find'n'replace the shorthand names with relative file paths. (Fractal's own docs have an example of something like this)
  • Or, write a custom Nunjucks loader, which can "understand" the same @... shorthand.
  • There may be other options, or the above could be combined somehow. In any case, this needs some more research

With a solution to the above in place, we should then get semantic-release enabled and configured properly for the @buildit/gravity-ui-nunjucks package and get it published.

@james-nash james-nash added this to the Gravity NEXT milestone May 19, 2019
@james-nash james-nash added 🌟 enhancement TYPE: Indicates new feature requests buildit-website CONSUMER: Indicates that this is required by the Buildit website infrastructure CATEGORY: Infrastructure related - e.g. updates to build process, tests, tooling, etc. labels May 19, 2019
@james-nash james-nash removed this from the Gravity NEXT milestone Jan 2, 2020
@james-nash
Copy link
Author

In a personal project I have managed to pull this off using the approach outlined in Fractal's docs, i.e. exporting copies of the template files somewhere into the dist/ dir and then shipping those in an NPM package.

It's relatively straightforward for consuming projects to then configure their Nunjucks environment to look for templates in that directory (and our build-api can assist with this) in addition to whatever local template directory(-ies) they have.

However, I think we need to be picky about which templates we export. There's little value in all the ones that are "just" plain HTML elements. Likewise templates and pages probably shouldn't be published either.

I reckon (non-element) atoms, molecules and organisms are the sweet spot.

Unfortunately our current organisation is a mess. Also, in a misguided attempt to get lineage links for ALL THE THINGS, I regretfully overengineered and entangled our Nunjucks templates.

As a way forward, I therefore propose:

  1. We reorganise our pattern library - see Re-organise pattern library #309
    • Now with the added constraint that atom / molecule / organism Nunjucks templates must not reference basic HTML element templates. This is because we'd exclude those in our NPM package and such references would then be broken.
  2. We remove gunk like 'section' - see Remove section "component" #276

Then we can update our build to copy out the templates we want to ship and publish them to NPM, which will be covered by this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buildit-website CONSUMER: Indicates that this is required by the Buildit website infrastructure CATEGORY: Infrastructure related - e.g. updates to build process, tests, tooling, etc. 🌟 enhancement TYPE: Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

1 participant