shopify-cli 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +15 -2
  3. data/CHANGELOG.md +4 -1
  4. data/Gemfile.lock +3 -3
  5. data/dev.yml +3 -0
  6. data/lib/graphql/extension_create.graphql +17 -2
  7. data/lib/project_types/extension/cli.rb +2 -0
  8. data/lib/project_types/extension/commands/extension_command.rb +4 -4
  9. data/lib/project_types/extension/commands/push.rb +2 -2
  10. data/lib/project_types/extension/commands/register.rb +4 -3
  11. data/lib/project_types/extension/commands/serve.rb +1 -35
  12. data/lib/project_types/extension/extension_project.rb +15 -4
  13. data/lib/project_types/extension/extension_project_keys.rb +2 -1
  14. data/lib/project_types/extension/features/argo.rb +6 -0
  15. data/lib/project_types/extension/features/argo_renderer_package.rb +32 -0
  16. data/lib/project_types/extension/features/argo_serve.rb +69 -0
  17. data/lib/project_types/extension/messages/message_loading.rb +3 -1
  18. data/lib/project_types/extension/models/registration.rb +1 -0
  19. data/lib/project_types/extension/models/specification.rb +2 -0
  20. data/lib/project_types/extension/models/specification_handlers/default.rb +8 -0
  21. data/lib/project_types/extension/tasks/configure_features.rb +2 -0
  22. data/lib/project_types/extension/tasks/converters/registration_converter.rb +2 -0
  23. data/lib/project_types/node/commands/generate.rb +0 -22
  24. data/lib/project_types/script/cli.rb +2 -8
  25. data/lib/project_types/script/commands/create.rb +0 -7
  26. data/lib/project_types/script/commands/push.rb +2 -2
  27. data/lib/project_types/script/config/extension_points.yml +2 -0
  28. data/lib/project_types/script/errors.rb +0 -19
  29. data/lib/project_types/script/forms/create.rb +3 -14
  30. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +0 -3
  31. data/lib/project_types/script/graphql/script_service_proxy.graphql +1 -2
  32. data/lib/project_types/script/layers/application/build_script.rb +1 -2
  33. data/lib/project_types/script/layers/application/create_script.rb +30 -51
  34. data/lib/project_types/script/layers/application/extension_points.rb +3 -2
  35. data/lib/project_types/script/layers/application/push_script.rb +2 -4
  36. data/lib/project_types/script/layers/domain/extension_point.rb +56 -46
  37. data/lib/project_types/script/layers/domain/metadata.rb +18 -25
  38. data/lib/project_types/script/layers/domain/push_package.rb +0 -4
  39. data/lib/project_types/script/layers/domain/script_project.rb +34 -0
  40. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +6 -2
  41. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +4 -4
  42. data/lib/project_types/script/layers/infrastructure/errors.rb +12 -10
  43. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +10 -12
  44. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +1 -1
  45. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +145 -0
  46. data/lib/project_types/script/layers/infrastructure/script_service.rb +9 -72
  47. data/lib/project_types/script/messages/messages.rb +0 -47
  48. data/lib/project_types/script/ui/error_handler.rb +7 -24
  49. data/lib/shopify-cli/context.rb +28 -0
  50. data/lib/shopify-cli/version.rb +1 -1
  51. metadata +6 -10
  52. data/lib/project_types/script/commands/disable.rb +0 -25
  53. data/lib/project_types/script/commands/enable.rb +0 -80
  54. data/lib/project_types/script/graphql/shop_script_delete.graphql +0 -14
  55. data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +0 -28
  56. data/lib/project_types/script/layers/application/disable_script.rb +0 -21
  57. data/lib/project_types/script/layers/application/enable_script.rb +0 -23
  58. data/lib/project_types/script/layers/infrastructure/config_ui_repository.rb +0 -46
  59. data/lib/project_types/script/script_project.rb +0 -64
@@ -15,7 +15,6 @@ module Script
15
15
  script_name:,
16
16
  script_content:,
17
17
  compiled_type:,
18
- description: nil,
19
18
  api_key: nil,
20
19
  force: false,
21
20
  metadata:,
