-
Notifications
You must be signed in to change notification settings - Fork 363
Now sections can have separate .json file for schema. #954
Conversation
This module exports function to inject separately placed `section_name.schema.json` file into respective `section_name.liquid` file. It checks, if liquid file has already set `{% schema %}` or not, and injects it to result `section_name.liquid` file which will be placed in `dist/sections` directory.
Now sections has ability to have separately placed json files to be used as schema. The idea is: We have section files in `/src/sections/` like `/src/sections/section_name.liquid` and to simplify editing of section's schema which is json We now can create just `/src/sections/section_name.schema.json` file and it'll be injected to same named section liquid file upon build process and be placed wrapped with right `{% schema %}` tags in `/dist/sections/section_name.liquid` Same logic can be implemented for Scripts and Styles. But i consider Slate's approach is to separate JS and CSS\SCSS out of sections to be built with webpack instead of having them inlined in sections, even Shopify supports it.
Very cool! Thanks @MikhailRoot. Will give this a review. @harshal317 This might be helpful for your work on section locales. |
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
packages/slate-tools/tools/webpack/config/utilities/inject-schemas-to-sections.js
Outdated
Show resolved
Hide resolved
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
…emas-to-sections.js Co-Authored-By: MikhailRoot <durnevM@mail.ru>
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.
Thank you for checks, and sorry for some typo errors.
Hehe sorry typos were bugging me |
I've signed Shopify's CLA, but i don't know how to trigger recheck. |
Done! There are some linter errors in the CI check though. |
Rather than include by convention (matching section name), could you not use this same approach to enable something like {% schema 'section_schema.json' %} with no closing tag, like {% include ... %} The function could look for the .json file specified in the parameter, and then inject it into the page, wrapped in a real open and closing {% schema %} tag. That way you could solve the (very very useful) issue brought up in #749 |
added `{% inject 'file_name_to_inject.json|whatever' %}` path of file to inject is relative to liquid file we inject to, and is resolved via `path.resolve()`. NB: approach to insert {% schema %} with a separate file named `section-name.schema.json` will work only if there's no `{% schema %}` tag defined in liquid file, so these approaches will not conflict or overwrite each other.
@disantlor thank you for idea, i've implemented it like |
Now with My original approach by naming convention still works. |
Sorry, closed PR by accident. Reopened it :) |
@MikhailRoot could you confirm that an edit to the schema json file triggers a Webpack rebuild when running |
@t-kelly Yes, changing |
Hey @MikhailRoot -- First off, thanks for taking the time and working on this great addition to Slate. As you can see in #856 -- this is something we've thought of and wanted to move on. Coincidentally, you opened this PR just as @harshal317 started working on it. I had him review your PR and we were have both seriously considered using it and expanding upon it. However, we have both come to the opinion that we would like this functionality to live in its own Webpack plugin, and not depend on CopyWebpackPlugin. All this to say, expect a PR in the next few weeks from Harshal. We would love your feedback on it and will cc you when its posted! Also, in the future, as we mention in the CONTRIBUTING.md:
It helps to post that you're intending to work on something so we know what's up and let you know if we're already working on it! |
Would it be possible to add The way I see this working is by using |
@davidwarrington copying your comment into #982. Please continue the conversation there! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Now sections can have separate .json file for schema.
If we have
section_name.schema.json
file in same directory assection_name.liquid
file it will inject it as a{% schema %}
for this section while placing it in/dist/sections
directory.It checks if
section_name.liquid
has inline definition and does nothing if it has it inline.If
section_name.liquid
don't have neithersection_name.schema.json
neither inline{% schema %}
declaration in it, it outputs a warning.The win of this approach is simplifying json editing leading to less errors in schema declaration. Also you have good syntax highlighting in editor of choice for .json files for sure.
#749
#856
Checklist
For contributors:
For maintainers: