Class: Node::Commands::Generate::Page

Inherits:
ShopifyCli::SubCommand show all
Defined in:
lib/project_types/node/commands/generate/page.rb

Constant Summary collapse

PAGE_TYPES =
{
  'empty-state' => ['./node_modules/.bin/generate-node-app', 'empty-state-page'],
  'two-column' => ['./node_modules/.bin/generate-node-app', 'two-column-page'],
  'annotated' => ['./node_modules/.bin/generate-node-app', 'settings-page'],
  'list' => ['./node_modules/.bin/generate-node-app', 'list-page'],
}

Instance Attribute Summary

Attributes inherited from ShopifyCli::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCli::SubCommand

call

Methods inherited from ShopifyCli::Command

call, call_help, #initialize, options, prerequisite_task, run_prerequisites, subcommand, subcommand_registry

Methods included from ShopifyCli::Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCli::Command

Class Method Details

.helpObject



53
54
55
# File 'lib/project_types/node/commands/generate/page.rb', line 53

def self.help
  ShopifyCli::Context.message('node.generate.page.help', ShopifyCli::TOOL_NAME)
end

Instance Method Details

#call(args, _name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/project_types/node/commands/generate/page.rb', line 20

def call(args, _name)
  name = args.first
  flag = options.flags[:type]
  unless name
    @ctx.puts(self.class.help)
    return
  end

  selected_type = if flag
    unless PAGE_TYPES.key?(flag)
      @ctx.abort(@ctx.message('node.generate.page.error.invalid_page_type'))
    end
    PAGE_TYPES[flag]
  else
    CLI::UI::Prompt.ask(@ctx.message('node.generate.page.type_select')) do |handler|
      PAGE_TYPES.each do |key, value|
        handler.option(key) { value }
      end
    end
  end
  page_type_name = PAGE_TYPES.key(selected_type)
  selected_type[0] = File.join(ShopifyCli::Project.current.directory, selected_type[0])
  selected_type[0] = "\"#{selected_type[0]}\""
  selected_type = selected_type.join(' ')

  spin_group = CLI::UI::SpinGroup.new
  spin_group.add(@ctx.message('node.generate.page.generating', page_type_name)) do |spinner|
    Node::Commands::Generate.run_generate("#{selected_type} #{name}", name, @ctx)
    spinner.update_title(@ctx.message('node.generate.page.generated', name, name))
  end
  spin_group.wait
end