-
Notifications
You must be signed in to change notification settings - Fork 405
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
Add Preliminary Support For Javascript-based Configs #1000
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if we can get backwards compatibility with the .json
format in addition to the new .js
format.
packages/core/src/lib/patternlab.js
Outdated
@@ -36,8 +36,7 @@ module.exports = class PatternLab { | |||
constructor(config) { | |||
// Either use the config we were passed, or load one up from the config file ourselves | |||
this.config = | |||
config || | |||
fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json')); | |||
config || require(path.resolve(__dirname, '../../patternlab-config.js')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we just do this instead and then either .json
or .js
(or even patternlab-config/index.js
) would work? Backwards compatible so previous installs do not error if they have .json
and might even help with some of the other problems you've mentioned.
- require(path.resolve(__dirname, '../../patternlab-config.js'))
+ require(path.resolve(__dirname, '../../patternlab-config'))
'../uikit-workshop/views/partials/patternSection.mustache', | ||
patternSectionSubtype: | ||
'../uikit-workshop/views/partials/patternSectionSubtype.mustache', | ||
viewall: '../uikit-workshop/views/viewall.mustache', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we need require.resolve()
on all these uikit-workshop
paths too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1225
'../uikit-workshop/views/partials/patternSection.mustache', | ||
patternSectionSubtype: | ||
'../uikit-workshop/views/partials/patternSectionSubtype.mustache', | ||
viewall: '../uikit-workshop/views/viewall.mustache', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moar require.resolve()
spots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1225
OK, so it looks like plugins have the ability to "enable" and "disable" themselves by firing off a cli command that alters the
patternlab-node/packages/cli/bin/cli-actions/enable.js Lines 33 to 34 in 4556fc7
There's one in patternlab-node/packages/cli/bin/cli-actions/disable.js Lines 35 to 36 in 4556fc7
And another one in patternlab-node/packages/cli/bin/cli-actions/install.js Lines 61 to 62 in 4556fc7
So since This is the ultimate low-level function that gets called that overwrites our file: patternlab-node/packages/cli/bin/utils.js Lines 184 to 187 in 992ebce
|
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 patternlab-node/packages/cli/bin/replace-config.js Lines 5 to 15 in 4556fc7
Or perhaps we can replace this:
with this:
I tried that, but then I just now got this weird error and I'm not able to pursue further at the moment:
|
OMG! The UI kits resolve those paths already relative to where they are! All this time I thought that This change fixes it!!
PR up at #1003 |
# Conflicts: # packages/edition-twig/package.json # packages/edition-twig/patternlab-config.json
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 would love to talk more about what's required to make that happen! |
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! |
|
||
module.exports = { | ||
engines: { | ||
twig: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
twig engine should not be in core?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am excited for this !
think it'd be a good time to change to .patternlabrc.js
? it's the shortest and aligns with recommended config defaults for eslint => .eslintrc.js
is .patternlabrc.js
used by the uikit right now?
@bmuenzenmeyer It is! |
@sghoweri I am likely going to use this heavily as a reference but pivot to a new approach. are you alright with that? |
👍🏼 |
Closing this for now, trying to implement it in a second approach. |
Closes #999
WIP - adding preliminary support for dynamic JS-based configs.
Todos
.js
and.json
based configs with minimal overheadCC @EvanLovely