@@ -25,7 +24,6 @@ module Script
25
24
  variables = {
26
25
  extensionPointName: extension_point_type.upcase,
27
26
  title: script_name,
28
- description: description,
29
27
  configUi: config_ui&.content,
30
28
  sourceCode: Base64.encode64(script_content),
31
29
  language: compiled_type,
@@ -47,94 +45,33 @@ module Script
47
45
  raise Errors::ConfigUiMissingKeysError.new(config_ui&.filename, e["message"])
48
46
  elsif (e = user_errors.find { |err| err["tag"] == "config_ui_fields_missing_keys_error" })
49
47
  raise Errors::ConfigUiFieldsMissingKeysError.new(config_ui&.filename, e["message"])
48
+ elsif user_errors.find { |err| %w(not_use_msgpack_error schema_version_argument_error).include?(err["tag"]) }
49
+ raise Domain::Errors::MetadataValidationError
50
50
  else
51
- raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s)
52
- end
53
- end
54
-
55
- def enable(api_key:, shop_domain:, configuration:, extension_point_type:, title:)
56
- query_name = "shop_script_update_or_create"
57
- variables = {
58
- extensionPointName: extension_point_type.upcase,
59
- configuration: configuration,
60
- title: title,
61
- }
62
-
63
- resp_hash = script_service_request(
64
- query_name: query_name,
65
- api_key: api_key,
66
- shop_domain: format_shop_domain(shop_domain),
67
- variables: variables,
68
- )
69
- user_errors = resp_hash["data"]["shopScriptUpdateOrCreate"]["userErrors"]
70
-
71
- return resp_hash if user_errors.empty?
72
-
73
- if user_errors.any? { |e| e["tag"] == "app_script_not_found" }
74
- raise Errors::AppScriptUndefinedError, api_key
75
- elsif user_errors.any? { |e| e["tag"] == "shop_script_conflict" }
76
- raise Errors::ShopScriptConflictError
77
- elsif user_errors.any? { |e| e["tag"] == "app_script_not_pushed" }
78
- raise Errors::AppScriptNotPushedError
79
- else
80
- raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s)
81
- end
82
- end
83
-
84
- def disable(api_key:, shop_domain:, extension_point_type:)
85
- query_name = "shop_script_delete"
86
- variables = {
87
- extensionPointName: extension_point_type.upcase,
88
- }
89
-
90
- resp_hash = script_service_request(
91
- query_name: query_name,
92
- api_key: api_key,
93
- shop_domain: format_shop_domain(shop_domain),
94
- variables: variables,
95
- )
96
- user_errors = resp_hash["data"]["shopScriptDelete"]["userErrors"]
97
- return resp_hash if user_errors.empty?
98
-
99
- if user_errors.any? { |e| e["tag"] == "shop_script_not_found" }
100
- raise Errors::ShopScriptUndefinedError, api_key
101
- else
102
- raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s)
51
+ raise Errors::GraphqlError, user_errors
103
52
  end
104
53
  end
105
54
 
106
55
  private
107
56
 
108
- def format_shop_domain(shop_domain)
109
- shop_domain.delete_suffix("/")
110
- end
111
-
112
57
  class ScriptServiceAPI < ShopifyCli::API
113
58
  property(:api_key, accepts: String)
114
- property(:shop_id, accepts: Integer)
115
59
 
116
- def self.query(ctx, query_name, api_key: nil, shop_domain: nil, variables: {})
117
- api_client(ctx, api_key, shop_domain).query(query_name, variables: variables)
60
+ def self.query(ctx, query_name, api_key: nil, variables: {})
61
+ api_client(ctx, api_key).query(query_name, variables: variables)
118
62
  end
119
63
 
120
- def self.api_client(ctx, api_key, shop_domain)
64
+ def self.api_client(ctx, api_key)
121
65
  new(
122
66
  ctx: ctx,
123
67
  url: "https://script-service.myshopify.io/graphql",
124
68
  token: "",
125
- api_key: api_key,
126
- shop_id: infer_shop_id(shop_domain)
69
+ api_key: api_key
127
70
  )
128
71
  end
129
72
 
130
- def self.infer_shop_id(shop_domain)
131
- return unless shop_domain
132
-
133
- [shop_domain.to_i, 1].max
134
- end
135
-
136
73
  def auth_headers(*)
137
- tokens = { "APP_KEY" => api_key, "SHOP_ID" => shop_id }.compact.to_json
74
+ tokens = { "APP_KEY" => api_key }.compact.to_json
138
75
  { "X-Shopify-Authenticated-Tokens" => tokens }
139
76
  end
140
77
  end
@@ -177,7 +114,7 @@ module Script
177
114
  when "app_not_installed_on_shop"
178
115
  raise Errors::AppNotInstalledError
179
116
  else
180
- raise Errors::GraphqlError, response["errors"].map { |e| e["message"] }
117
+ raise Errors::GraphqlError, response["errors"]
181
118
  end
182
119
  end
183
120
 
@@ -73,9 +73,6 @@ module Script
73
73
  service_failure_cause: "Internal service error.",
74
74
  service_failure_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
75
75
 
76
- user_error_cause: "Invalid script extension metadata.",
77
- user_error_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
78
-
79
76
  metadata_validation_cause: "Invalid script extension metadata.",
80
77
  metadata_validation_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
81
78
 
@@ -94,8 +91,6 @@ module Script
94
91
  "'--metadata build/metadata.json' argument",
95
92
  app_not_installed_cause: "App not installed on store.",
96
93
 
97
- app_script_not_pushed_help: "Script isn't on the app. Run {{command:shopify push}}, and then try again.",
98
-
99
94
  build_error_cause: "Something went wrong while building the script.",
100
95
  build_error_help: "Correct the errors and try again.",
101
96
 
@@ -116,12 +111,6 @@ module Script
116
111
  shop_auth_cause: "Unable to authenticate with the store.",
117
112
  shop_auth_help: "Try again.",
118
113
 
119
- shop_script_conflict_cause: "Another app in this store has already enabled a script "\
120
- "on this extension point.",
121
- shop_script_conflict_help: "Disable that script or uninstall that app and try again.",
122
-
123
- shop_script_undefined_cause: "Script is already turned off in store.",
124
-
125
114
  invalid_build_script: "The root package.json contains an invalid build command that " \
126
115
  "is needed to compile your script to WebAssembly.",
127
116
  build_script_not_found: "The root package.json is missing the build command that " \
@@ -142,7 +131,6 @@ module Script
142
131
  Usage: {{command:%1$s create script}}
143
132
  Options:
144
133
  {{command:--name=NAME}} Script project name. Use any string.
145
- {{command:--description=DESCRIPTION}} Description of the project. Use any string.
146
134
  {{command:--extension-point=TYPE}} Extension point name. Allowed values: %2$s.
147
135
  {{command:--no-config-ui}} Specify this option if you don’t want Scripts to render an interface in the Shopify admin.
148
136
  HELP
@@ -171,40 +159,6 @@ module Script
171
159
  script_pushed: "{{v}} Script pushed to app (API key: %{api_key}).",
172
160
  },
173
161
 
