shopify-cli 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/CHANGELOG.md +20 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +13 -13
  6. data/bin/load_shopify.rb +3 -1
  7. data/bin/shopify +2 -0
  8. data/docs/Gemfile.lock +23 -13
  9. data/docs/getting-started/install/index.md +37 -1
  10. data/docs/getting-started/migrate/index.md +34 -1
  11. data/ext/shopify-cli/extconf.rb +40 -20
  12. data/lib/project_types/extension/cli.rb +1 -1
  13. data/lib/project_types/extension/commands/build.rb +1 -1
  14. data/lib/project_types/extension/models/type.rb +1 -0
  15. data/lib/project_types/extension/tasks/create_extension.rb +1 -1
  16. data/lib/project_types/extension/tasks/get_app.rb +1 -1
  17. data/lib/project_types/extension/tasks/update_draft.rb +1 -1
  18. data/lib/project_types/node/commands/create.rb +4 -4
  19. data/lib/project_types/node/commands/deploy/heroku.rb +6 -1
  20. data/lib/project_types/node/commands/generate/billing.rb +6 -5
  21. data/lib/project_types/node/commands/generate/page.rb +8 -5
  22. data/lib/project_types/node/commands/generate/webhook.rb +4 -1
  23. data/lib/project_types/node/messages/messages.rb +3 -2
  24. data/lib/project_types/rails/cli.rb +0 -1
  25. data/lib/project_types/rails/commands/create.rb +52 -4
  26. data/lib/project_types/rails/commands/generate.rb +1 -0
  27. data/lib/project_types/rails/commands/generate/webhook.rb +3 -2
  28. data/lib/project_types/rails/commands/serve.rb +6 -2
  29. data/lib/project_types/rails/gem.rb +61 -6
  30. data/lib/project_types/rails/messages/messages.rb +29 -13
  31. data/lib/project_types/script/cli.rb +2 -3
  32. data/lib/project_types/script/commands/create.rb +5 -9
  33. data/lib/project_types/script/commands/disable.rb +4 -15
  34. data/lib/project_types/script/commands/enable.rb +37 -13
  35. data/lib/project_types/script/commands/push.rb +8 -13
  36. data/lib/project_types/script/config/extension_points.yml +9 -3
  37. data/lib/project_types/script/errors.rb +8 -0
  38. data/lib/project_types/script/forms/create.rb +1 -1
  39. data/lib/project_types/script/layers/application/create_script.rb +7 -6
  40. data/lib/project_types/script/layers/application/disable_script.rb +9 -7
  41. data/lib/project_types/script/layers/application/enable_script.rb +11 -9
  42. data/lib/project_types/script/layers/application/push_script.rb +6 -4
  43. data/lib/project_types/script/layers/domain/errors.rb +2 -0
  44. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +2 -2
  45. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +2 -2
  46. data/lib/project_types/script/layers/infrastructure/errors.rb +2 -0
  47. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +1 -1
  48. data/lib/project_types/script/layers/infrastructure/script_repository.rb +1 -1
  49. data/lib/project_types/script/layers/infrastructure/script_service.rb +2 -0
  50. data/lib/project_types/script/messages/messages.rb +25 -31
  51. data/lib/project_types/script/script_project.rb +8 -4
  52. data/lib/project_types/script/templates/ts/as-pect.config.js +6 -0
  53. data/lib/project_types/script/ui/error_handler.rb +8 -0
  54. data/lib/project_types/script/ui/printing_spinner.rb +75 -0
  55. data/lib/rubygems_plugin.rb +18 -10
  56. data/lib/shopify-cli/admin_api/populate_resource_command.rb +1 -1
  57. data/lib/shopify-cli/admin_api/schema.rb +20 -8
  58. data/lib/shopify-cli/command.rb +14 -11
  59. data/lib/shopify-cli/commands.rb +1 -0
  60. data/lib/shopify-cli/commands/config.rb +44 -0
  61. data/lib/shopify-cli/commands/connect.rb +8 -69
  62. data/lib/shopify-cli/commands/create.rb +2 -2
  63. data/lib/shopify-cli/commands/help.rb +1 -1
  64. data/lib/shopify-cli/commands/system.rb +22 -13
  65. data/lib/shopify-cli/context.rb +38 -1
  66. data/lib/shopify-cli/core.rb +0 -1
  67. data/lib/shopify-cli/core/entry_point.rb +1 -1
  68. data/lib/shopify-cli/core/executor.rb +3 -5
  69. data/lib/shopify-cli/core/monorail.rb +1 -1
  70. data/lib/shopify-cli/db.rb +1 -1
  71. data/lib/shopify-cli/feature.rb +97 -0
  72. data/lib/shopify-cli/heroku.rb +21 -5
  73. data/lib/shopify-cli/js_deps.rb +2 -2
  74. data/lib/shopify-cli/js_system.rb +2 -2
  75. data/lib/shopify-cli/messages/messages.rb +37 -12
  76. data/lib/shopify-cli/partners_api/organizations.rb +7 -7
  77. data/lib/shopify-cli/process_supervision.rb +60 -21
  78. data/lib/shopify-cli/project.rb +14 -6
  79. data/lib/shopify-cli/project_type.rb +5 -7
  80. data/lib/shopify-cli/sub_command.rb +1 -0
  81. data/lib/shopify-cli/task.rb +2 -2
  82. data/lib/shopify-cli/tasks.rb +11 -4
  83. data/lib/shopify-cli/tasks/ensure_env.rb +72 -16
  84. data/lib/shopify-cli/tasks/update_dashboard_urls.rb +4 -3
  85. data/lib/shopify-cli/tunnel.rb +44 -14
  86. data/lib/shopify-cli/version.rb +1 -1
  87. data/lib/shopify_cli.rb +36 -9
  88. data/shopify-cli.gemspec +4 -1
  89. data/vendor/deps/cli-kit/REVISION +1 -1
  90. data/vendor/deps/cli-kit/lib/cli/kit.rb +1 -1
  91. data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +2 -2
  92. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +12 -6
  93. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +9 -11
  94. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +8 -2
  95. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +7 -7
  96. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +48 -17
  97. data/vendor/deps/cli-ui/REVISION +1 -1
  98. data/vendor/deps/cli-ui/lib/cli/ui.rb +5 -4
  99. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +9 -3
  100. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +1 -0
  101. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -2
  102. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -0
  103. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +13 -5
  104. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +29 -2
  105. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +21 -10
  106. data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
  107. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +11 -2
  108. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +1 -0
  109. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -3
  110. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +6 -8
  111. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +2 -0
  112. data/vendor/gen/lib/gen.rb +39 -0
  113. data/vendor/gen/lib/gen/commands.rb +18 -0
  114. data/vendor/gen/lib/gen/commands/help.rb +20 -0
  115. data/vendor/gen/lib/gen/commands/new.rb +21 -0
  116. data/vendor/gen/lib/gen/entry_point.rb +10 -0
  117. data/vendor/gen/lib/gen/generator.rb +165 -0
  118. data/vendor/gen/template/.gitignore +2 -0
  119. data/vendor/gen/template/Gemfile +10 -0
  120. data/vendor/gen/template/README.md +1 -0
  121. data/vendor/gen/template/bin/testunit +23 -0
  122. data/vendor/gen/template/bin/update-deps +97 -0
  123. data/vendor/gen/template/dev-gems.yml +3 -0
  124. data/vendor/gen/template/dev-vendor.yml +4 -0
  125. data/vendor/gen/template/exe/__app__-gems +17 -0
  126. data/vendor/gen/template/exe/__app__-vendor +18 -0
  127. data/vendor/gen/template/lib/__app__.rb +33 -0
  128. data/vendor/gen/template/lib/__app__/commands.rb +18 -0
  129. data/vendor/gen/template/lib/__app__/commands/example.rb +19 -0
  130. data/vendor/gen/template/lib/__app__/commands/help.rb +21 -0
  131. data/vendor/gen/template/lib/__app__/entry_point.rb +10 -0
  132. data/vendor/gen/template/test/example_test.rb +17 -0
  133. data/vendor/gen/template/test/test_helper.rb +22 -0
  134. metadata +28 -6
  135. data/Vagrantfile +0 -17
  136. data/lib/project_types/script/forms/enable.rb +0 -24
  137. data/lib/project_types/script/forms/push.rb +0 -19
  138. data/lib/project_types/script/forms/script_form.rb +0 -66
