shopify-cli 1.6.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +15 -2
  3. data/CHANGELOG.md +21 -0
  4. data/Gemfile +12 -12
  5. data/Gemfile.lock +14 -14
  6. data/Rakefile +32 -30
  7. data/bin/load_shopify.rb +6 -6
  8. data/bin/shopify +2 -2
  9. data/dev.yml +3 -0
  10. data/ext/shopify-cli/extconf.rb +7 -7
  11. data/lib/docgen/markdown.rb +12 -12
  12. data/lib/graphql/extension_create.graphql +17 -2
  13. data/lib/graphql/fetch_specifications.graphql +14 -0
  14. data/lib/{project_types/extension/graphql → graphql}/get_app_by_api_key.graphql +0 -0
  15. data/lib/project_types/extension/cli.rb +56 -55
  16. data/lib/project_types/extension/commands/build.rb +3 -3
  17. data/lib/project_types/extension/commands/create.rb +17 -10
  18. data/lib/project_types/extension/commands/extension_command.rb +14 -7
  19. data/lib/project_types/extension/commands/push.rb +10 -10
  20. data/lib/project_types/extension/commands/register.rb +22 -32
  21. data/lib/project_types/extension/commands/serve.rb +1 -7
  22. data/lib/project_types/extension/commands/tunnel.rb +12 -12
  23. data/lib/project_types/extension/extension_project.rb +22 -7
  24. data/lib/project_types/extension/extension_project_keys.rb +5 -4
  25. data/lib/project_types/extension/features/argo.rb +26 -42
  26. data/lib/project_types/extension/features/argo_config.rb +5 -5
  27. data/lib/project_types/extension/features/argo_dependencies.rb +5 -5
  28. data/lib/project_types/extension/features/argo_renderer_package.rb +47 -0
  29. data/lib/project_types/extension/features/argo_serve.rb +69 -0
  30. data/lib/project_types/extension/features/argo_setup.rb +3 -3
  31. data/lib/project_types/extension/features/argo_setup_steps.rb +4 -4
  32. data/lib/project_types/extension/forms/create.rb +28 -34
  33. data/lib/project_types/extension/forms/questions/ask_app.rb +53 -0
  34. data/lib/project_types/extension/forms/questions/ask_name.rb +40 -0
  35. data/lib/project_types/extension/forms/questions/ask_type.rb +47 -0
  36. data/lib/project_types/extension/messages/message_loading.rb +3 -1
  37. data/lib/project_types/extension/messages/messages.rb +55 -55
  38. data/lib/project_types/extension/models/lazy_specification_handler.rb +12 -0
  39. data/lib/project_types/extension/models/registration.rb +1 -0
  40. data/lib/project_types/extension/models/specification.rb +6 -2
  41. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +1 -1
  42. data/lib/project_types/extension/models/specification_handlers/default.rb +10 -2
  43. data/lib/project_types/extension/models/specifications.rb +14 -3
  44. data/lib/project_types/extension/models/version.rb +1 -1
  45. data/lib/project_types/extension/tasks/configure_features.rb +7 -5
  46. data/lib/project_types/extension/tasks/converters/app_converter.rb +6 -6
  47. data/lib/project_types/extension/tasks/converters/registration_converter.rb +8 -6
  48. data/lib/project_types/extension/tasks/converters/validation_error_converter.rb +4 -4
  49. data/lib/project_types/extension/tasks/converters/version_converter.rb +7 -7
  50. data/lib/project_types/extension/tasks/create_extension.rb +4 -4
  51. data/lib/project_types/extension/tasks/fetch_specifications.rb +8 -28
  52. data/lib/project_types/extension/tasks/get_app.rb +4 -4
  53. data/lib/project_types/extension/tasks/get_apps.rb +3 -3
  54. data/lib/project_types/extension/tasks/update_draft.rb +4 -4
  55. data/lib/project_types/extension/tasks/user_errors.rb +4 -4
  56. data/lib/project_types/node/cli.rb +19 -19
  57. data/lib/project_types/node/commands/connect.rb +3 -3
  58. data/lib/project_types/node/commands/create.rb +40 -38
  59. data/lib/project_types/node/commands/deploy.rb +4 -4
  60. data/lib/project_types/node/commands/deploy/heroku.rb +24 -24
  61. data/lib/project_types/node/commands/generate.rb +2 -24
  62. data/lib/project_types/node/commands/open.rb +2 -2
  63. data/lib/project_types/node/commands/populate.rb +6 -6
  64. data/lib/project_types/node/commands/populate/customer.rb +5 -5
  65. data/lib/project_types/node/commands/populate/draft_order.rb +5 -5
  66. data/lib/project_types/node/commands/populate/product.rb +5 -5
  67. data/lib/project_types/node/commands/serve.rb +9 -9
  68. data/lib/project_types/node/commands/tunnel.rb +7 -7
  69. data/lib/project_types/node/forms/create.rb +17 -8
  70. data/lib/project_types/node/messages/messages.rb +8 -7
  71. data/lib/project_types/rails/cli.rb +21 -21
  72. data/lib/project_types/rails/commands/connect.rb +3 -3
  73. data/lib/project_types/rails/commands/create.rb +51 -48
  74. data/lib/project_types/rails/commands/deploy.rb +4 -4
  75. data/lib/project_types/rails/commands/deploy/heroku.rb +30 -30
  76. data/lib/project_types/rails/commands/generate.rb +7 -7
  77. data/lib/project_types/rails/commands/generate/webhook.rb +6 -6
  78. data/lib/project_types/rails/commands/open.rb +2 -2
  79. data/lib/project_types/rails/commands/populate.rb +6 -6
  80. data/lib/project_types/rails/commands/populate/customer.rb +5 -5
  81. data/lib/project_types/rails/commands/populate/draft_order.rb +5 -5
  82. data/lib/project_types/rails/commands/populate/product.rb +5 -5
  83. data/lib/project_types/rails/commands/serve.rb +11 -11
  84. data/lib/project_types/rails/commands/tunnel.rb +7 -7
  85. data/lib/project_types/rails/forms/create.rb +34 -24
  86. data/lib/project_types/rails/gem.rb +23 -23
  87. data/lib/project_types/rails/messages/messages.rb +9 -8
  88. data/lib/project_types/rails/ruby.rb +2 -2
  89. data/lib/project_types/script/cli.rb +36 -40
  90. data/lib/project_types/script/commands/create.rb +9 -13
  91. data/lib/project_types/script/commands/push.rb +6 -5
  92. data/lib/project_types/script/config/extension_points.yml +25 -10
  93. data/lib/project_types/script/errors.rb +1 -19
  94. data/lib/project_types/script/forms/create.rb +7 -18
  95. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +7 -5
  96. data/lib/project_types/script/graphql/script_service_proxy.graphql +1 -2
  97. data/lib/project_types/script/layers/application/build_script.rb +6 -8
  98. data/lib/project_types/script/layers/application/create_script.rb +34 -24
  99. data/lib/project_types/script/layers/application/extension_points.rb +3 -2
  100. data/lib/project_types/script/layers/application/project_dependencies.rb +4 -4
  101. data/lib/project_types/script/layers/application/push_script.rb +10 -15
  102. data/lib/project_types/script/layers/domain/config_ui.rb +16 -0
  103. data/lib/project_types/script/layers/domain/errors.rb +16 -0
  104. data/lib/project_types/script/layers/domain/extension_point.rb +60 -45
  105. data/lib/project_types/script/layers/domain/metadata.rb +18 -25
  106. data/lib/project_types/script/layers/domain/push_package.rb +9 -5
  107. data/lib/project_types/script/layers/domain/script_project.rb +38 -0
  108. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +39 -10
  109. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +9 -44
  110. data/lib/project_types/script/layers/infrastructure/errors.rb +50 -19
  111. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +2 -2
  112. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +16 -21
  113. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +4 -4
  114. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +2 -2
  115. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +179 -0
  116. data/lib/project_types/script/layers/infrastructure/script_service.rb +35 -78
  117. data/lib/project_types/script/messages/messages.rb +33 -57
  118. data/lib/project_types/script/ui/error_handler.rb +116 -88
  119. data/lib/project_types/script/ui/printing_spinner.rb +1 -1
  120. data/lib/project_types/script/ui/strict_spinner.rb +1 -1
  121. data/lib/project_types/theme/cli.rb +19 -19
  122. data/lib/project_types/theme/commands/connect.rb +12 -12
  123. data/lib/project_types/theme/commands/create.rb +11 -11
  124. data/lib/project_types/theme/commands/deploy.rb +8 -8
  125. data/lib/project_types/theme/commands/generate.rb +3 -3
  126. data/lib/project_types/theme/commands/generate/env.rb +15 -15
  127. data/lib/project_types/theme/commands/push.rb +15 -15
  128. data/lib/project_types/theme/commands/serve.rb +5 -5
  129. data/lib/project_types/theme/forms/connect.rb +4 -4
  130. data/lib/project_types/theme/forms/create.rb +5 -5
  131. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +22 -22
  132. data/lib/project_types/theme/themekit.rb +15 -15
  133. data/lib/rubygems_plugin.rb +3 -3
  134. data/lib/shopify-cli/admin_api.rb +11 -11
  135. data/lib/shopify-cli/admin_api/populate_resource_command.rb +17 -17
  136. data/lib/shopify-cli/admin_api/schema.rb +3 -3
  137. data/lib/shopify-cli/api.rb +10 -10
  138. data/lib/shopify-cli/command.rb +1 -1
  139. data/lib/shopify-cli/commands.rb +9 -9
  140. data/lib/shopify-cli/commands/config.rb +28 -52
  141. data/lib/shopify-cli/commands/connect.rb +10 -10
  142. data/lib/shopify-cli/commands/create.rb +5 -5
  143. data/lib/shopify-cli/commands/help.rb +6 -6
  144. data/lib/shopify-cli/commands/logout.rb +3 -3
  145. data/lib/shopify-cli/commands/system.rb +32 -32
  146. data/lib/shopify-cli/commands/version.rb +2 -2
  147. data/lib/shopify-cli/context.rb +51 -23
  148. data/lib/shopify-cli/core.rb +4 -4
  149. data/lib/shopify-cli/core/entry_point.rb +5 -5
  150. data/lib/shopify-cli/core/executor.rb +1 -1
  151. data/lib/shopify-cli/core/help_resolver.rb +2 -2
  152. data/lib/shopify-cli/core/monorail.rb +16 -16
  153. data/lib/shopify-cli/db.rb +2 -2
  154. data/lib/shopify-cli/feature.rb +1 -1
  155. data/lib/shopify-cli/form.rb +1 -1
  156. data/lib/shopify-cli/git.rb +17 -17
  157. data/lib/shopify-cli/helpers.rb +1 -1
  158. data/lib/shopify-cli/helpers/haikunator.rb +1 -1
  159. data/lib/shopify-cli/heroku.rb +28 -28
  160. data/lib/shopify-cli/http_request.rb +2 -2
  161. data/lib/shopify-cli/js_deps.rb +12 -12
  162. data/lib/shopify-cli/js_system.rb +7 -7
  163. data/lib/shopify-cli/lazy_delegator.rb +55 -0
  164. data/lib/shopify-cli/messages/messages.rb +7 -16
  165. data/lib/shopify-cli/method_object.rb +1 -1
  166. data/lib/shopify-cli/oauth.rb +27 -27
  167. data/lib/shopify-cli/oauth/servlet.rb +9 -9
  168. data/lib/shopify-cli/options.rb +3 -3
  169. data/lib/shopify-cli/packager.rb +25 -25
  170. data/lib/shopify-cli/partners_api.rb +16 -16
  171. data/lib/shopify-cli/partners_api/organizations.rb +10 -10
  172. data/lib/shopify-cli/process_supervision.rb +7 -7
  173. data/lib/shopify-cli/project.rb +16 -16
  174. data/lib/shopify-cli/project_type.rb +3 -3
  175. data/lib/shopify-cli/resolve_constant.rb +1 -1
  176. data/lib/shopify-cli/resources.rb +1 -1
  177. data/lib/shopify-cli/resources/env_file.rb +10 -10
  178. data/lib/shopify-cli/result.rb +11 -11
  179. data/lib/shopify-cli/shopifolk.rb +6 -9
  180. data/lib/shopify-cli/sub_command.rb +1 -1
  181. data/lib/shopify-cli/task.rb +3 -3
  182. data/lib/shopify-cli/tasks.rb +7 -7
  183. data/lib/shopify-cli/tasks/create_api_client.rb +5 -5
  184. data/lib/shopify-cli/tasks/ensure_dev_store.rb +12 -12
  185. data/lib/shopify-cli/tasks/ensure_env.rb +15 -15
  186. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +4 -4
  187. data/lib/shopify-cli/tasks/select_org_and_shop.rb +19 -19
  188. data/lib/shopify-cli/tasks/update_dashboard_urls.rb +10 -10
  189. data/lib/shopify-cli/transform_data_structure.rb +86 -0
  190. data/lib/shopify-cli/tunnel.rb +30 -30
  191. data/lib/shopify-cli/version.rb +1 -1
  192. data/lib/shopify_cli.rb +56 -54
  193. data/shopify-cli.gemspec +6 -6
  194. data/vendor/deps/smart_properties/REVISION +1 -1
  195. data/vendor/deps/smart_properties/lib/smart_properties/property.rb +7 -1
  196. data/vendor/deps/smart_properties/lib/smart_properties/version.rb +1 -1
  197. data/vendor/gen/template/bin/update-deps +9 -9
  198. metadata +15 -11
  199. data/lib/project_types/extension/forms/register.rb +0 -47
  200. data/lib/project_types/script/commands/disable.rb +0 -25
  201. data/lib/project_types/script/commands/enable.rb +0 -78
  202. data/lib/project_types/script/graphql/shop_script_delete.graphql +0 -14
  203. data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +0 -28
  204. data/lib/project_types/script/layers/application/disable_script.rb +0 -21
  205. data/lib/project_types/script/layers/application/enable_script.rb +0 -23
  206. data/lib/project_types/script/script_project.rb +0 -63
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'shopify_cli'
2
+ require "shopify_cli"
3
3
 
