Class: ShopifyThemeBuilder::CommandLine

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/shopify_theme_builder/command_line.rb

Overview

CommandLine class to handle CLI commands using Thor.

Constant Summary collapse

SUPPORTED_TYPES =
%w[section block snippet].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/shopify_theme_builder/command_line.rb', line 13

def name
  @name
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/shopify_theme_builder/command_line.rb', line 13

def type
  @type
end

Class Method Details

.source_root ⇒ Object



15
16
17
# File 'lib/shopify_theme_builder/command_line.rb', line 15

def self.source_root
  File.expand_path("../..", __dir__)
end

Instance Method Details

#generate ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/shopify_theme_builder/command_line.rb', line 48

def generate
  @type = options[:type]
  @name = options[:name]
  folder = options[:folder]

  until ShopifyThemeBuilder::CommandLine::SUPPORTED_TYPES.include?(@type)
    unless @type.nil?
      say_error "Error: Unsupported type '#{@type}'.\
 Supported types are: #{ShopifyThemeBuilder::CommandLine::SUPPORTED_TYPES.join(", ")}"
    end

    @type = ask(
      "Enter component type (section, block or snippet):",
      limited_to: ShopifyThemeBuilder::CommandLine::SUPPORTED_TYPES
    )
  end

  @name = ask("Enter component name (E.g., Slideshow):") if @name.nil?

  folder = ask("Enter folder to generate the component in:", default: "_components") if folder.nil?

  directory "generators", "#{folder}/#{@name.parameterize(separator: "_")}", exclude_pattern:
end

#install ⇒ Object



38
39
40
41
42
# File 'lib/shopify_theme_builder/command_line.rb', line 38

def install
  add_tailwind_to_theme
  add_stimulus_to_theme
  add_watcher_to_procfile
end

#watch ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/shopify_theme_builder/command_line.rb', line 27

def watch
  ShopifyThemeBuilder.watch(
    folders_to_watch: options[:folders],
    tailwind_input_file: options[:tailwind_input_file],
    tailwind_output_file: options[:tailwind_output_file],
    skip_tailwind: options[:skip_tailwind],
    stimulus_output_file: options[:stimulus_output_file]
  )
end