-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
refactor: allow .json extension on annotations file #836 #1402
refactor: allow .json extension on annotations file #836 #1402
Conversation
How do you find stuff like this all the time? That's crazy 😄 |
@JosefBredereck … oh, don't ask … ;-) others read novels, I read git commit history … |
logger.info( | ||
`Please convert ${jsPath} to JSON and rename it annotations.json.` | ||
); |
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'm a bit on the fence with that. We should let the user decide if he wants to use JS or JSON, even in the future.
Furthermore, we could check if it is possible to require
that .js
or .json
file so that we do not have to strip comments and anything else in that file. Maybe we can change the way it needs to be written to a module.exports
format.
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.
@JosefBredereck, actually I've realized that we're stripping that var comments
part first of all, to add it again on exporting the data:
'var comments = { "comments" : ' + JSON.stringify(annotationsJSON) + '};'; |
So another solution might be to skip that whole transition to a pure JSON file and only provide the possibility with using JS (the existing format), but remove the JSON file possibility, as we're even already providing another format with the markdown notation as well.
So another task for this ticket could be still to correct the documentation part anyhow: https://patternlab.io/docs/adding-annotations/#heading-json-example
What do you think?
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.
No way 😄. In that case, throw away those nasty JSON files 🗑️
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.
okay, sounds reasonable to me. I've set this ticket on draft again and will proceed by removing these parts as well as the nasty existing transitions in the codebase, as well as correct the documentation page.
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.
The whole file you mentioned is a solution, but if we would rework the codebase with today's standards, we would maybe not do it that way.
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.
so does it mean that you want to come up with (or at least describe) a solution ?
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.
Not for now; it would require a more significant rewrite.
This line shows that we already work with modules somewhere.
'module.exports = { config, ishControls, navItems, patternPaths, viewAllPaths, plugins, defaultShowPatternInfo, defaultPattern };'; |
But then we also need to adjust the place where we load those annotations again.
What makes me curious. Annotations always have a comments property and no other. Is it possible that they have different properties? If not, this would be another change I would like to implement somehow.
'var comments = { "comments" : ' + JSON.stringify(annotationsJSON) + '};'; |
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.
No way 😄. In that case, throw away those nasty JSON files 🗑️
@JosefBredereck, on the other hand, besides the strange way to include the JSON data into the website after a transformation, the positive way of using JSON (even only) would be that this adapts the way other data is being maintained in the pattern lab system (like pattern data).
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.
That is correct. Nodejs is so fast in transforming the data that we could use the approach that is already in this PR. In the end, it makes no difference.
Another thing I just discovered and never understood: The annotations are written once and visible on all patterns there are available. Why should I want that? |
well, they are as global as the global data, but there's no "scoped" or "local" annotations, related to a pattern even only. This even also made me wonder. Probably this would be a nice enhancement / future feature ? |
Or I'm just blind. There is the |
Some minor adjustment is standing out after the merge of #1406 |
good catch, thanks. Just checked in the migrated file. |
PR was released with v5.16.0 |
Summary of changes:
As the original implementation by @engelfrost (kudos for that!) accidentally got reverted with commit 9c49a09, we should add that nice refactoring again to ensure that annotations JSON files could get used with the correct filetype / file-ending, and even also advocate for that file-ending from now on.
@engelfrost implementation even also ensured backwards compatibility, so this wouldn't be a breaking change.
The resulting implementation could get reviewed on https://deploy-preview-1402--patternlab-handlebars-preview.netlify.app/?p=viewall-molecules-global&view=annotations and https://deploy-preview-1402--patternlab-handlebars-preview.netlify.app/?p=pages-homepage&view=annotations
There's still a problem with displaying the tooltips on the "standalone" view (in our example for the header), as the general styles from
pattern-lab.css
aren't included in this view.This problem is unrelated to the fixes in this pull request and I've opened another pull request for that to fix: #1406