Skip to content

Add install command to CLI interface#20

Merged
MassimilianoLattanzio merged 6 commits intomainfrom
massimilianolattanzio/add-install-command
Jan 13, 2026
Merged

Add install command to CLI interface#20
MassimilianoLattanzio merged 6 commits intomainfrom
massimilianolattanzio/add-install-command

Conversation

@MassimilianoLattanzio
Copy link
Member

@MassimilianoLattanzio MassimilianoLattanzio commented Jan 13, 2026

This PR adds a new install command to the theme builder CLI that sets up all the necessary files for a Shopify theme project.

Changes

  • Add install command to CLI interface that:
    • Injects Tailwind CSS configuration and assets
    • Injects Stimulus JS controller setup
    • Creates a Procfile.dev for running the theme watcher
    • Updates the README with installation instructions

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 install command 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.

Comment on lines +109 to +162
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
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@MassimilianoLattanzio MassimilianoLattanzio force-pushed the massimilianolattanzio/add-install-command branch from 5dbf0e6 to 4d9e665 Compare January 13, 2026 20:15
@MassimilianoLattanzio MassimilianoLattanzio merged commit 4a42bf2 into main Jan 13, 2026
5 checks passed
@MassimilianoLattanzio MassimilianoLattanzio deleted the massimilianolattanzio/add-install-command branch January 13, 2026 20:18
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