174
- disable: {
175
- help: <<~HELP,
176
- Turn off script in store.
177
- Usage: {{command:%s disable}}
178
- HELP
179
-
180
- error: {
181
- operation_failed: "Can't disable script.",
182
- },
183
-
184
- script_disabled: "{{v}} Script disabled. Script is turned off in store.",
185
- },
186
-
187
- enable: {
188
- help: <<~HELP,
189
- Turn on script in store.
190
- Usage: {{command:%s enable}}
191
- Options:
192
- {{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.
193
- {{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.
194
- HELP
195
-
196
- info: "{{*}} A script always remains enabled until you disable it - even after pushing "\
197
- "script changes with the same extension point to an app. To disable a script, use "\
198
- "the 'disable' command.",
199
-
200
- error: {
201
- operation_failed: "Can't enable script.",
202
- },
203
-
204
- script_enabled: "{{v}} Script enabled. %{type} script %{title} in app (API key: %{api_key}) "\
205
- "is turned on in store {{green:%{shop_domain}}}",
206
- },
207
-
208
162
  project_deps: {
209
163
  none_required: "{{v}} None required",
210
164
  checking_with_npm: "Checking dependencies with npm",
@@ -217,7 +171,6 @@ module Script
217
171
  select_extension_point: "Which extension point do you want to use?",
218
172
  select_language: "Which language do you want to use?",
219
173
  script_name: "Script Name",
220
- description: "Description",
221
174
  },
222
175
  },
223
176
 
@@ -39,7 +39,7 @@ module Script
39
39
  cause_of_error: ShopifyCli::Context.message("script.error.oauth_cause"),
40
40
  help_suggestion: ShopifyCli::Context.message("script.error.oauth_help"),
41
41
  }
42
- when Errors::InvalidContextError
42
+ when Layers::Infrastructure::Errors::InvalidContextError
43
43
  {
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"),
@@ -53,7 +53,7 @@ module Script
53
53
  {
54
54
  cause_of_error: ShopifyCli::Context.message("script.error.invalid_config", e.config_file),
55
55
  }
56
- when Errors::InvalidLanguageError
56
+ when Layers::Infrastructure::Errors::InvalidLanguageError
57
57
  {
58
58
  cause_of_error: ShopifyCli::Context.message("script.error.invalid_language_cause", e.language),
59
59
  help_suggestion: ShopifyCli::Context.message(
@@ -84,12 +84,12 @@ module Script
84
84
  organization_id: e.organization_id
85
85
  ),
86
86
  }
87
- when Errors::ScriptProjectAlreadyExistsError
87
+ when Layers::Infrastructure::Errors::ScriptProjectAlreadyExistsError
88
88
  {
89
89
  cause_of_error: ShopifyCli::Context.message("script.error.project_exists_cause"),
90
90
  help_suggestion: ShopifyCli::Context.message("script.error.project_exists_help"),
91
91
  }
92
- when Errors::DeprecatedEPError
92
+ when Layers::Infrastructure::Errors::DeprecatedEPError
93
93
  {
94
94
  cause_of_error: ShopifyCli::Context.message("script.error.deprecated_ep", e.ep),
95
95
  help_suggestion: ShopifyCli::Context.message("script.error.deprecated_ep_cause"),
@@ -141,11 +141,6 @@ module Script
141
141
  {
142
142
  cause_of_error: ShopifyCli::Context.message("script.error.app_not_installed_cause"),
143
143
  }
144
- when Layers::Infrastructure::Errors::AppScriptNotPushedError,
145
- Layers::Infrastructure::Errors::AppScriptUndefinedError
146
- {
147
- cause_of_error: ShopifyCli::Context.message("script.error.app_script_not_pushed_help"),
148
- }
149
144
  when Layers::Infrastructure::Errors::BuildError
150
145
  {
151
146
  cause_of_error: ShopifyCli::Context.message("script.error.build_error_cause"),
@@ -193,7 +188,9 @@ module Script
193
188
  }
194
189
  when Layers::Infrastructure::Errors::GraphqlError
195
190
  {
196
- cause_of_error: ShopifyCli::Context.message("script.error.graphql_error_cause", e.errors.join(", ")),
191
+ cause_of_error: ShopifyCli::Context.message(
192
+ "script.error.graphql_error_cause", JSON.pretty_generate(e.errors)
193
+ ),
197
194
  help_suggestion: ShopifyCli::Context.message("script.error.graphql_error_help"),
198
195
  }
199
196
  when Layers::Infrastructure::Errors::ScriptRepushError
@@ -201,25 +198,11 @@ module Script
201
198
  cause_of_error: ShopifyCli::Context.message("script.error.script_repush_cause", e.api_key),
202
199
  help_suggestion: ShopifyCli::Context.message("script.error.script_repush_help"),
203
200
  }
204
- when Layers::Infrastructure::Errors::ScriptServiceUserError
205
- {
206
- cause_of_error: ShopifyCli::Context.message("script.error.user_error_cause"),
207
- help_suggestion: ShopifyCli::Context.message("script.error.user_error_help"),
208
- }
209
201
  when Layers::Infrastructure::Errors::ShopAuthenticationError
210
202
  {
211
203
  cause_of_error: ShopifyCli::Context.message("script.error.shop_auth_cause"),
212
204
  help_suggestion: ShopifyCli::Context.message("script.error.shop_auth_help"),
213
205
  }
214
- when Layers::Infrastructure::Errors::ShopScriptConflictError
215
- {
216
- cause_of_error: ShopifyCli::Context.message("script.error.shop_script_conflict_cause"),
217
- help_suggestion: ShopifyCli::Context.message("script.error.shop_script_conflict_help"),
218
- }
219
- when Layers::Infrastructure::Errors::ShopScriptUndefinedError
220
- {
221
- cause_of_error: ShopifyCli::Context.message("script.error.shop_script_undefined_cause"),
222
- }
223
206
  when Layers::Infrastructure::Errors::BuildScriptNotFoundError
224
207
  {
225
208
  cause_of_error: ShopifyCli::Context.message("script.error.build_script_not_found"),
@@ -144,6 +144,34 @@ module ShopifyCli
144
144
  File.write(ctx_path(fname), content)
145
145
  end
146
146
 
147
+ # will read a binary file relative to the context root unless the file path is absolute.
148
+ #
149
+ # #### Parameters
150
+ # * `fname` - filename of the file that you are reading, relative to root unless it is absolute.
151
+ #
152
+ # #### Example
153
+ #
154
+ # @ctx.read('binary.out')
155
+ #
156
+ def binread(fname)
157
+ File.binread(ctx_path(fname))
158
+ end
159
+
160
+ # will write/overwrite a binary file with the provided contents, relative to the context root
161
+ # unless the file path is absolute.
162
+ #
163
+ # #### Parameters
164
+ # * `fname` - filename of the file that you are writing, relative to root unless it is absolute.
165
+ # * `content` - the body contents of the file that you are writing
166
+ #
167
+ # #### Example
168
+ #
169
+ # @ctx.binwrite('binary.out', 'ASCII-8BIT encoded binary')
170
+ #
171
+ def binwrite(fname, content)
172
+ File.binwrite(ctx_path(fname), content)
173
+ end
174
+
147
175
  # will change directories and update the root, the filepath is relative to the command root unless absolute
148
176
  #
149
177
  # #### Parameters
@@ -1,3 +1,3 @@
1
1
  module ShopifyCli
2
- VERSION = "1.8.0"
2
+ VERSION = "1.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,8 @@ files:
144
144
  - lib/project_types/extension/features/argo.rb
145
145
  - lib/project_types/extension/features/argo_config.rb
146
146
  - lib/project_types/extension/features/argo_dependencies.rb
147
+ - lib/project_types/extension/features/argo_renderer_package.rb
148
+ - lib/project_types/extension/features/argo_serve.rb
147
149
  - lib/project_types/extension/features/argo_setup.rb
148
150
  - lib/project_types/extension/features/argo_setup_step.rb
149
151
  - lib/project_types/extension/features/argo_setup_steps.rb
@@ -208,20 +210,14 @@ files:
208
210
  - lib/project_types/rails/ruby.rb
209
211
  - lib/project_types/script/cli.rb
210
212
  - lib/project_types/script/commands/create.rb
211
- - lib/project_types/script/commands/disable.rb
212
- - lib/project_types/script/commands/enable.rb
213
213
  - lib/project_types/script/commands/push.rb
214
214
  - lib/project_types/script/config/extension_points.yml
215
215
  - lib/project_types/script/errors.rb
216
216
  - lib/project_types/script/forms/create.rb
217
217
  - lib/project_types/script/graphql/app_script_update_or_create.graphql
218
218
  - lib/project_types/script/graphql/script_service_proxy.graphql
219
- - lib/project_types/script/graphql/shop_script_delete.graphql
220
- - lib/project_types/script/graphql/shop_script_update_or_create.graphql
221
219
  - lib/project_types/script/layers/application/build_script.rb
222
220
  - lib/project_types/script/layers/application/create_script.rb
223
- - lib/project_types/script/layers/application/disable_script.rb
224
- - lib/project_types/script/layers/application/enable_script.rb
225
221
  - lib/project_types/script/layers/application/extension_points.rb
226
222
  - lib/project_types/script/layers/application/project_dependencies.rb
227
223
  - lib/project_types/script/layers/application/push_script.rb
@@ -230,19 +226,19 @@ files:
230
226
  - lib/project_types/script/layers/domain/extension_point.rb
231
227
  - lib/project_types/script/layers/domain/metadata.rb
232
228
  - lib/project_types/script/layers/domain/push_package.rb
229
+ - lib/project_types/script/layers/domain/script_project.rb
233
230
  - lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb
234
231
  - lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb
235
- - lib/project_types/script/layers/infrastructure/config_ui_repository.rb
236
232
  - lib/project_types/script/layers/infrastructure/errors.rb
237
233
  - lib/project_types/script/layers/infrastructure/extension_point_repository.rb
238
234
  - lib/project_types/script/layers/infrastructure/project_creator.rb
239
235
  - lib/project_types/script/layers/infrastructure/push_package_repository.rb
240
236
  - lib/project_types/script/layers/infrastructure/rust_project_creator.rb
241
237
  - lib/project_types/script/layers/infrastructure/rust_task_runner.rb
238
+ - lib/project_types/script/layers/infrastructure/script_project_repository.rb
242
239
  - lib/project_types/script/layers/infrastructure/script_service.rb
243
240
  - lib/project_types/script/layers/infrastructure/task_runner.rb
244
241
  - lib/project_types/script/messages/messages.rb
245
- - lib/project_types/script/script_project.rb
246
242
  - lib/project_types/script/ui/error_handler.rb
247
243
  - lib/project_types/script/ui/printing_spinner.rb
248
244
  - lib/project_types/script/ui/strict_spinner.rb
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Commands
5
- class Disable < ShopifyCli::Command
6
- def call(_args, _name)
7
- ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
8
- project = ScriptProject.current
9
- Layers::Application::DisableScript.call(
10
- ctx: @ctx,
11
- api_key: project.env[:api_key],
12
- shop_domain: project.env[:shop],
13
- extension_point_type: project.extension_point_type
14
- )
15
- @ctx.puts(@ctx.message("script.disable.script_disabled"))
16
- rescue StandardError => e
17
- UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message("script.disable.error.operation_failed"))
18
- end
19
-
20
- def self.help
21
- ShopifyCli::Context.message("script.disable.help", ShopifyCli::TOOL_NAME)
22
- end
23
- end
24
- end
25
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Commands
5
- class Enable < ShopifyCli::Command
6
- options do |parser, flags|
7
- parser.on("--config_props=KEYVALUEPAIRS", Array) { |t| flags[:config_props] = t }
8
- parser.on("--config-props=KEYVALUEPAIRS", Array) { |t| flags[:config_props] = t }
9
- parser.on("--config_file=CONFIGFILEPATH") { |t| flags[:config_file] = t }
10
- parser.on("--config-file=CONFIGFILEPATH") { |t| flags[:config_file] = t }
11
- end
12
-
13
- def call(_args, _name)
14
- ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
15
- project = ScriptProject.current
16
- api_key = project.env[:api_key]
17
- shop_domain = project.env[:shop]
18
-
19
- Layers::Application::EnableScript.call(
20
- ctx: @ctx,
21
- api_key: api_key,
22
- shop_domain: shop_domain,
23
- configuration: acquire_configuration(**slice(options.flags, :config_file, :config_props)),
24
- extension_point_type: project.extension_point_type,
25
- title: project.script_name
26
- )
27
- @ctx.puts(@ctx.message(
28
- "script.enable.script_enabled",
29
- api_key: api_key,
30
- shop_domain: shop_domain,
31
- type: project.extension_point_type.capitalize,
32
- title: project.script_name
33
- ))
34
- @ctx.puts(@ctx.message("script.enable.info"))
35
- rescue Errors::InvalidConfigYAMLError => e
36
- UI::ErrorHandler.pretty_print_and_raise(e)
37
- rescue StandardError => e
38
- UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message("script.enable.error.operation_failed"))
39
- end
40
-
41
- def self.help
42
- ShopifyCli::Context.message("script.enable.help", ShopifyCli::TOOL_NAME)
43
- end
44
-
45
- private
46
-
47
- def acquire_configuration(config_file: nil, config_props: nil)
48
- properties = {}
49
- properties = YAML.load(File.read(config_file)) unless config_file.nil?
50
- properties = properties.merge(parse_config_props(config_props)) unless config_props.nil?
51
-
52
- configuration = { entries: [] }
53
- properties.each do |key, value|
54
- configuration[:entries].push({
55
- key: key,
56
- value: value,
57
- })
58
- end
59
- configuration
60
- rescue Errno::ENOENT, Psych::SyntaxError
61
- raise Errors::InvalidConfigYAMLError, options.flags[:config_file]
62
- end
63
-
64
- def parse_config_props(config_props)
65
- Hash[
66
- config_props.map do |s|
67
- args = s.split(":").map(&:strip)
68
- raise Errors::InvalidConfigProps unless args.size == 2
69
- args
70
- end
71
- ]
72
- end
73
-
74
- # No slice pre Ruby 2.5 so roll our own
75
- def slice(hash, *keys)
76
- Hash[hash.to_a - hash.select { |key, _value| !keys.include?(key) }.to_a]
77
- end
78
- end
79
- end
80
- end