patternlab-node icon indicating copy to clipboard operation
patternlab-node copied to clipboard

Add Preliminary Support For Javascript-based Configs

Open sghoweri opened this issue 6 years ago • 10 comments

Closes #999

WIP - adding preliminary support for dynamic JS-based configs.

Todos

  • [ ] Wire up cosmic config to allow support for .js and .json based configs with minimal overhead
  • [ ] Update existing tests to pass with updated config
  • [ ] Troubleshoot config getting overwritten with JSON-like output (have to revert every time atm
  • [ ] Finish updating docs / code comments

CC @EvanLovely

sghoweri avatar Mar 31 '19 12:03 sghoweri

OK, so it looks like plugins have the ability to "enable" and "disable" themselves by firing off a cli command that alters the patternlab-config.json for you:

enable.js: https://github.com/pattern-lab/patternlab-node/blob/4556fc7d12a1d11b401821919ff2f3ddc5658c93/packages/cli/bin/cli-actions/enable.js#L33-L34

There's one in disable.js too: https://github.com/pattern-lab/patternlab-node/blob/4556fc7d12a1d11b401821919ff2f3ddc5658c93/packages/cli/bin/cli-actions/disable.js#L35-L36

And another one in install.js as well: https://github.com/pattern-lab/patternlab-node/blob/4556fc7d12a1d11b401821919ff2f3ddc5658c93/packages/cli/bin/cli-actions/install.js#L61-L62

So since options.parent.config at this point is what we passed in via command line flag: patternlab-config.js, this writes a string of JSON to that file....

This is the ultimate low-level function that gets called that overwrites our file:

https://github.com/pattern-lab/patternlab-node/blob/992ebce457ccf5fd3221f5ab5bc3a4543e475e03/packages/cli/bin/utils.js#L184-L187

EvanLovely avatar Apr 06 '19 23:04 EvanLovely

Well, crap 💩 this will be a tough refactor with those in there. Perhaps keeping it json and then passing the string paths we get from it through resolvePkg might work? This function caught my eye:

https://github.com/pattern-lab/patternlab-node/blob/4556fc7d12a1d11b401821919ff2f3ddc5658c93/packages/cli/bin/replace-config.js#L5-L15

Or perhaps we can replace this:

      "patternlabFiles": {
        "general-header": "../uikit-workshop/views/partials/general-header.mustache",
        "general-footer": "../uikit-workshop/views/partials/general-footer.mustache",
        "patternSection": "../uikit-workshop/views/partials/patternSection.mustache",
        "patternSectionSubtype": "../uikit-workshop/views/partials/patternSectionSubtype.mustache",
        "viewall": "../uikit-workshop/views/viewall.mustache"
      },

with this:

      "patternlabFiles": {
        "general-header": "./node_modules/@pattern-lab/uikit-workshop/views/partials/general-header.mustache",
        "general-footer": "./node_modules/@pattern-lab/uikit-workshop/views/partials/general-footer.mustache",
        "patternSection": "./node_modules/@pattern-lab/uikit-workshop/views/partials/patternSection.mustache",
        "patternSectionSubtype": "./node_modules/@pattern-lab/uikit-workshop/views/partials/patternSectionSubtype.mustache",
        "viewall": "./node_modules/@pattern-lab/uikit-workshop/views/viewall.mustache"
      },

I tried that, but then I just now got this weird error and I'm not able to pursue further at the moment:

Pattern Lab Node v3.0.1-alpha.0
Pattern Engine mustache: good to go
Pattern Engine twig-php: good to go
Error: ENOENT: no such file or directory, open '/Users/Evan/dev/pl/pl--node/patternlab-node/packages/edition-twig/node_modules/@pattern-lab/uikit-workshop/node_modules/@pattern-lab/uikit-workshop/views/partials/general-header.mustache'

ERROR: missing an essential file from /Users/Evan/dev/pl/pl--node/patternlab-node/packages/edition-twig/node_modules/@pattern-lab/uikit-workshop[object Object]. Pattern Lab won't work without this file.

Incremental builds enabled.
⊙ patternlab → build: Yay, your Pattern Lab project was successfully built ☺

EvanLovely avatar Apr 07 '19 00:04 EvanLovely

OMG! The UI kits resolve those paths already relative to where they are! All this time I thought that ../uikit-workshop was going up and out of the the edition-twig directory and into the uikit-workshop directory but it WASN'T! It was going up and out of the uikit-workshop directory and then right back into that same directory!!!! 😆

This change fixes it!!

      "patternlabFiles": {
        "general-header": "views/partials/general-header.mustache",
        "general-footer": "views/partials/general-footer.mustache",
        "patternSection": "views/partials/patternSection.mustache",
        "patternSectionSubtype": "views/partials/patternSectionSubtype.mustache",
        "viewall": "views/viewall.mustache"
      },

PR up at #1003

EvanLovely avatar Apr 07 '19 00:04 EvanLovely

Did we already link in the doc/spec updates PR for this or do I need to go make one to https://github.com/pattern-lab/the-spec/ to update the spec & docs?

cybtachyon avatar Apr 14 '19 21:04 cybtachyon

Did we already link in the doc/spec updates PR for this or do I need to go make one to https://github.com/pattern-lab/the-spec/ to update the spec & docs?

@cybtachyon Spec? What spec? (Seriously, all I see is rough outline that hasn’t gotten updated in a long time).

IMHO, what we REALLY need is a schema that lives in the same repo as the rest of PL’s code (not a separate repo that’s guaranteed to go out of date). That’s the sort of thing that can get tested against, have documentation generated from it, and can get enforced.

sghoweri avatar Apr 16 '19 21:04 sghoweri

what we REALLY need is a schema that lives in the same repo as the rest of PL’s code (not a separate repo that’s guaranteed to go out of date). That’s the sort of thing that can get tested against, have documentation generated from it, and can get enforced.

@sghoweri would love to talk more about what's required to make that happen!

bradfrost avatar Jun 02 '19 01:06 bradfrost

It's hard to keep track of everything. This issue has been automatically marked as stale because it has not had recent activity, neither from the team nor the community. It will be closed if no further activity occurs. Please consider adding additional info, volunteering to contribute a fix for this issue, or making a further case that this is important to you, the team, and the project as a whole. Thanks!

stale[bot] avatar Aug 01 '19 01:08 stale[bot]

is .patternlabrc.js used by the uikit right now?

@bmuenzenmeyer It is!

sghoweri avatar Aug 23 '19 20:08 sghoweri

@sghoweri I am likely going to use this heavily as a reference but pivot to a new approach. are you alright with that?

bmuenzenmeyer avatar Feb 09 '20 20:02 bmuenzenmeyer

👍🏼

sghoweri avatar Feb 09 '20 21:02 sghoweri

Closing this for now, trying to implement it in a second approach.

JosefBredereck avatar Feb 12 '23 17:02 JosefBredereck