@@ -22,7 +22,7 @@ module Script
22
22
  def get_push_package(script, compiled_type)
23
23
  build_file_path = file_path(script.name, compiled_type)
24
24
 
25
- raise Domain::PushPackageNotFoundError unless File.exist?(build_file_path)
25
+ raise Domain::PushPackageNotFoundError unless ctx.file_exist?(build_file_path)
26
26
 
27
27
  script_content = File.read(build_file_path)
28
28
 
@@ -9,7 +9,7 @@ module Script
9
9
 
10
10
  def get_script(language, extension_point_type, script_name)
11
11
  source_file_path = src_code_file(language)
12
- unless File.exist?(source_file_path)
12
+ unless ctx.file_exist?(source_file_path)
13
13
  raise Domain::Errors::ScriptNotFoundError.new(extension_point_type, source_file_path)
14
14
  end
15
15
 
@@ -60,6 +60,8 @@ module Script
60
60
  raise Errors::AppScriptUndefinedError, api_key
61
61
  elsif user_errors.any? { |e| e['tag'] == 'shop_script_conflict' }
62
62
  raise Errors::ShopScriptConflictError
63
+ elsif user_errors.any? { |e| e['tag'] == 'app_script_not_pushed' }
64
+ raise Errors::AppScriptNotPushedError
63
65
  else
64
66
  raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s)
65
67
  end
@@ -38,10 +38,15 @@ module Script
38
38
  invalid_extension_cause: "Invalid extension point %s",
39
39
  invalid_extension_help: "Allowed values: %s.",
40
40
 
41
+ invalid_config: "Can't change the configuration values because %1$s is missing or "\
42
+ "it is not formatted properly.",
43
+
41
44
  script_not_found_cause: "Couldn't find script %s for extension point %s",
42
45
 
43
46
  app_not_installed_cause: "App not installed on development store.",
44
47
 
48
+ app_script_not_pushed_help: "Push the script and then try this command again.",
49
+
45
50
  app_script_undefined_help: "Push script to app.",
46
51
 
47
52
  build_error_cause: "Something went wrong while building the script.",
@@ -72,32 +77,26 @@ module Script
72
77
  help: <<~HELP,
73
78
  {{command:%1$s create script}}: Creates a script project.
74
79
  Usage: {{command:%1$s create script}}
75
- HELP
76
- extended_help: <<~HELP,
77
- \s\sOptions:
78
- \s\s{{command:--name=NAME}} Script project name. Use any string.
79
- \s\s{{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
80
+ Options:
81
+ {{command:--name=NAME}} Script project name. Use any string.
82
+ {{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
80
83
  HELP
81
84
 
82
85
  error: {
83
86
  operation_failed: "Script not created.",
84
87
  },
85
88
 
86
- script_path: "{{v}} Project directory: {{green:%{folder}}}",
87
- script_created: "{{v}} Script created: {{green:%{script_id}}}",
89
+ change_directory_notice: "{{*}} Change directories to {{green:%s}} to run script commands",
88
90
  creating: "Creating script",
89
- created: "Created script",
91
+ created: "Created script: {{green:%s}}",
90
92
  },
91
93
 
92
94
  push: {
93
95
  help: <<~HELP,
94
96
  Build the script and put it into production. If you've already pushed a script with the same extension point, use --force to replace the current script with the newest one.
95
97
  Usage: {{command:%s push}}
96
- HELP
97
- extended_help: <<~HELP,
98
- \s\sOptions:
99
- \s\s{{command:--API_key=<API_key>}} API key. Must be a valid API key, otherwise store access fails.
100
- \s\s{{command:[--force]}} Forces the script to be overwritten if an instance of it already exists.
98
+ Options:
99
+ {{command:[--force]}} Forces the script to be overwritten if an instance of it already exists.
101
100
  HELP
102
101
 
103
102
  error: {
@@ -112,14 +111,10 @@ module Script
112
111
  Turn off script in development store.
113
112
  Usage: {{command:%s disable}}
114
113
  HELP
115
- extended_help: <<~HELP,
116
- \s\sOptions:
117
- \s\s{{command:--API_key=<API_key>}} API key. Must be a valid API key, otherwise store access fails.
118
- \s\s{{command:--shop_domain=<my_store.myshopify.com>}} Test store URL. Must be an existing test store.
119
- HELP
120
114
 
121
115
  error: {
122
116
  operation_failed: "Can't disable script.",
117
+ not_pushed_to_app: "Can't disable the script because it hasn't been pushed to the app.",
123
118
  },
124
119
 
125
120
  script_disabled: "{{v}} Script disabled. Script is turned off in development store.",
@@ -129,11 +124,9 @@ module Script
129
124
  help: <<~HELP,
130
125
  Turn on script in development store.
131
126
  Usage: {{command:%s enable}}
132
- HELP
133
- extended_help: <<~HELP,
134
- \s\sOptions:
135
- \s\s{{command:--API_key=<API_key>}} API key. Must be a valid API key, otherwise store access fails.
136
- \s\s{{command:--shop_domain=<my_store.myshopify.com>}} Test store URL. Must be an existing test store.
127
+ Options:
128
+ {{command:--config_props='name1:value1, name2:value2'}} Optional. Define the configuration of your script by passing individual name and value pairs. If used with --config_file, then matching values in --config_props will override those set in the file.
129
+ {{command:--config_file=<path/to/YAMLFilename>}} Optional. Define the configuration of your script using a YAML formatted file. --config_props values override properties in this file.
137
130
  HELP
138
131
 
139
132
  info: "{{*}} A script always remains enabled until you disable it - even after pushing "\
@@ -142,6 +135,7 @@ module Script
142
135
 
143
136
  error: {
144
137
  operation_failed: "Can't enable script.",
138
+ not_pushed_to_app: "Can't enable the script because it hasn't been pushed to the app.",
145
139
  },
146
140
 
147
141
  script_enabled: "{{v}} Script enabled. %{type} script %{title} in app (API key: %{api_key}) "\
@@ -177,25 +171,25 @@ module Script
177
171
  script_form: {
178
172
  ask_app_api_key_default: "Which app do you want this script to belong to?",
179
173
  ask_shop_domain_default: "Select a development store",
180
- fetching_organizations: "{{i}} Fetching partner organizations",
174
+ fetching_organizations: "Fetching partner organizations",
175
+ fetched_organizations: "Fetched partner organizations",
181
176
  select_organization: "Select partner organization.",
182
177
  using_app: "Using app {{green:%{title} (%{api_key})}}.",
183
178
  using_development_store: "Using development store {{green:%{domain}}}",
184
179
  using_organization: "Partner organization {{green:%s}}.",
185
180
  },
186
- enable: {
187
- ask_app_api_key: "Which app is the script pushed to?",
188
- ask_shop_domain: "Which development store is the app installed on?",
189
- },
190
181
  },
191
182
 
192
183
  application: {
193
184
  building: "Building",
194
185
  building_script: "Building script",
195
186
  built: "Built",
196
- pushed: "{{v}} Pushed",
197
- disabled: "{{v}} Disabled",
198
- enabled: "{{v}} Enabled",
187
+ pushing: "Pushing",
188
+ pushed: "Pushed",
189
+ disabling: "Disabling",
190
+ disabled: "Disabled",
191
+ enabling: "Enabling",
192
+ enabled: "Enabled",
199
193
  },
200
194
  },
201
195
  }.freeze
@@ -19,12 +19,16 @@ module Script
19
19
  }
20
20
  end
21
21
 
22
+ def file_name
23
+ "script.#{language}"
24
+ end
25
+
22
26
  def source_file
23
27
  "#{SOURCE_DIR}/#{file_name}"
24
28
  end
25
29
 
26
- def file_name
27
- "script.#{language}"
30
+ def source_path
31
+ "#{script_name}/#{source_file}"
28
32
  end
29
33
 
30
34
  private
@@ -36,14 +40,14 @@ module Script
36
40
 
37
41
  class << self
38
42
  def create(ctx, dir)
39
- raise Errors::ScriptProjectAlreadyExistsError, dir if ctx.exist?(dir)
43
+ raise Errors::ScriptProjectAlreadyExistsError, dir if ctx.dir_exist?(dir)
40
44
  ctx.mkdir_p(dir)
41
45
  ctx.chdir(dir)
42
46
  end
43
47
 
44
48
  def cleanup(ctx:, script_name:, root_dir:)
45
49
  ctx.chdir(root_dir)
46
- ctx.rm_r("#{root_dir}/#{script_name}") if ctx.exist?("#{root_dir}/#{script_name}")
50
+ ctx.rm_r("#{root_dir}/#{script_name}") if ctx.dir_exist?("#{root_dir}/#{script_name}")
47
51
  end
48
52
  end
49
53
  end
@@ -17,5 +17,11 @@ module.exports = {
17
17
  reportMax: false,
18
18
  reportMin: false,
19
19
  },
20
+ wasi: {
21
+ args: [],
22
+ env: process.env,
23
+ preopens: {},
24
+ returnOnExit: false,
25
+ },
20
26
  outputBinary: false,
21
27
  };
@@ -44,6 +44,10 @@ module Script
44
44
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_context_cause'),
45
45
  help_suggestion: ShopifyCli::Context.message('script.error.invalid_context_help'),
46
46
  }
47
+ when Errors::InvalidConfigYAMLError
48
+ {
49
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_config', e.config_file),
50
+ }
47
51
  when Errors::InvalidScriptNameError
48
52
  {
49
53
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_script_name_cause'),
@@ -92,6 +96,10 @@ module Script
92
96
  {
93
97
  cause_of_error: ShopifyCli::Context.message('script.error.app_not_installed_cause'),
94
98
  }
99
+ when Layers::Infrastructure::Errors::AppScriptNotPushedError
100
+ {
101
+ cause_of_error: ShopifyCli::Context.message('script.error.app_script_not_pushed_help'),
102
+ }
95
103
  when Layers::Infrastructure::Errors::AppScriptUndefinedError
96
104
  {
97
105
  help_suggestion: ShopifyCli::Context.message('script.error.app_script_undefined_help'),
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+ require 'shopify_cli'
3
+
4
+ module Script
5
+ module UI
6
+ module PrintingSpinner
7
+ ##
8
+ # Creates a single spinner that runs the provided block.
9
+ # The block can take in a ctx argument that formats printed output to support
10
+ # printing from within the spin block.
11
+ #
12
+ # ==== Attributes
13
+ #
14
+ # * +ctx+ - The current context.
15
+ # * +title+ - Title of the spinner to use
16
+ #
17
+ # ==== Options
18
+ #
19
+ # * +:auto_debrief+ - Automatically debrief exceptions? Default to true
20
+ #
21
+ # ==== Block
22
+ #
23
+ # * +ctx+ - Instance of the PrintingSpinnerContext built from the ctx attribute.
24
+ # - +ctx.puts(...)+ formats output to enable support for printing within spinners
25
+ # * +spinner+ - Instance of the spinner. Can call +update_title+ to update the user of changes
26
+ #
27
+ def self.spin(ctx, title, auto_debrief: false)
28
+ StrictSpinner.spin(title, auto_debrief: auto_debrief) do |spinner, *args|
29
+ Thread.current[:cliui_output_hook] = nil
30
+ yield(PrintingSpinnerContext.from(ctx, spinner), spinner, *args)
31
+ end
32
+ end
33
+
34
+ ##
35
+ # Printing within spinners requires the manipulation of ANSI escape
36
+ # sequences in order to make sure the CLI::UI::Spinner does not overwrite
37
+ # previously printed content.
38
+ class PrintingSpinnerContext < ShopifyCli::Context
39
+ include SmartProperties
40
+ property :spinner, required: true
41
+
42
+ def self.from(ctx, spinner)
43
+ new_ctx = new(spinner: spinner)
44
+ ctx.instance_variables.each do |var|
45
+ new_ctx.instance_variable_set(var, ctx.instance_variable_get(var))
46
+ end
47
+ new_ctx
48
+ end
49
+
50
+ def puts(*input)
51
+ super(encoded_lines(*input) + "\n" + spinner_text)
52
+ end
53
+
54
+ private
55
+
56
+ def encoded_lines(*lines)
57
+ lines
58
+ .join("\n")
59
+ .split("\n")
60
+ .map { |line| encode_ansi(line) unless line.nil? }
61
+ .join(CLI::UI::ANSI.next_line + "\n")
62
+ end
63
+
64
+ def encode_ansi(line)
65
+ CLI::UI::ANSI.previous_line + line + CLI::UI::ANSI.clear_to_end_of_line
66
+ end
67
+
68
+ def spinner_text
69
+ spinner.render(0, true)
70
+ end
71
+ end
72
+ private_constant(:PrintingSpinnerContext)
73
+ end
74
+ end
75
+ end
@@ -1,17 +1,25 @@
1
1
  Gem.post_uninstall do |uninstaller|
2
2
  if uninstaller.spec.name == 'shopify-cli'
3
- require 'fileutils'
3
+ if RUBY_PLATFORM.match(/mingw32/)
4
+ bat_path = File.dirname(RbConfig.ruby)
5
+ bat = "#{bat_path}\\shopify.bat"
4
6
 
5
- symlink = '/usr/local/bin/shopify'
7
+ # delete the auto-generated batch script
8
+ File.unlink(bat)
9
+ else
10
+ require 'fileutils'
6
11
 
7
- # delete the symbolic link IFF it exists AND it does not point to a file
8
- # (i.e., it's been left hanging as a result of the uninstall, as expected)
9
- #
10
- # if the file still exists, either the uninstall failed (possible but
11
- # unlikely) OR
12
- # there's another installation of the gem in another ruby folder that has
13
- # overwritten it, so leave the symbolic link alone
14
- system("sudo rm -f #{symlink}") if File.symlink?(symlink) && !File.exist?(symlink)
12
+ symlink = '/usr/local/bin/shopify'
13
+
14
+ # delete the symbolic link IFF it exists AND it does not point to a file
15
+ # (i.e., it's been left hanging as a result of the uninstall, as expected)
16
+ #
17
+ # if the file still exists, either the uninstall failed (possible but
18
+ # unlikely) OR
19
+ # there's another installation of the gem in another ruby folder that has
20
+ # overwritten it, so leave the symbolic link alone
21
+ system("sudo rm -f #{symlink}") if File.symlink?(symlink) && !File.exist?(symlink)
22
+ end
15
23
  end
16
24
 
17
25
  true
@@ -118,7 +118,7 @@ module ShopifyCli
118
118
  kwargs = { input: data }
119
119
  kwargs[:shop] = @shop
120
120
  resp = AdminAPI.query(
121
- @ctx, "create_#{snake_case_resource_type}", kwargs
121
+ @ctx, "create_#{snake_case_resource_type}", **kwargs
122
122
  )
123
123
  @ctx.abort(resp['errors']) if resp['errors']
124
124
  @ctx.done(message(resp['data'])) unless @silent
@@ -3,15 +3,27 @@ require 'shopify_cli'
3
3
  module ShopifyCli
4
4
  class AdminAPI
5
5
  class Schema < Hash
6
- def self.get(ctx)
7
- unless ShopifyCli::DB.exists?(:shopify_admin_schema)
8
- schema = AdminAPI.query(ctx, 'admin_introspection')
9
- ShopifyCli::DB.set(shopify_admin_schema: JSON.dump(schema))
6
+ class << self
7
+ def get(ctx)
8
+ unless ShopifyCli::DB.exists?(:shopify_admin_schema)
9
+ shop = Project.current.env.shop || get_shop(ctx)
10
+ schema = AdminAPI.query(ctx, 'admin_introspection', shop: shop)
11
+ ShopifyCli::DB.set(shopify_admin_schema: JSON.dump(schema))
12
+ end
13
+ # This is ruby magic for making a new hash with another hash.
14
+ # It wraps the JSON in our Schema Class to have the helper methods
15
+ # available
16
+ self[JSON.parse(ShopifyCli::DB.get(:shopify_admin_schema))]
17
+ end
18
+
19
+ private
20
+
21
+ def get_shop(ctx)
22
+ res = ShopifyCli::Tasks::SelectOrgAndShop.call(ctx)
23
+ domain = res[:shop_domain]
24
+ Project.current.env.update(ctx, :shop, domain)
25
+ domain
10
26
  end
11
- # This is ruby magic for making a new hash with another hash.
12
- # It wraps the JSON in our Schema Class to have the helper methods
13
- # available
14
- self[JSON.parse(ShopifyCli::DB.get(:shopify_admin_schema))]
15
27
  end
16
28
 
17
29
  def type(name)
@@ -3,30 +3,29 @@ require 'shopify_cli'
3
3
 
4
4
  module ShopifyCli
5
5
  class Command < CLI::Kit::BaseCommand
6
+ extend Feature::Set
7
+
6
8
  attr_writer :ctx
7
9
  attr_accessor :options
8
10
 
9
11
  class << self
10
- attr_writer :ctx
11
- attr_reader :hidden
12
+ attr_writer :ctx, :task_registry
12
13
 
13
14
  def call(args, command_name)
14
15
  subcommand, resolved_name = subcommand_registry.lookup_command(args.first)
15
16
  if subcommand
16
17
  subcommand.ctx = @ctx
18
+ subcommand.task_registry = @task_registry
17
19
  subcommand.call(args, resolved_name, command_name)
18
20
  else
19
21
  cmd = new(@ctx)
20
22
  cmd.options.parse(@_options, args)
21
23
  return call_help(command_name) if cmd.options.help
24
+ run_prerequisites
22
25
  cmd.call(args, command_name)
23
26
  end
24
27
  end
25
28
 
26
- def hidden_command
27
- @hidden = true
28
- end
29
-
30
29
  def options(&block)
31
30
  @_options = block
32
31
  end
@@ -44,13 +43,16 @@ module ShopifyCli
44
43
  end
45
44
 
46
45
  def prerequisite_task(*tasks)
47
- tasks.each do |task|
48
- prerequisite_tasks[task] = ShopifyCli::Tasks::Registry[task]
49
- end
46
+ @prerequisite_tasks ||= []
47
+ @prerequisite_tasks += tasks
48
+ end
49
+
50
+ def run_prerequisites
51
+ (@prerequisite_tasks || []).each { |task| task_registry[task]&.call(@ctx) }
50
52
  end
51
53
 
52
- def prerequisite_tasks
53
- @prerequisite_tasks ||= {}
54
+ def task_registry
55
+ @task_registry || ShopifyCli::Tasks::Registry
54
56
  end
55
57
 
56
58
  def call_help(*cmds)
@@ -60,6 +62,7 @@ module ShopifyCli
60
62
  end
61
63
 
62
64
  def initialize(ctx = nil)
65
+ super()
63
66
  @ctx = ctx || ShopifyCli::Context.new
64
67
  self.options = Options.new
65
68
  end