Skip to content
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

[Themes] Add support for generating liquid and JSON section files #5090

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

jamesmengo
Copy link
Contributor

WHY are these changes introduced?

Adds support for generating theme sections with both Liquid and JSON file types, providing developers with more flexibility when creating new theme sections.

WHAT is this pull request doing?

  • Introduces a new generateSection service to handle section file creation
  • Adds support for both Liquid and JSON section file types
  • Implements file existence checks to prevent overwriting existing sections
  • Updates the section generator command to handle the new file type option
  • Adds comprehensive tests for the section generation functionality

How to test your changes?

  1. Run theme generate section and follow the prompts
  2. Choose between Liquid or JSON file types
  3. Verify the generated section file contains the correct structure
  4. Try generating a section with a name that already exists to test error handling

Measuring impact

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

Unused types (3)

Filename types
packages/theme/src/cli/services/generate/blocks.ts BlockGeneratorOptions
packages/theme/src/cli/utilities/generator.ts TemplateType
packages/theme/src/cli/services/generate/sections.ts SectionGeneratorOptions

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 75.27% 8780/11664
🟡 Branches 70.57% 4280/6065
🟡 Functions 74.98% 2295/3061
🟡 Lines 75.83% 8301/10947

Test suite run success

1981 tests passing in 896 suites.

Report generated by 🧪jest coverage report action from 9a241ab

@david-w-shopify
Copy link

Had a very quick play with this. A couple of comments

  1. I'd expect section groups (JSON sections) to be a separate command. Despite existing inside /sections they're so different to liquid sections that I wouldn't expect them to share a command. It would also remove an extra step from the section command which is a nice win. In my experience in agencies building Shopify themes - new Liquid sections are regularly created, JSON section groups are rarely created
  2. It would be nice to include a type field when generating the section group to populate that field in the schema. Perhaps if the user doesn't use header, footer or aside we could automatically prefix it with custom. too

@david-w-shopify
Copy link

Both section filename and schema "name" property match. This will result in users changing one or the other almost every time this command is used. I'd recommend converting the name to kebab case for the filename

Base automatically changed from jm/blocks_generator to jm/generators December 16, 2024 21:57
@jamesmengo jamesmengo merged commit 3c39897 into jm/generators Dec 16, 2024
23 of 27 checks passed
@jamesmengo jamesmengo deleted the jm/section_generator branch December 16, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants