Class: Node::Commands::Generate::Webhook

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

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



31
32
33
# File 'lib/project_types/node/commands/generate/webhook.rb', line 31

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

Instance Method Details

#call(args, _name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/project_types/node/commands/generate/webhook.rb', line 7

def call(args, _name)
  selected_type = args.first
  schema = ShopifyCli::AdminAPI::Schema.get(@ctx)
  webhooks = schema.get_names_from_type('WebhookSubscriptionTopic')
  unless selected_type && webhooks.include?(selected_type)
    selected_type = CLI::UI::Prompt.ask(@ctx.message('node.generate.webhook.type_select')) do |handler|
      webhooks.each do |type|
        handler.option(type) { type }
      end
    end
  end

  generate_path = File.join(ShopifyCli::Project.current.directory, "node_modules/.bin/generate-node-app")
  generate_path = "\"#{generate_path}\""

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