Add install command to CLI interface#20
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new install command to the theme builder CLI that automates the setup process for integrating Tailwind CSS and Stimulus JS into a Shopify theme project.
Changes:
- Add
installcommand that injects Tailwind CSS and Stimulus JS tags into theme layout files - Add Procfile.dev integration to include the theme watcher command
- Update README to document the new install command and remove manual setup instructions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/shopify_theme_builder/command_line.rb | Implements the install command with helper methods for injecting Tailwind CSS, Stimulus JS, and updating Procfile.dev |
| spec/shopify_theme_builder/command_line_spec.rb | Comprehensive test coverage for the install command covering various scenarios and edge cases |
| README.md | Documents the new install command and removes now-obsolete manual setup instructions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def add_tailwind_to_snippet(theme_file_path, theme_file, injection_tag) | ||
| File.write(theme_file_path, "#{theme_file.chomp}\n#{injection_tag}\n") | ||
| say "Injected Tailwind CSS tag into #{theme_file_path}.", :green | ||
| end | ||
|
|
||
| def add_tailwind_to_layout(theme_file_path, theme_file, injection_tag) | ||
| stylesheet_tag_regex = | ||
| /(\{\{\s*['"][^'"]+['"]\s*\|\s*asset_url\s*\|\s*stylesheet_tag(?:\s*:\s*((?!\}\}).)*)?\s*\}\})/ | ||
| if theme_file.match?(stylesheet_tag_regex) | ||
| updated_content = theme_file.sub( | ||
| stylesheet_tag_regex, | ||
| "\\1\n#{injection_tag}" | ||
| ) | ||
| File.write(theme_file_path, updated_content) | ||
| say "Injected Tailwind CSS tag into #{theme_file_path}.", :green | ||
| else | ||
| say_error "Error: Could not find a way to inject Tailwind CSS. Please manually add the CSS tag.", | ||
| :red | ||
| end | ||
| end | ||
|
|
||
| def add_stimulus_to_theme | ||
| theme_file_path = | ||
| if File.exist?("snippets/scripts.liquid") | ||
| "snippets/scripts.liquid" | ||
| elsif File.exist?("layout/theme.liquid") | ||
| "layout/theme.liquid" | ||
| end | ||
|
|
||
| unless theme_file_path | ||
| say_error "Error: Could not find a theme file to inject Stimulus JS.", :red | ||
| return | ||
| end | ||
|
|
||
| theme_file = File.read(theme_file_path) | ||
|
|
||
| if theme_file.include?("controllers.js") | ||
| say "Stimulus JS already included in #{theme_file_path}. Skipping injection.", :blue | ||
| return | ||
| end | ||
|
|
||
| injection_tag = "<script type=\"module\" defer=\"defer\" src=\"{{ 'controllers.js' | asset_url }}\"></script>" | ||
|
|
||
| if theme_file_path == "snippets/scripts.liquid" | ||
| add_stimulus_to_snippet(theme_file_path, theme_file, injection_tag) | ||
| else | ||
| add_stimulus_to_layout(theme_file_path, theme_file, injection_tag) | ||
| end | ||
| end | ||
|
|
||
| def add_stimulus_to_snippet(theme_file_path, theme_file, injection_tag) | ||
| File.write(theme_file_path, "#{theme_file.chomp}\n#{injection_tag}\n") | ||
| say "Injected Stimulus JS tag into #{theme_file_path}.", :green | ||
| end |
There was a problem hiding this comment.
The methods add_tailwind_to_snippet and add_stimulus_to_snippet contain duplicated logic. Consider extracting this into a shared helper method (e.g., add_tag_to_snippet) that accepts the file path, file content, and injection tag as parameters to reduce code duplication and improve maintainability.
There was a problem hiding this comment.
Since it's not part of the library, but just a utility command, it's fine as it is.
Introduces a new install command to provide installation steps for users setting up the theme builder.
Enhances the install process by automatically injecting Tailwind CSS stylesheet tags into theme files.
Extends the install command to automatically inject Stimulus JS into Shopify themes alongside existing Tailwind CSS injection.
Automatically adds the theme-builder watch command to Procfile.dev during installation when the file exists.
And simplifies setup instructions.
5dbf0e6 to
4d9e665
Compare
This PR adds a new
installcommand to the theme builder CLI that sets up all the necessary files for a Shopify theme project.Changes
installcommand to CLI interface that: