shopify-cli 1.11.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/CONTRIBUTING.md +7 -7
  4. data/.github/DESIGN.md +3 -3
  5. data/.github/PULL_REQUEST_TEMPLATE.md +1 -1
  6. data/.github/workflows/build.yml +1 -1
  7. data/.gitignore +3 -0
  8. data/.rubocop.yml +3 -1
  9. data/.ruby-version +1 -1
  10. data/CHANGELOG.md +48 -20
  11. data/Gemfile +4 -0
  12. data/Gemfile.lock +32 -0
  13. data/LICENSE +4 -1
  14. data/README.md +92 -26
  15. data/RELEASING.md +29 -7
  16. data/Rakefile +2 -2
  17. data/SECURITY.md +1 -1
  18. data/bin/load_shopify.rb +1 -1
  19. data/bin/shopify +3 -3
  20. data/dev.yml +1 -1
  21. data/docs/app/node/index.md +1 -1
  22. data/docs/app/rails/index.md +1 -1
  23. data/docs/core/index.md +1 -1
  24. data/docs/getting-started/index.md +1 -1
  25. data/docs/getting-started/install/index.md +1 -1
  26. data/docs/getting-started/migrate/index.md +1 -1
  27. data/docs/getting-started/uninstall/index.md +1 -1
  28. data/docs/getting-started/upgrade/index.md +1 -1
  29. data/docs/help/start-app/index.md +1 -1
  30. data/docs/index.md +1 -1
  31. data/ext/shopify-cli/extconf.rb +17 -5
  32. data/install.sh +1 -1
  33. data/lib/docgen/index_template.md.erb +2 -2
  34. data/lib/graphql/all_orgs_with_extensions.graphql +37 -0
  35. data/lib/graphql/find_organization.graphql +2 -1
  36. data/lib/project_types/extension/cli.rb +18 -15
  37. data/lib/project_types/extension/commands/build.rb +4 -5
  38. data/lib/project_types/extension/commands/connect.rb +35 -0
  39. data/lib/project_types/extension/commands/create.rb +12 -16
  40. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  41. data/lib/project_types/extension/commands/info.rb +86 -0
  42. data/lib/project_types/extension/commands/push.rb +8 -7
  43. data/lib/project_types/extension/commands/register.rb +4 -5
  44. data/lib/project_types/extension/commands/serve.rb +5 -8
  45. data/lib/project_types/extension/commands/tunnel.rb +3 -1
  46. data/lib/project_types/extension/errors.rb +9 -0
  47. data/lib/project_types/extension/extension_project.rb +5 -0
  48. data/lib/project_types/extension/features/argo.rb +6 -6
  49. data/lib/project_types/extension/features/argo_runtime.rb +22 -38
  50. data/lib/project_types/extension/features/argo_serve.rb +25 -20
  51. data/lib/project_types/extension/forms/connect.rb +42 -0
  52. data/lib/project_types/extension/forms/questions/ask_name.rb +14 -6
  53. data/lib/project_types/extension/forms/questions/ask_registration.rb +51 -0
  54. data/lib/project_types/extension/messages/messages.rb +75 -11
  55. data/lib/project_types/extension/models/specification.rb +1 -0
  56. data/lib/project_types/extension/models/specification_handlers/{checkout_argo_extension.rb → checkout_ui_extension.rb} +3 -1
  57. data/lib/project_types/extension/models/specification_handlers/default.rb +21 -6
  58. data/lib/project_types/extension/models/specification_handlers/theme_app_extension.rb +86 -0
  59. data/lib/project_types/extension/models/specifications.rb +1 -0
  60. data/lib/project_types/extension/tasks/configure_features.rb +6 -7
  61. data/lib/project_types/extension/tasks/configure_options.rb +20 -0
  62. data/lib/project_types/extension/tasks/get_extensions.rb +32 -0
  63. data/lib/project_types/node/cli.rb +9 -21
  64. data/lib/project_types/node/commands/connect.rb +8 -2
  65. data/lib/project_types/node/commands/create.rb +9 -5
  66. data/lib/project_types/node/commands/deploy.rb +15 -5
  67. data/lib/project_types/node/commands/deploy/heroku.rb +29 -29
  68. data/lib/project_types/node/commands/generate.rb +4 -2
  69. data/lib/project_types/node/commands/open.rb +4 -2
  70. data/lib/project_types/node/commands/serve.rb +3 -2
  71. data/lib/project_types/node/commands/tunnel.rb +4 -2
  72. data/lib/project_types/node/messages/messages.rb +46 -89
  73. data/lib/project_types/rails/cli.rb +9 -21
  74. data/lib/project_types/rails/commands/connect.rb +8 -2
  75. data/lib/project_types/rails/commands/create.rb +10 -6
  76. data/lib/project_types/rails/commands/deploy.rb +15 -5
  77. data/lib/project_types/rails/commands/deploy/heroku.rb +84 -82
  78. data/lib/project_types/rails/commands/generate.rb +15 -5
  79. data/lib/project_types/rails/commands/generate/webhook.rb +28 -26
  80. data/lib/project_types/rails/commands/open.rb +4 -2
  81. data/lib/project_types/rails/commands/serve.rb +3 -2
  82. data/lib/project_types/rails/commands/tunnel.rb +4 -2
  83. data/lib/project_types/rails/messages/messages.rb +54 -101
  84. data/lib/project_types/script/cli.rb +18 -20
  85. data/lib/project_types/script/commands/create.rb +3 -1
  86. data/lib/project_types/script/commands/push.rb +12 -5
  87. data/lib/project_types/script/config/extension_points.yml +0 -3
  88. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +9 -3
  89. data/lib/project_types/script/layers/application/create_script.rb +6 -5
  90. data/lib/project_types/script/layers/application/push_script.rb +2 -1
  91. data/lib/project_types/script/layers/domain/errors.rb +6 -11
  92. data/lib/project_types/script/layers/domain/push_package.rb +4 -8
  93. data/lib/project_types/script/layers/domain/script_json.rb +32 -0
  94. data/lib/project_types/script/layers/domain/script_project.rb +1 -1
  95. data/lib/project_types/script/layers/infrastructure/errors.rb +14 -18
  96. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_project_creator.rb +105 -0
  97. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb +103 -0
  98. data/lib/project_types/script/layers/infrastructure/languages/project_creator.rb +26 -0
  99. data/lib/project_types/script/layers/infrastructure/languages/rust_project_creator.rb +73 -0
  100. data/lib/project_types/script/layers/infrastructure/languages/rust_task_runner.rb +60 -0
  101. data/lib/project_types/script/layers/infrastructure/languages/task_runner.rb +21 -0
  102. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +2 -4
  103. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +45 -34
  104. data/lib/project_types/script/layers/infrastructure/script_service.rb +20 -14
  105. data/lib/project_types/script/messages/messages.rb +66 -55
  106. data/lib/project_types/script/tasks/ensure_env.rb +22 -1
  107. data/lib/project_types/script/ui/error_handler.rb +32 -32
  108. data/lib/project_types/theme/cli.rb +15 -27
  109. data/lib/project_types/theme/commands/check.rb +33 -0
  110. data/lib/project_types/theme/commands/delete.rb +64 -0
  111. data/lib/project_types/theme/commands/language_server.rb +16 -0
  112. data/lib/project_types/theme/commands/package.rb +55 -0
  113. data/lib/project_types/theme/commands/publish.rb +43 -0
  114. data/lib/project_types/theme/commands/pull.rb +51 -0
  115. data/lib/project_types/theme/commands/push.rb +58 -32
  116. data/lib/project_types/theme/commands/serve.rb +7 -17
  117. data/lib/project_types/theme/forms/confirm_store.rb +15 -0
  118. data/lib/project_types/theme/forms/select.rb +59 -0
  119. data/lib/project_types/theme/messages/messages.rb +110 -106
  120. data/lib/project_types/theme/ui/sync_progress_bar.rb +20 -0
  121. data/lib/shopify-cli/admin_api.rb +53 -35
  122. data/lib/shopify-cli/admin_api/populate_resource_command.rb +6 -14
  123. data/lib/shopify-cli/admin_api/schema.rb +1 -10
  124. data/lib/shopify-cli/api.rb +29 -14
  125. data/lib/shopify-cli/command.rb +15 -3
  126. data/lib/shopify-cli/commands.rb +7 -2
  127. data/lib/shopify-cli/commands/help.rb +2 -29
  128. data/lib/shopify-cli/commands/login.rb +95 -0
  129. data/lib/shopify-cli/commands/logout.rb +24 -8
  130. data/lib/shopify-cli/commands/populate.rb +23 -0
  131. data/lib/{project_types/node → shopify-cli}/commands/populate/customer.rb +2 -8
  132. data/lib/{project_types/node → shopify-cli}/commands/populate/draft_order.rb +2 -2
  133. data/lib/{project_types/node → shopify-cli}/commands/populate/product.rb +2 -8
  134. data/lib/shopify-cli/commands/store.rb +15 -0
  135. data/lib/shopify-cli/commands/switch.rb +39 -0
  136. data/lib/shopify-cli/commands/system.rb +12 -0
  137. data/lib/shopify-cli/commands/whoami.rb +28 -0
  138. data/lib/shopify-cli/connect.rb +32 -0
  139. data/lib/shopify-cli/context.rb +65 -4
  140. data/lib/shopify-cli/core/entry_point.rb +3 -22
  141. data/lib/shopify-cli/db.rb +4 -4
  142. data/lib/shopify-cli/http_request.rb +10 -0
  143. data/lib/shopify-cli/identity_auth.rb +282 -0
  144. data/lib/shopify-cli/{oauth → identity_auth}/servlet.rb +11 -12
  145. data/lib/shopify-cli/messages/messages.rb +133 -39
  146. data/lib/shopify-cli/partners_api.rb +21 -41
  147. data/lib/shopify-cli/partners_api/organizations.rb +8 -0
  148. data/lib/shopify-cli/project_commands.rb +16 -0
  149. data/lib/shopify-cli/project_type.rb +0 -31
  150. data/lib/shopify-cli/resources/env_file.rb +1 -1
  151. data/lib/shopify-cli/shopifolk.rb +8 -11
  152. data/lib/shopify-cli/sub_command.rb +1 -0
  153. data/lib/shopify-cli/tasks.rb +3 -0
  154. data/lib/shopify-cli/tasks/confirm_store.rb +18 -0
  155. data/lib/shopify-cli/tasks/create_api_client.rb +2 -2
  156. data/lib/shopify-cli/tasks/ensure_authenticated.rb +13 -0
  157. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +1 -1
  158. data/lib/shopify-cli/tasks/ensure_project_type.rb +12 -0
  159. data/lib/shopify-cli/tasks/select_org_and_shop.rb +0 -3
  160. data/lib/shopify-cli/theme/dev_server.rb +98 -0
  161. data/lib/shopify-cli/theme/dev_server/certificate_manager.rb +79 -0
  162. data/lib/shopify-cli/theme/dev_server/header_hash.rb +94 -0
  163. data/lib/shopify-cli/theme/dev_server/hot-reload.js +93 -0
  164. data/lib/shopify-cli/theme/dev_server/hot_reload.rb +76 -0
  165. data/lib/shopify-cli/theme/dev_server/local_assets.rb +87 -0
  166. data/lib/shopify-cli/theme/dev_server/proxy.rb +205 -0
  167. data/lib/shopify-cli/theme/dev_server/sse.rb +75 -0
  168. data/lib/shopify-cli/theme/dev_server/watcher.rb +59 -0
  169. data/lib/shopify-cli/theme/dev_server/web_server.rb +140 -0
  170. data/lib/shopify-cli/theme/development_theme.rb +69 -0
  171. data/lib/shopify-cli/theme/file.rb +112 -0
  172. data/lib/shopify-cli/theme/ignore_filter.rb +109 -0
  173. data/lib/shopify-cli/theme/mime_type.rb +34 -0
  174. data/lib/shopify-cli/theme/syncer.rb +328 -0
  175. data/lib/shopify-cli/theme/theme.rb +204 -0
  176. data/lib/shopify-cli/version.rb +1 -1
  177. data/lib/shopify_cli.rb +18 -11
  178. data/shopify-cli.gemspec +12 -5
  179. data/shopify.fish +1 -1
  180. data/shopify.sh +1 -1
  181. metadata +95 -41
  182. data/.github/workflows/release.yml +0 -61
  183. data/lib/project_types/extension/features/argo_serve_options.rb +0 -40
  184. data/lib/project_types/node/commands/populate.rb +0 -23
  185. data/lib/project_types/rails/commands/populate.rb +0 -23
  186. data/lib/project_types/rails/commands/populate/customer.rb +0 -31
  187. data/lib/project_types/rails/commands/populate/draft_order.rb +0 -28
  188. data/lib/project_types/rails/commands/populate/product.rb +0 -30
  189. data/lib/project_types/script/layers/domain/config_ui.rb +0 -16
  190. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +0 -95
  191. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +0 -101
  192. data/lib/project_types/script/layers/infrastructure/project_creator.rb +0 -24
  193. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +0 -71
  194. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +0 -58
  195. data/lib/project_types/script/layers/infrastructure/task_runner.rb +0 -19
  196. data/lib/project_types/theme/commands/connect.rb +0 -54
  197. data/lib/project_types/theme/commands/create.rb +0 -48
  198. data/lib/project_types/theme/commands/deploy.rb +0 -38
  199. data/lib/project_types/theme/commands/generate.rb +0 -20
  200. data/lib/project_types/theme/commands/generate/env.rb +0 -79
  201. data/lib/project_types/theme/forms/connect.rb +0 -34
  202. data/lib/project_types/theme/forms/create.rb +0 -22
  203. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +0 -78
  204. data/lib/project_types/theme/themekit.rb +0 -113
  205. data/lib/shopify-cli/commands/connect.rb +0 -64
  206. data/lib/shopify-cli/commands/create.rb +0 -50
  207. data/lib/shopify-cli/oauth.rb +0 -198
@@ -1,21 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Extension
4
- module Commands
4
+ class Command
5
5
  class Create < ShopifyCli::SubCommand
6
+ prerequisite_task :ensure_authenticated
7
+
6
8
  options do |parser, flags|
7
9
  parser.on("--name=NAME") { |name| flags[:name] = name }
8
10
  parser.on("--type=TYPE") { |type| flags[:type] = type.upcase }
9
11
  parser.on("--api-key=KEY") { |key| flags[:api_key] = key.downcase }
12
+ parser.on("--getting-started") { flags[:getting_started] = true }
10
13
  end
11
14
 
12
15
  def call(args, _)
13
- with_create_form(args) do |form|
16
+ with_create_form(args) do |form, message_for_extension|
14
17
  if Dir.exist?(form.directory_name)
15
- @ctx.abort(@ctx.message("create.errors.directory_exists", form.directory_name))
18
+ @ctx.abort(message_for_extension["create.errors.directory_exists", form.directory_name])
16
19
  end
17
20
 
18
- if form.type.create(form.directory_name, @ctx)
21
+ if form.type.create(form.directory_name, @ctx, getting_started: options.flags[:getting_started])
19
22
  ExtensionProject.write_cli_file(context: @ctx, type: form.type.identifier)
20
23
  ExtensionProject.write_env_file(
21
24
  context: @ctx,
@@ -24,23 +27,16 @@ module Extension
24
27
  api_secret: form.app.secret
25
28
  )
26
29
 
27
- @ctx.puts(@ctx.message("create.ready_to_start", form.directory_name, form.name))
28
- @ctx.puts(@ctx.message("create.learn_more", form.type.name))
30
+ @ctx.puts(message_for_extension["create.ready_to_start", form.directory_name, form.name])
31
+ @ctx.puts(message_for_extension["create.learn_more", form.type.name])
29
32
  else
30
- @ctx.puts(@ctx.message("create.try_again"))
33
+ @ctx.puts(message_for_extension["create.try_again"])
31
34
  end
32
35
  end
33
36
  end
34
37
 
35
38
  def self.help
36
- <<~HELP
37
- Create a new app extension.
38
- Usage: {{command:#{ShopifyCli::TOOL_NAME} create extension}}
39
- Options:
40
- {{command:--type=TYPE}} The type of extension you would like to create.
41
- {{command:--name=NAME}} The name of your extension (50 characters).
42
- {{command:--api-key=KEY}} The API key of your app.
43
- HELP
39
+ @ctx.message("create.help", ShopifyCli::TOOL_NAME)
44
40
  end
45
41
 
46
42
  private
@@ -49,7 +45,7 @@ module Extension
49
45
  form = Forms::Create.ask(@ctx, args, options.flags)
50
46
  return @ctx.puts(self.class.help) if form.nil?
51
47
 
52
- yield form
48
+ yield form, form.type.method(:message_for_extension)
53
49
  end
54
50
  end
55
51
  end
@@ -2,8 +2,8 @@
2
2
  require "shopify_cli"
3
3
 
4
4
  module Extension
5
- module Commands
6
- class ExtensionCommand < ShopifyCli::Command
5
+ class Command
6
+ class ExtensionCommand < ShopifyCli::SubCommand
7
7
  def project
8
8
  @project ||= ExtensionProject.current
9
9
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ require "shopify_cli"
3
+
4
+ module Extension
5
+ class Command
6
+ class Info < ExtensionCommand
7
+ hidden_feature
8
+
9
+ def call(*)
10
+ @ctx.puts("Extension Title: #{project.title}")
11
+ @ctx.puts("Extension UUID: #{project.registration_uuid}")
12
+ @ctx.puts("Extension ID: #{project.registration_id}")
13
+ theme_app_extension_additional_info
14
+ end
15
+
16
+ def self.help
17
+ ShopifyCli::Context.new.message("info.help", ShopifyCli::TOOL_NAME)
18
+ end
19
+
20
+ private
21
+
22
+ OPENING_SCHEMA = "{%schema%}"
23
+ CLOSING_SCHEMA = "{%endschema%}"
24
+
25
+ def theme_app_extension_additional_info
26
+ if project.specification_identifier == "THEME_APP_EXTENSION" && (infos = block_infos)
27
+ title = to_handle(app.title)
28
+ uuid = project.registration_uuid
29
+ @ctx.puts("Block Infos \n")
30
+ index = 1
31
+ infos.each do |type, blocks_name|
32
+ @ctx.puts(" << #{type} >>\n")
33
+ blocks_name.each do |block_name|
34
+ @ctx.puts(" #{index}. shopify://apps/#{title}/blocks/#{block_name}/#{uuid} \n")
35
+ index += 1
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def app
42
+ @app ||= Tasks::GetApp.call(context: @ctx, api_key: project.app.api_key)
43
+ end
44
+
45
+ def block_infos
46
+ block_infos = {}
47
+ Dir["blocks/*.liquid"].map do |filename|
48
+ block_name = File.basename(filename, ".liquid")
49
+ json_schema = block_info(filename)
50
+
51
+ next unless json_schema
52
+ block_type = json_schema["target"] == "section" ? "App Block" : "App Embed"
53
+ block_infos[block_type] ||= []
54
+ block_infos[block_type] << block_name
55
+ end
56
+ block_infos
57
+ end
58
+
59
+ def block_info(filename)
60
+ output = File.read(filename)
61
+ output = output.gsub(/\s+/, "")
62
+
63
+ if output
64
+ opening_index = output.index(OPENING_SCHEMA) + OPENING_SCHEMA.size
65
+ closing_index = output.index(CLOSING_SCHEMA) - 1
66
+
67
+ if (schema = output.slice(opening_index..closing_index))
68
+ json_schema = JSON.parse(schema)
69
+ end
70
+ end
71
+ json_schema
72
+ rescue JSON::ParserError
73
+ {}
74
+ end
75
+
76
+ def to_handle(s)
77
+ s = s.dup
78
+ s.downcase!
79
+ s.delete!("'\"()[]")
80
+ s.gsub!(/\W+/, "-")
81
+ s.gsub!(/\A-+|-+\z/, "")
82
+ -s
83
+ end
84
+ end
85
+ end
86
+ end
@@ -2,13 +2,15 @@
2
2
  require "shopify_cli"
3
3
 
4
4
  module Extension
5
- module Commands
5
+ class Command
6
6
  class Push < ExtensionCommand
7
+ prerequisite_task ensure_project_type: :extension
8
+
7
9
  TIME_DISPLAY_FORMAT = "%B %d, %Y %H:%M:%S %Z"
8
10
 
9
11
  def call(args, name)
10
- Commands::Register.new(@ctx).call(args, name) unless project.registered?
11
- Commands::Build.new(@ctx).call(args, name)
12
+ Command::Register.new(@ctx).call(args, name) unless project.registered?
13
+ Command::Build.new(@ctx).call(args, name) unless specification_handler.specification.options[:skip_build]
12
14
 
13
15
  CLI::UI::Frame.open(@ctx.message("push.frame_title")) do
14
16
  updated_draft_version = update_draft
@@ -17,10 +19,7 @@ module Extension
17
19
  end
18
20
 
19
21
  def self.help
20
- <<~HELP
21
- Push the current extension to Shopify.
22
- Usage: {{command:#{ShopifyCli::TOOL_NAME} push}}
23
- HELP
22
+ ShopifyCli::Context.new.message("push.help", ShopifyCli::TOOL_NAME)
24
23
  end
25
24
 
26
25
  private
@@ -63,6 +62,8 @@ module Extension
63
62
  extension_context: specification_handler.extension_context(@ctx)
64
63
  )
65
64
  end
65
+ rescue Extension::Errors::ExtensionError => e
66
+ @ctx.abort(e)
66
67
  end
67
68
  end
68
69
  end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Extension
4
- module Commands
4
+ class Command
5
5
  class Register < ExtensionCommand
6
+ prerequisite_task ensure_project_type: :extension
7
+
6
8
  def call(_args, _command_name)
7
9
  CLI::UI::Frame.open(@ctx.message("register.frame_title")) do
8
10
  @ctx.abort(@ctx.message("register.already_registered")) if project.registered?
@@ -18,10 +20,7 @@ module Extension
18
20
  end
19
21
 
20
22
  def self.help
21
- <<~HELP
22
- Register your local extension to a Shopify app
23
- Usage: {{command:#{ShopifyCli::TOOL_NAME} register}}
24
- HELP
23
+ ShopifyCli::Context.new.message("register.help", ShopifyCli::TOOL_NAME)
25
24
  end
26
25
 
27
26
  private
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Extension
4
- module Commands
4
+ class Command
5
5
  class Serve < ExtensionCommand
6
+ prerequisite_task ensure_project_type: :extension
7
+
6
8
  DEFAULT_PORT = 39351
7
9
 
8
10
  options do |parser, flags|
@@ -12,7 +14,7 @@ module Extension
12
14
  class RuntimeConfiguration
13
15
  include SmartProperties
14
16
 
15
- property! :tunnel_url, accepts: String, default: ""
17
+ property :tunnel_url, accepts: String, default: nil
16
18
  property! :tunnel_requested, accepts: [true, false], reader: :tunnel_requested?, default: true
17
19
  property! :port, accepts: (1...(2**16)), default: DEFAULT_PORT
18
20
  end
@@ -31,12 +33,7 @@ module Extension
31
33
  end
32
34
 
33
35
  def self.help
34
- <<~HELP
35
- Serve your extension in a local simulator for development.
36
- Usage: {{command:#{ShopifyCli::TOOL_NAME} serve}}
37
- Options:
38
- {{command:--tunnel=TUNNEL}} Establish an ngrok tunnel (default: false)
39
- HELP
36
+ ShopifyCli::Context.new.message("serve.help", ShopifyCli::TOOL_NAME)
40
37
  end
41
38
 
42
39
  private
@@ -2,8 +2,10 @@
2
2
  require "shopify_cli"
3
3
 
4
4
  module Extension
5
- module Commands
5
+ class Command
6
6
  class Tunnel < ExtensionCommand
7
+ prerequisite_task ensure_project_type: :extension
8
+
7
9
  options do |parser, flags|
8
10
  parser.on("--port=PORT") { |port| flags[:port] = port }
9
11
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Extension
4
+ module Errors
5
+ class ExtensionError < StandardError; end
6
+ class InvalidFilenameError < ExtensionError; end
7
+ class BundleTooLargeError < ExtensionError; end
8
+ end
9
+ end
@@ -82,6 +82,11 @@ module Extension
82
82
  private
83
83
 
84
84
  def get_extra_field(key)
85
+ unless env
86
+ Kernel.puts("Run the command inside the correct extension directory.")
87
+ exit
88
+ end
89
+
85
90
  extra = env[:extra] || {}
86
91
  extra[key]
87
92
  end
@@ -19,14 +19,14 @@ module Extension
19
19
  YARN_RUN_SCRIPT_NAME = %w(build).freeze
20
20
  private_constant :YARN_INSTALL_COMMAND, :YARN_INSTALL_PARAMETERS, :YARN_RUN_COMMAND, :YARN_RUN_SCRIPT_NAME
21
21
 
22
- ARGO_CHECKOUT = "@shopify/argo-checkout"
23
- ARGO_ADMIN = "@shopify/argo-admin"
24
- ARGO_POST_PURCHASE = "@shopify/argo-post-purchase"
22
+ UI_EXTENSIONS_CHECKOUT = "@shopify/checkout-ui-extensions"
23
+ UI_EXTENSIONS_ADMIN = "@shopify/admin-ui-extensions"
24
+ UI_EXTENSIONS_POST_PURCHASE = "@shopify/post-purchase-ui-extensions"
25
25
 
26
26
  PACKAGE_NAMES = [
27
- ARGO_CHECKOUT,
28
- ARGO_ADMIN,
29
- ARGO_POST_PURCHASE,
27
+ UI_EXTENSIONS_CHECKOUT,
28
+ UI_EXTENSIONS_ADMIN,
29
+ UI_EXTENSIONS_POST_PURCHASE,
30
30
  ].freeze
31
31
 
32
32
  def create(directory_name, identifier, context)
@@ -3,60 +3,44 @@ module Extension
3
3
  class ArgoRuntime
4
4
  include SmartProperties
5
5
 
6
- ARGO_RUN_PACKAGE_NAME = "@shopify/argo-run"
7
- ARGO_ADMIN_CLI_PACKAGE_NAME = "@shopify/argo-admin-cli"
8
-
9
- ARGO_RUN_0_4_0 = Models::NpmPackage.new(name: "@shopify/argo-run", version: "0.4.0")
10
- ARGO_ADMIN_CLI_0_9_3 = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.9.3")
11
- ARGO_ADMIN_CLI_0_11_0 = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0")
6
+ UI_EXTENSIONS_CHECKOUT_RUN = "@shopify/checkout-ui-extensions-run"
7
+ UI_EXTENSIONS_ADMIN_RUN = "@shopify/admin-ui-extensions-run"
8
+
9
+ ADMIN_RUN_FLAGS = [
10
+ :api_key,
11
+ :name,
12
+ :port,
13
+ :public_url,
14
+ :renderer_version,
15
+ :shop,
16
+ :uuid,
17
+ ]
18
+
19
+ CHECKOUT_RUN_FLAGS = [
20
+ :port,
21
+ :public_url,
22
+ ]
12
23
 
13
24
  property! :renderer, accepts: Models::NpmPackage
14
25
  property! :cli, accepts: Models::NpmPackage
15
26
 
16
- def accepts_port?
27
+ def supports?(flag)
17
28
  case cli
18
29
  when admin?
19
- cli >= ARGO_ADMIN_CLI_0_11_0
30
+ ADMIN_RUN_FLAGS.include?(flag.to_sym)
20
31
  when checkout?
21
- cli >= ARGO_RUN_0_4_0
22
- end
23
- end
24
-
25
- def accepts_tunnel_url?
26
- case cli
27
- when admin?
28
- cli >= ARGO_ADMIN_CLI_0_11_0
29
- when checkout?
30
- cli >= ARGO_RUN_0_4_0
31
- end
32
- end
33
-
34
- def accepts_uuid?
35
- case cli
36
- when admin?
37
- cli >= ARGO_ADMIN_CLI_0_11_0
38
- else
39
- false
40
- end
41
- end
42
-
43
- def accepts_argo_version?
44
- case cli
45
- when admin?
46
- cli >= ARGO_ADMIN_CLI_0_9_3
47
- else
48
- false
32
+ CHECKOUT_RUN_FLAGS.include?(flag.to_sym)
49
33
  end
50
34
  end
51
35
 
52
36
  private
53
37
 
54
38
  def admin?
55
- ->(cli) { cli.name == ARGO_ADMIN_CLI_PACKAGE_NAME }
39
+ ->(cli) { cli.name == UI_EXTENSIONS_ADMIN_RUN }
56
40
  end
57
41
 
58
42
  def checkout?
59
- ->(cli) { cli.name == ARGO_RUN_PACKAGE_NAME }
43
+ ->(cli) { cli.name == UI_EXTENSIONS_CHECKOUT_RUN }
60
44
  end
61
45
  end
62
46
  end
@@ -3,25 +3,29 @@ module Extension
3
3
  class ArgoServe
4
4
  include SmartProperties
5
5
 
6
+ YARN_SERVE_COMMAND = %w(server)
7
+ NPM_SERVE_COMMAND = %w(run-script server)
8
+
6
9
  property! :specification_handler, accepts: Extension::Models::SpecificationHandlers::Default
7
10
  property! :argo_runtime, accepts: Features::ArgoRuntime
8
11
  property! :context, accepts: ShopifyCli::Context
9
12
  property! :port, accepts: Integer, default: 39351
10
- property :tunnel_url, accepts: String, default: ""
13
+ property :tunnel_url, accepts: String, default: nil
14
+ property! :js_system, accepts: ->(jss) { jss.respond_to?(:call) }, default: ShopifyCli::JsSystem
11
15
 
12
16
  def call
13
17
  validate_env!
14
18
 
15
19
  CLI::UI::Frame.open(context.message("serve.frame_title")) do
16
- success = call_js_system(yarn_command: yarn_serve_command, npm_command: npm_serve_command)
17
- context.abort(context.message("serve.serve_failure_message")) unless success
20
+ next if start_server
21
+ context.abort(context.message("serve.serve_failure_message"))
18
22
  end
19
23
  end
20
24
 
21
25
  private
22
26
 
23
- def call_js_system(yarn_command:, npm_command:)
24
- ShopifyCli::JsSystem.call(context, yarn: yarn_command, npm: npm_command)
27
+ def start_server
28
+ js_system.call(context, yarn: yarn_serve_command, npm: npm_serve_command)
25
29
  end
26
30
 
27
31
  def specification
@@ -36,30 +40,17 @@ module Extension
36
40
  specification.features.argo.required_fields
37
41
  end
38
42
 
39
- def serve_options
40
- @options ||= Features::ArgoServeOptions.new(
41
- argo_runtime: argo_runtime,
42
- port: port,
43
- context: context,
44
- required_fields: required_fields,
45
- renderer_package: renderer_package,
46
- public_url: tunnel_url
47
- )
48
- end
49
-
50
43
  def yarn_serve_command
51
- serve_options.yarn_serve_command
44
+ YARN_SERVE_COMMAND + options
52
45
  end
53
46
 
54
47
  def npm_serve_command
55
- serve_options.npm_serve_command
48
+ NPM_SERVE_COMMAND + ["--"] + options
56
49
  end
57
50
 
58
51
  def validate_env!
59
52
  ExtensionProject.reload
60
53
 
61
- ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
62
-
63
54
  return if required_fields.none?
64
55
 
65
56
  ShopifyCli::Tasks::EnsureEnv.call(context, required: required_fields)
@@ -74,6 +65,20 @@ module Extension
74
65
 
75
66
  context.abort(context.message("serve.serve_missing_information"))
76
67
  end
68
+
69
+ def options
70
+ project = ExtensionProject.current
71
+
72
+ @serve_options ||= [].tap do |options|
73
+ options << "--port=#{port}" if argo_runtime.supports?(:port)
74
+ options << "--store=#{project.env.shop}" if argo_runtime.supports?(:shop)
75
+ options << "--apiKey=#{project.env.api_key}" if argo_runtime.supports?(:api_key)
76
+ options << "--rendererVersion=#{renderer_package.version}" if argo_runtime.supports?(:renderer_version)
77
+ options << "--uuid=#{project.registration_uuid}" if argo_runtime.supports?(:uuid)
78
+ options << "--publicUrl=#{tunnel_url}" if !tunnel_url.nil? && argo_runtime.supports?(:public_url)
79
+ options << "--name=#{project.title}" if argo_runtime.supports?(:name)
80
+ end
81
+ end
77
82
  end
78
83
  end
79
84
  end