patternlab-php-core icon indicating copy to clipboard operation
patternlab-php-core copied to clipboard

Symfonize all the things!

Open aleksip opened this issue 8 years ago • 10 comments

I'd like to propose refactoring Pattern Lab PHP to use Symfony components and best practices as much as possible.

Pros:

  • Less custom code.
  • Pattern Lab PHP already uses several Symfony components.
  • Code is more approachable by people who know Symfony, making it easier to contribute.
  • Same skills can also be used in other projects like Drupal and Drupal Console. Lots of synergy opportunities!
  • Current static classes cause tight coupling and are bad for unit testing.
  • Dependency injection and decoupling console commands from business logic could make all kinds of interesting things possible...

Cons:

  • ?

Background:

The secret plan I mentioned in #150 was to replace Pattern Lab's console code with Symfony's Console component. My experiments with that have been very positive, but I quickly realized that a full rewrite using dependency injection and separation of concerns would be really nice. Or at least something I'd be very interested in and motivated to do! :)

Implementation plan:

We could add new Symfonized implementations of PL core code, with the old console commands using the old code and the new console commands using the new code. And when the time is right, we'd just leave out all the old code and release PL 3.0.

Tasks:

  • [ ] Decouple editions from core #155

aleksip avatar Nov 12 '17 19:11 aleksip

I love this approach! Let’s do it.

EvanLovely avatar Nov 12 '17 19:11 EvanLovely

Ditto - love love love love this idea. Count me in!

sghoweri avatar Nov 12 '17 20:11 sghoweri

Was literally poking in the guts of PL this week looking to live-route requests instead of writing to the filesystem and was inching toward this direction.

illepic avatar Nov 12 '17 20:11 illepic

@illepic I was literally doing the same thing last weekend! I came up with a POC giving PL the ability to render individual patterns via a tiny PHP server instance (aka let Node get PL rendered HTML if you pass the service a pattern name + data to pass in)... kind of like a mini Pattern Lab web service....

Will try to get code posted today or tomorrow!!

sghoweri avatar Nov 12 '17 20:11 sghoweri

Get out of my head @sghoweri, this is MY EXACT USE CASE. Let me guess, you've Webpack'd pretty much everything and this is the last bit needed to get this output on the "dependency chain" of a component?

Guess where we're heading here: https://github.com/phase2/pattern-lab-starter/tree/epic/v10.

illepic avatar Nov 12 '17 21:11 illepic

@illepic

Get out of my head @sghoweri, this is MY EXACT USE CASE. Let me guess, you've Webpack'd pretty much everything and this is the last bit needed to get this output on the "dependency chain" of a component?

Ding ding ding ding ding! Bingo. But that's not all.

The TLDR; version is that our Design System uses Lerna for versioning & publishing standalone components, ITCSS to organize and scale shared design tokens, mixins, etc, and Gulp + Webpack to glue everything together.

Unfortunately we just keep hitting more and more hurdles with the way Pattern Lab works and expects things... (and mind you, this is after coming up with around a dozen patches to help address some of these)

Just to name a few things I'm looking solve w/ this incremental / route-based rendering POC:

  1. Extremely long compile times when running Pattern Lab as a Design System monorepo (node_modules installed at the component level) since the PHP version of PL can't focus on just the patterns needed per request / incrementally.
  2. Extremely heavy (borderline unusable) Styleguide View All page
  3. Resolving the Webpack dependency chain / shared modules to optimize how things get bundled / chunked / asynced.
  4. Compiling test patterns to their own local dist folder for running regression tests (ie. better encapsulation) - similar to what we're already started doing w/ Webpack
  5. Schema validation + the ability to render patterns via a query string (inline editing similar to what Pattern Kit was doing)
  6. Decouple Styleguidekit Assets Default from PL core itself (major refactor, replace current Search, etc)
  7. Help w/ server-side rendering, especially considering the web component route we've been taking more recently
  8. Config patterns / define pattern variations in a single JavaScript file (cough Fractal cough)

sghoweri avatar Nov 13 '17 13:11 sghoweri

So great that we are all thinking along the same lines! :)

Updated title accordingly and created first task/sub-issue.

aleksip avatar Nov 13 '17 14:11 aleksip

Hey all! This all sounds fantastic, and while the technical details are well over my head, I just wanted to come in to simultaneously give a big 👍 and also a bit of a word of warning.

We want to make sure that PL continues to be an accessible and relatively lightweight tool in terms of dependencies. Based on what I'm hearing you all say, it sounds like this initiative is a bit of a behind-the-scenes refactoring to use Symfony's well-established conventions so there's less reinventing the wheel on PL's part. That all sounds great, and even better it helps address your specific project needs. So long as this is also useful for other PL users and it's done in an implementation-agnostic way, I'm all for it!

bradfrost avatar Nov 13 '17 16:11 bradfrost

@bradfrost Thanks! This is indeed more of a behind-the-scenes type of thing, and everything should work as before for end users.

aleksip avatar Nov 13 '17 16:11 aleksip

@aleksip @EvanLovely @illepic if you guys were curious, here's the working Patternlab PHP Renderer POC I've been working on with the main server logic just being a little under 30 lines of code:

https://github.com/sghoweri/patternlab-php-renderer/blob/feature/patternlab-server-poc/index.php

And on the client side (once a PHP Server is running), you can have Node ping that server with the Pattern + Data and if everything is working, it'll respond with the rendered HTML: https://github.com/sghoweri/patternlab-php-renderer/blob/feature/patternlab-server-poc/render.js

Still lots to do (especially w/ documenting all this + pointing out the small patch I had to add) but all in all this seems really promising!!

Hoping to try to get the iFrame viewer in PL wired up to this as a logical next step!

sghoweri avatar Nov 14 '17 11:11 sghoweri