drupal-pattern-lab / patternlab-php-core

This repository provides the core functionality for Pattern Lab. It is meant to be used from within an Edition with a PatternEngine and StarterKit.
http://patternlab.io/
MIT License
2 stars 1 forks source link

Working solution to regenerate missing styleguideKit index.html in the public directory #15

Closed sghoweri closed 7 years ago

sghoweri commented 7 years ago

Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14 if we are ok with this only getting triggered if the index.html file is missing in our public directory (vs check if every single styleguidekit asset is in it's proper place).

I'm also not a huge fan of having to hard-code the dist folder to guess which specific files need to get copied over but the baked in mechanism getting used in PL to normally handle this is so incredibly tied in with the composer install events, this was the simplest solution I could come up with without trying to impersonate composer (or something even crazier) @_@

To test locally, update your composer.json file to point at this feature branch, remove your vendor folder + composer.lock file and go through the steps from the original ticket.

"require": {
    "php": ">=5.4",
    "pattern-lab/core": "dev-feature/resilient-public-dir as 2.0.0",
    "pattern-lab/patternengine-twig": "^2.0.0",
    "pattern-lab/styleguidekit-assets-default": "^3.0.0",
    "pattern-lab/styleguidekit-twig-default": "^3.0.0"
},

Should now work as expected!

Author's note: OMG TABS & WHITESPACE AHHHHH

EvanLovely commented 7 years ago

@sghoweri Nice work! I can confirm it works, but I bet we can get paths in a more resilient way. I just added commit 0eace9e to this that adds a $kit_path var that is an absolute path to the styleguide kit folder in the vendor directory, so we should be able to reduce some lines. Can we get it so we don't need that $base var? Would be nice to not have to rely on the brittleness of /../../../.

sghoweri commented 7 years ago

@EvanLovely can you take another look at this when you get a chance?

Unfortunately the $kit_path variable you added actually points to the /vendor/pattern-lab/styleguidekit-twig-default package instead of the OTHER styleguideKit we actually need here (styleguidekit-assets-default, or whatever is currently installed).

I consolidated that little bit of logic to now use the baseDir config option instead which should hopefully be a little less prone to breaking. Lemme know what you think!

EvanLovely commented 7 years ago

Released in v2.8.1 ~ https://github.com/drupal-pattern-lab/patternlab-php-core/releases/tag/v2.8.1