4
4
  module Extension
5
5
  class ExtensionProject < ShopifyCli::Project
@@ -9,20 +9,27 @@ module Extension
9
9
  context,
10
10
  project_type: :extension,
11
11
  organization_id: nil,
12
- "#{ExtensionProjectKeys::EXTENSION_TYPE_KEY}": type
12
+ "#{ExtensionProjectKeys::SPECIFICATION_IDENTIFIER_KEY}": type
13
13
  )
14
14
  end
15
15
 
16
- def write_env_file(context:, title:, api_key: '', api_secret: '', registration_id: nil)
16
+ def write_env_file(
17
+ context:, title:, api_key: "", api_secret: "", registration_id: nil, registration_uuid: nil
18
+ )
17
19
  ShopifyCli::Resources::EnvFile.new(
18
20
  api_key: api_key,
19
21
  secret: api_secret,
20
22
  extra: {
21
23
  ExtensionProjectKeys::TITLE_KEY => title,
22
24
  ExtensionProjectKeys::REGISTRATION_ID_KEY => registration_id,
25
+ ExtensionProjectKeys::REGISTRATION_UUID_KEY => registration_uuid || generate_temporary_uuid,
23
26
  }.compact
24
27
  ).write(context)
25
28
 
29
+ reload
30
+ end
31
+
32
+ def reload
26
33
  current.reload unless project_empty?
27
34
  end
28
35
 
@@ -34,19 +41,19 @@ module Extension
34
41
  end
35
42
 
36
43
  def app
37
- Models::App.new(api_key: env['api_key'], secret: env['secret'])
44
+ Models::App.new(api_key: env["api_key"], secret: env["secret"])
38
45
  end
39
46
 
40
47
  def registered?
41
- property_present?('api_key') && property_present?('secret') && registration_id?
48
+ property_present?("api_key") && property_present?("secret") && registration_id?
42
49
  end
43
50
 
44
51
  def title
45
52
  get_extra_field(ExtensionProjectKeys::TITLE_KEY)
46
53
  end
47
54
 
48
- def extension_type_identifier
49
- config[ExtensionProjectKeys::EXTENSION_TYPE_KEY]
55
+ def specification_identifier
56
+ config[ExtensionProjectKeys::SPECIFICATION_IDENTIFIER_KEY]
50
57
  end
51
58
 
52
59
  def registration_id?
@@ -59,10 +66,18 @@ module Extension
59
66
  get_extra_field(ExtensionProjectKeys::REGISTRATION_ID_KEY).to_i
60
67
  end
61
68
 
69
+ def registration_uuid
70
+ get_extra_field(ExtensionProjectKeys::REGISTRATION_UUID_KEY)
71
+ end
72
+
62
73
  def reload
63
74
  @env = nil
64
75
  end
65
76
 
77
+ def self.generate_temporary_uuid
78
+ "dev-#{SecureRandom.uuid}"
79
+ end
80
+
66
81
  private
67
82
 
68
83
  def get_extra_field(key)
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
- require 'shopify_cli'
2
+ require "shopify_cli"
3
3
 
4
4
  module Extension
5
5
  module ExtensionProjectKeys
6
- REGISTRATION_ID_KEY = 'EXTENSION_ID'
7
- EXTENSION_TYPE_KEY = 'EXTENSION_TYPE'
8
- TITLE_KEY = 'EXTENSION_TITLE'
6
+ REGISTRATION_ID_KEY = "EXTENSION_ID"
7
+ REGISTRATION_UUID_KEY = "EXTENSION_UUID"
8
+ SPECIFICATION_IDENTIFIER_KEY = "EXTENSION_TYPE"
9
+ TITLE_KEY = "EXTENSION_TITLE"
9
10
  end
10
11
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'base64'
3
- require 'shopify_cli'
4
- require 'semantic/semantic'
2
+ require "base64"
3
+ require "shopify_cli"
4
+ require "semantic/semantic"
5
5
 
6
6
  module Extension
7
7
  module Features
@@ -14,8 +14,8 @@ module Extension
14
14
  SCRIPT_PATH = %w(build main.js).freeze
15
15
 
16
16
  NPM_LIST_COMMAND = %w(list).freeze
17
- YARN_LIST_COMMAND = %w(list --pattern).freeze
18
- NPM_LIST_PARAMETERS = %w(--prod).freeze
17
+ YARN_LIST_COMMAND = %w(list).freeze
18
+ NPM_LIST_PARAMETERS = %w(--prod --depth=1).freeze
19
19
  YARN_LIST_PARAMETERS = %w(--production).freeze
20
20
  private_constant :NPM_LIST_COMMAND, :YARN_LIST_COMMAND, :NPM_LIST_PARAMETERS, :YARN_LIST_PARAMETERS
21
21
 
@@ -31,61 +31,45 @@ module Extension
31
31
 
32
32
  def config(context)
33
33
  js_system = ShopifyCli::JsSystem.new(ctx: context)
34
- if js_system.package_manager == 'yarn'
34
+ if js_system.package_manager == "yarn"
35
35
  run_yarn_install(context, js_system)
36
36
  run_yarn_run_script(context, js_system)
37
37
  end
38
38
  filepath = File.join(context.root, SCRIPT_PATH)
39
- context.abort(context.message('features.argo.missing_file_error')) unless File.exist?(filepath)
39
+ context.abort(context.message("features.argo.missing_file_error")) unless File.exist?(filepath)
40
40
  begin
41
41
  {
42
- renderer_version: extract_argo_renderer_version(context),
42
+ renderer_version: renderer_package(context).version,
43
43
  serialized_script: Base64.strict_encode64(File.read(filepath).chomp),
44
44
  }
45
45
  rescue StandardError
46
- context.abort(context.message('features.argo.script_prepare_error'))
46
+ context.abort(context.message("features.argo.script_prepare_error"))
47
47
  end
48
48
  end
49
49
 
50
- private
51
-
52
- def extract_argo_renderer_version(context)
53
- result = run_list_command(context)
54
- found_version = find_version_number(context, result)
55
- context.abort(
56
- context.message('features.argo.dependencies.argo_renderer_package_invalid_version_error')
57
- ) if found_version.nil?
58
- ::Semantic::Version.new(found_version).to_s
59
- rescue ArgumentError
50
+ def renderer_package(context)
51
+ Features::ArgoRendererPackage.from_package_manager(run_list_command(context))
52
+ rescue Extension::PackageNotFound
60
53
  context.abort(
61
- context.message('features.argo.dependencies.argo_renderer_package_invalid_version_error')
54
+ context.message("features.argo.dependencies.argo_missing_renderer_package_error")
62
55
  )
63
56
  end
64
57
 
65
- def find_version_number(context, result)
66
- packages = result.to_json.split('\n')
67
- found_package = packages.find do |package|
68
- package.match(/#{renderer_package_name}@/)
69
- end
70
- if found_package.nil?
71
- error = "'#{renderer_package_name}' not found."
72
- context.abort(
73
- context.message('features.argo.dependencies.argo_missing_renderer_package_error', error)
74
- )
75
- end
76
- found_package.split('@')[2]&.strip
77
- end
58
+ private
78
59
 
79
60
  def run_list_command(context)
80
- js_system = ShopifyCli::JsSystem.new(ctx: context)
81
- result, error, status = js_system.call(
82
- yarn: YARN_LIST_COMMAND + [renderer_package_name] + YARN_LIST_PARAMETERS,
83
- npm: NPM_LIST_COMMAND + [renderer_package_name] + NPM_LIST_PARAMETERS,
61
+ yarn_list = YARN_LIST_COMMAND + YARN_LIST_PARAMETERS
62
+ npm_list = NPM_LIST_COMMAND + NPM_LIST_PARAMETERS
63
+
64
+ result, error, status = ShopifyCli::JsSystem.call(
65
+ context,
66
+ yarn: yarn_list,
67
+ npm: npm_list,
84
68
  capture_response: true
85
69
  )
86
- context.abort(
87
- context.message('features.argo.dependencies.argo_missing_renderer_package_error', error)
88
- ) unless status.success?
70
+ # context.abort(
71
+ # context.message("features.argo.dependencies.argo_missing_renderer_package_error", error)
72
+ # ) unless status.success?
89
73
  result
90
74
  end
91
75
 
@@ -97,7 +81,7 @@ module Extension
97
81
  )
98
82
 
99
83
  context.abort(
100
- context.message('features.argo.dependencies.yarn_install_error', error)
84
+ context.message("features.argo.dependencies.yarn_install_error", error)
101
85
  ) unless status.success?
102
86
  end
103
87
 
@@ -109,7 +93,7 @@ module Extension
109
93
  )
110
94
 
111
95
  context.abort(
112
- context.message('features.argo.dependencies.yarn_run_script_error', error)
96
+ context.message("features.argo.dependencies.yarn_run_script_error", error)
113
97
  ) unless status.success?
114
98
  end
115
99
  end
@@ -3,7 +3,7 @@
3
3
  module Extension
4
4
  module Features
5
5
  class ArgoConfig
6
- CONFIG_FILE_NAME = 'extension.config.yml'
6
+ CONFIG_FILE_NAME = "extension.config.yml"
7
7
 
8
8
  class << self
9
9
  def parse_yaml(context, permitted_keys = [])
@@ -11,7 +11,7 @@ module Extension
11
11
 
12
12
  return {} unless File.size?(file_name)
13
13
 
14
- require 'yaml' # takes 20ms, so deferred as late as possible.
14
+ require "yaml" # takes 20ms, so deferred as late as possible.
15
15
  begin
16
16
  config = YAML.load_file(file_name)
17
17
 
@@ -21,7 +21,7 @@ module Extension
21
21
  return {} if config.nil?
22
22
 
23
23
  unless config.is_a?(Hash)
24
- raise ShopifyCli::Abort, ShopifyCli::Context.message('core.yaml.error.not_hash', CONFIG_FILE_NAME)
24
+ raise ShopifyCli::Abort, ShopifyCli::Context.message("core.yaml.error.not_hash", CONFIG_FILE_NAME)
25
25
  end
26
26
 
27
27
  config.transform_keys!(&:to_sym)
@@ -31,7 +31,7 @@ module Extension
31
31
  rescue Psych::SyntaxError => e
32
32
  raise(
33
33
  ShopifyCli::Abort,
34
- ShopifyCli::Context.message('core.yaml.error.invalid', CONFIG_FILE_NAME, e.message)
34
+ ShopifyCli::Context.message("core.yaml.error.invalid", CONFIG_FILE_NAME, e.message)
35
35
  )
36
36
  end
37
37
  end
@@ -47,7 +47,7 @@ module Extension
47
47
  raise(
48
48
  ShopifyCli::Abort,
49
49
  ShopifyCli::Context.message(
50
- 'features.argo.config.unpermitted_keys',
50
+ "features.argo.config.unpermitted_keys",
51
51
  CONFIG_FILE_NAME,
52
52
  unpermitted_keys.map { |k| "\n- #{k}" }.join
53
53
  )
@@ -5,21 +5,21 @@ module Extension
5
5
  class ArgoDependencies
6
6
  def self.node_installed(min_major:, min_minor: nil)
7
7
  -> (context) do
8
- out, status = CLI::Kit::System.capture2('node', '-v')
9
- context.abort(context.message('features.argo.dependencies.node.node_not_installed')) unless status.success?
8
+ out, status = CLI::Kit::System.capture2("node", "-v")
9
+ context.abort(context.message("features.argo.dependencies.node.node_not_installed")) unless status.success?
10
10
 
11
- min_version = 'v' + min_major .to_s + '.' + (min_minor.nil? ? 'x' : min_minor.to_s) + '.x'
11
+ min_version = "v" + min_major .to_s + "." + (min_minor.nil? ? "x" : min_minor.to_s) + ".x"
12
12
  version = out.strip
13
13
  parsed_version = version.match(/v(?<major>\d+).(?<minor>\d+).(?<patch>\d+)/)
14
14
 
15
15
  unless min_major.nil? || parsed_version[:major].to_i >= min_major
16
- context.abort(context.message('features.argo.dependencies.node.version_too_low', version, min_version))
16
+ context.abort(context.message("features.argo.dependencies.node.version_too_low", version, min_version))
17
17
  end
18
18
 
19
19
  return if parsed_version[:major].to_i > min_major
20
20
 
21
21
  unless min_minor.nil? || parsed_version[:minor].to_i >= min_minor
22
- context.abort(context.message('features.argo.dependencies.node.version_too_low', version, min_version))
22
+ context.abort(context.message("features.argo.dependencies.node.version_too_low", version, min_version))
23
23
  end
24
24
  end
25
25
  end
@@ -0,0 +1,47 @@
1
+ module Extension
2
+ module Features
3
+ class ArgoRendererPackage
4
+ include SmartProperties
5
+
6
+ ARGO_CHECKOUT = "@shopify/argo-checkout"
7
+ ARGO_ADMIN = "@shopify/argo-admin"
8
+ ARGO_POST_PURCHASE = "@shopify/argo-post-purchase"
9
+
10
+ PACKAGE_NAMES = [
11
+ ARGO_CHECKOUT,
12
+ ARGO_ADMIN,
13
+ ARGO_POST_PURCHASE
14
+ ].freeze
15
+ MINIMUM_ARGO_VERSION = "0.9.3".freeze
16
+
17
+ property! :package_name, accepts: PACKAGE_NAMES
18
+ property! :version, accepts: String
19
+
20
+ class << self
21
+ def from_package_manager(package_manager_output)
22
+ pattern = /(?<name>#{PACKAGE_NAMES.join("|")})@(?<version>\d.*)$/
23
+ match = package_manager_output.match(pattern)
24
+ raise PackageNotFound, package_manager_output if match.nil?
25
+ return new(package_name: match[:name], version: match[:version].strip)
26
+ end
27
+ end
28
+
29
+ def checkout?
30
+ package_name == ARGO_CHECKOUT
31
+ end
32
+
33
+ def admin?
34
+ package_name == ARGO_ADMIN
35
+ end
36
+
37
+ ##
38
+ # Temporarily returns false in all cases as the argo webpack server is
39
+ # unable to handle the UUID flag.
40
+ def supports_uuid_flag?
41
+ return false
42
+ # return false if checkout?
43
+ # Gem::Version.new(version) > Gem::Version.new(MINIMUM_ARGO_VERSION)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,69 @@
1
+ module Extension
2
+ module Features
3
+ class ArgoServe
4
+ include SmartProperties
5
+
6
+ property! :specification_handler, accepts: Extension::Models::SpecificationHandlers::Default
7
+ property! :context, accepts: ShopifyCli::Context
8
+
9
+ YARN_SERVE_COMMAND = %w(server)
10
+ NPM_SERVE_COMMAND = %w(run-script server)
11
+
12
+ def call
13
+ validate_env!
14
+
15
+ CLI::UI::Frame.open(context.message("serve.frame_title")) do
16
+ success = ShopifyCli::JsSystem.call(context, yarn: yarn_serve_command, npm: npm_serve_command)
17
+ context.abort(context.message("serve.serve_failure_message")) unless success
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def specification
24
+ specification_handler.specification
25
+ end
26
+
27
+ def validate_env!
28
+ ExtensionProject.reload
29
+
30
+ ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
31
+
32
+ required_fields = specification.features.argo.required_fields
33
+
34
+ return if required_fields.none?
35
+
36
+ ShopifyCli::Tasks::EnsureEnv.call(context, required: required_fields)
37
+ ShopifyCli::Tasks::EnsureDevStore.call(context) if required_fields.include?(:shop)
38
+
39
+ project = ExtensionProject.current
40
+
41
+ return if required_fields.all? do |field|
42
+ value = project.env.public_send(field)
43
+ value && !value.strip.empty?
44
+ end
45
+
46
+ context.abort(context.message("serve.serve_missing_information"))
47
+ end
48
+
49
+ def yarn_serve_command
50
+ YARN_SERVE_COMMAND + serve_options(specification.features.argo.required_fields)
51
+ end
52
+
53
+ def npm_serve_command
54
+ NPM_SERVE_COMMAND + ["--"] + serve_options(specification.features.argo.required_fields)
55
+ end
56
+
57
+ def serve_options(required_fields)
58
+ renderer_package = specification_handler.renderer_package(context)
59
+ project = ExtensionProject.current
60
+ @serve_options ||= [].tap do |options|
61
+ options << "--shop=#{project.env.shop}" if required_fields.include?(:shop)
62
+ options << "--apiKey=#{project.env.api_key}" if required_fields.include?(:api_key)
63
+ options << "--argoVersion=#{renderer_package.version}" if renderer_package.admin?
64
+ options << "--uuid=#{project.registration_uuid}" if renderer_package.supports_uuid_flag?
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -5,11 +5,11 @@ module Extension
5
5
  class ArgoSetup
6
6
  include SmartProperties
7
7
 
8
- GIT_DIRECTORY = '.git'
9
- SCRIPTS_DIRECTORY = 'scripts'
8
+ GIT_DIRECTORY = ".git"
9
+ SCRIPTS_DIRECTORY = "scripts"
10
10
 
11
11
  property! :git_template, accepts: String
12
- property! :dependency_checks, default: []
12
+ property! :dependency_checks, default: -> { [] }
13
13
 
14
14
  def call(directory_name, identifier, context)
15
15
  steps = [
@@ -5,7 +5,7 @@ module Extension
5
5
  module ArgoSetupSteps
6
6
  YARN_INITIALIZE_COMMAND = %w(generate).freeze
7
7
  NPM_INITIALIZE_COMMAND = %w(run generate --).freeze
8
- INITIALIZE_TYPE_PARAMETER = '--type=%s'
8
+ INITIALIZE_TYPE_PARAMETER = "--type=%s"
9
9
 
10
10
  def self.check_dependencies(dependency_checks)
11
11
  ArgoSetupStep.always_successful do |context, _identifier, _directory_name, _js_system|
@@ -21,7 +21,7 @@ module Extension
21
21
  ShopifyCli::Git.clone(git_template, directory_name, ctx: context)
22
22
  context.root = File.join(context.root, directory_name)
23
23
  rescue StandardError
24
- context.puts('{{x}} Unable to clone the repository.')
24
+ context.puts("{{x}} Unable to clone the repository.")
25
25
  end
26
26
  end
27
27
  end
@@ -34,8 +34,8 @@ module Extension
34
34
 
35
35
  def self.initialize_project
36
36
  ArgoSetupStep.default do |context, identifier, _directory_name, js_system|
37
- frame_title = context.message('create.setup_project_frame_title')
38
- failure_message = context.message('features.argo.initialization_error')
37
+ frame_title = context.message("create.setup_project_frame_title")
38
+ failure_message = context.message("features.argo.initialization_error")
39
39
 
40
40
  result = true
41
41
  CLI::UI::Frame.open(frame_title, failure_text: failure_message) do