shopify-cli 1.13.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) 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/workflows/build.yml +1 -1
  6. data/.gitignore +3 -0
  7. data/.rubocop.yml +3 -1
  8. data/.ruby-version +1 -1
  9. data/CHANGELOG.md +60 -26
  10. data/Gemfile +4 -0
  11. data/Gemfile.lock +32 -0
  12. data/LICENSE +4 -1
  13. data/README.md +94 -26
  14. data/RELEASING.md +31 -7
  15. data/Rakefile +2 -2
  16. data/SECURITY.md +1 -1
  17. data/THEMEKIT_MIGRATION.md +18 -0
  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/api_versions.graphql +1 -1
  36. data/lib/graphql/find_organization.graphql +2 -1
  37. data/lib/project_types/extension/cli.rb +19 -15
  38. data/lib/project_types/extension/commands/build.rb +4 -5
  39. data/lib/project_types/extension/commands/check.rb +44 -0
  40. data/lib/project_types/extension/commands/connect.rb +35 -0
  41. data/lib/project_types/extension/commands/create.rb +12 -16
  42. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  43. data/lib/project_types/extension/commands/info.rb +86 -0
  44. data/lib/project_types/extension/commands/push.rb +8 -7
  45. data/lib/project_types/extension/commands/register.rb +4 -5
  46. data/lib/project_types/extension/commands/serve.rb +5 -8
  47. data/lib/project_types/extension/commands/tunnel.rb +3 -1
  48. data/lib/project_types/extension/errors.rb +9 -0
  49. data/lib/project_types/extension/extension_project.rb +24 -1
  50. data/lib/project_types/extension/extension_project_keys.rb +1 -0
  51. data/lib/project_types/extension/features/argo.rb +6 -6
  52. data/lib/project_types/extension/features/argo_runtime.rb +22 -66
  53. data/lib/project_types/extension/features/argo_serve.rb +25 -18
  54. data/lib/project_types/extension/forms/connect.rb +42 -0
  55. data/lib/project_types/extension/forms/questions/ask_name.rb +14 -6
  56. data/lib/project_types/extension/forms/questions/ask_registration.rb +51 -0
  57. data/lib/project_types/extension/messages/messages.rb +84 -16
  58. data/lib/project_types/extension/models/specification.rb +1 -0
  59. data/lib/project_types/extension/models/specification_handlers/{checkout_argo_extension.rb → checkout_ui_extension.rb} +3 -1
  60. data/lib/project_types/extension/models/specification_handlers/default.rb +13 -3
  61. data/lib/project_types/extension/models/specification_handlers/theme_app_extension.rb +89 -0
  62. data/lib/project_types/extension/models/specifications.rb +1 -0
  63. data/lib/project_types/extension/tasks/configure_features.rb +6 -7
  64. data/lib/project_types/extension/tasks/configure_options.rb +20 -0
  65. data/lib/project_types/extension/tasks/get_extensions.rb +32 -0
  66. data/lib/project_types/node/cli.rb +9 -21
  67. data/lib/project_types/node/commands/connect.rb +8 -2
  68. data/lib/project_types/node/commands/create.rb +9 -5
  69. data/lib/project_types/node/commands/deploy.rb +15 -5
  70. data/lib/project_types/node/commands/deploy/heroku.rb +29 -29
  71. data/lib/project_types/node/commands/generate.rb +4 -2
  72. data/lib/project_types/node/commands/open.rb +4 -2
  73. data/lib/project_types/node/commands/serve.rb +3 -2
  74. data/lib/project_types/node/commands/tunnel.rb +4 -2
  75. data/lib/project_types/node/messages/messages.rb +47 -90
  76. data/lib/project_types/rails/cli.rb +9 -21
  77. data/lib/project_types/rails/commands/connect.rb +8 -2
  78. data/lib/project_types/rails/commands/create.rb +10 -6
  79. data/lib/project_types/rails/commands/deploy.rb +15 -5
  80. data/lib/project_types/rails/commands/deploy/heroku.rb +84 -82
  81. data/lib/project_types/rails/commands/generate.rb +15 -5
  82. data/lib/project_types/rails/commands/generate/webhook.rb +28 -26
  83. data/lib/project_types/rails/commands/open.rb +4 -2
  84. data/lib/project_types/rails/commands/serve.rb +3 -2
  85. data/lib/project_types/rails/commands/tunnel.rb +4 -2
  86. data/lib/project_types/rails/messages/messages.rb +72 -119
  87. data/lib/project_types/script/cli.rb +6 -8
  88. data/lib/project_types/script/commands/create.rb +3 -1
  89. data/lib/project_types/script/commands/push.rb +7 -4
  90. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +9 -3
  91. data/lib/project_types/script/layers/application/create_script.rb +4 -3
  92. data/lib/project_types/script/layers/domain/errors.rb +6 -11
  93. data/lib/project_types/script/layers/domain/push_package.rb +4 -8
  94. data/lib/project_types/script/layers/domain/script_json.rb +32 -0
  95. data/lib/project_types/script/layers/domain/script_project.rb +1 -1
  96. data/lib/project_types/script/layers/infrastructure/errors.rb +13 -17
  97. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_project_creator.rb +29 -21
  98. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +2 -4
  99. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +45 -34
  100. data/lib/project_types/script/layers/infrastructure/script_service.rb +37 -16
  101. data/lib/project_types/script/messages/messages.rb +64 -54
  102. data/lib/project_types/script/tasks/ensure_env.rb +3 -1
  103. data/lib/project_types/script/ui/error_handler.rb +32 -32
  104. data/lib/project_types/theme/cli.rb +16 -27
  105. data/lib/project_types/theme/commands/check.rb +33 -0
  106. data/lib/project_types/theme/commands/delete.rb +64 -0
  107. data/lib/project_types/theme/commands/init.rb +42 -0
  108. data/lib/project_types/theme/commands/language_server.rb +16 -0
  109. data/lib/project_types/theme/commands/package.rb +55 -0
  110. data/lib/project_types/theme/commands/publish.rb +43 -0
  111. data/lib/project_types/theme/commands/pull.rb +51 -0
  112. data/lib/project_types/theme/commands/push.rb +58 -32
  113. data/lib/project_types/theme/commands/serve.rb +8 -16
  114. data/lib/project_types/theme/forms/confirm_store.rb +15 -0
  115. data/lib/project_types/theme/forms/select.rb +59 -0
  116. data/lib/project_types/theme/messages/messages.rb +118 -103
  117. data/lib/project_types/theme/ui/sync_progress_bar.rb +20 -0
  118. data/lib/shopify-cli/admin_api.rb +57 -38
  119. data/lib/shopify-cli/admin_api/populate_resource_command.rb +6 -14
  120. data/lib/shopify-cli/admin_api/schema.rb +1 -10
  121. data/lib/shopify-cli/api.rb +29 -14
  122. data/lib/shopify-cli/command.rb +15 -3
  123. data/lib/shopify-cli/commands.rb +7 -2
  124. data/lib/shopify-cli/commands/help.rb +2 -29
  125. data/lib/shopify-cli/commands/login.rb +95 -0
  126. data/lib/shopify-cli/commands/logout.rb +24 -8
  127. data/lib/shopify-cli/commands/populate.rb +23 -0
  128. data/lib/{project_types/node → shopify-cli}/commands/populate/customer.rb +2 -8
  129. data/lib/{project_types/node → shopify-cli}/commands/populate/draft_order.rb +2 -2
  130. data/lib/{project_types/node → shopify-cli}/commands/populate/product.rb +2 -8
  131. data/lib/shopify-cli/commands/store.rb +15 -0
  132. data/lib/shopify-cli/commands/switch.rb +39 -0
  133. data/lib/shopify-cli/commands/system.rb +12 -0
  134. data/lib/shopify-cli/commands/whoami.rb +28 -0
  135. data/lib/shopify-cli/connect.rb +32 -0
  136. data/lib/shopify-cli/context.rb +65 -4
  137. data/lib/shopify-cli/core/entry_point.rb +3 -22
  138. data/lib/shopify-cli/core/monorail.rb +6 -2
  139. data/lib/shopify-cli/db.rb +4 -4
  140. data/lib/shopify-cli/http_request.rb +16 -0
  141. data/lib/shopify-cli/identity_auth.rb +282 -0
  142. data/lib/shopify-cli/{oauth → identity_auth}/servlet.rb +11 -12
  143. data/lib/shopify-cli/messages/messages.rb +140 -46
  144. data/lib/shopify-cli/packager.rb +5 -5
  145. data/lib/shopify-cli/partners_api.rb +21 -44
  146. data/lib/shopify-cli/partners_api/organizations.rb +8 -0
  147. data/lib/shopify-cli/project_commands.rb +16 -0
  148. data/lib/shopify-cli/project_type.rb +0 -31
  149. data/lib/shopify-cli/shopifolk.rb +8 -11
  150. data/lib/shopify-cli/sub_command.rb +1 -0
  151. data/lib/shopify-cli/tasks.rb +3 -0
  152. data/lib/shopify-cli/tasks/confirm_store.rb +18 -0
  153. data/lib/shopify-cli/tasks/create_api_client.rb +2 -2
  154. data/lib/shopify-cli/tasks/ensure_authenticated.rb +13 -0
  155. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +1 -1
  156. data/lib/shopify-cli/tasks/ensure_project_type.rb +12 -0
  157. data/lib/shopify-cli/tasks/select_org_and_shop.rb +0 -3
  158. data/lib/shopify-cli/theme/dev_server.rb +98 -0
  159. data/lib/shopify-cli/theme/dev_server/certificate_manager.rb +79 -0
  160. data/lib/shopify-cli/theme/dev_server/header_hash.rb +94 -0
  161. data/lib/shopify-cli/theme/dev_server/hot-reload.js +93 -0
  162. data/lib/shopify-cli/theme/dev_server/hot_reload.rb +76 -0
  163. data/lib/shopify-cli/theme/dev_server/local_assets.rb +87 -0
  164. data/lib/shopify-cli/theme/dev_server/proxy.rb +205 -0
  165. data/lib/shopify-cli/theme/dev_server/sse.rb +75 -0
  166. data/lib/shopify-cli/theme/dev_server/watcher.rb +59 -0
  167. data/lib/shopify-cli/theme/dev_server/web_server.rb +140 -0
  168. data/lib/shopify-cli/theme/development_theme.rb +69 -0
  169. data/lib/shopify-cli/theme/file.rb +112 -0
  170. data/lib/shopify-cli/theme/ignore_filter.rb +109 -0
  171. data/lib/shopify-cli/theme/mime_type.rb +34 -0
  172. data/lib/shopify-cli/theme/syncer.rb +332 -0
  173. data/lib/shopify-cli/theme/theme.rb +204 -0
  174. data/lib/shopify-cli/tunnel.rb +1 -1
  175. data/lib/shopify-cli/version.rb +1 -1
  176. data/lib/shopify_cli.rb +18 -11
  177. data/shopify-cli.gemspec +12 -5
  178. data/shopify.fish +1 -1
  179. data/shopify.sh +1 -1
  180. metadata +92 -35
  181. data/.github/workflows/release.yml +0 -59
  182. data/lib/project_types/extension/features/argo_serve_options.rb +0 -42
  183. data/lib/project_types/node/commands/populate.rb +0 -23
  184. data/lib/project_types/rails/commands/populate.rb +0 -23
  185. data/lib/project_types/rails/commands/populate/customer.rb +0 -31
  186. data/lib/project_types/rails/commands/populate/draft_order.rb +0 -28
  187. data/lib/project_types/rails/commands/populate/product.rb +0 -30
  188. data/lib/project_types/script/layers/domain/config_ui.rb +0 -16
  189. data/lib/project_types/theme/commands/connect.rb +0 -54
  190. data/lib/project_types/theme/commands/create.rb +0 -48
  191. data/lib/project_types/theme/commands/deploy.rb +0 -38
  192. data/lib/project_types/theme/commands/generate.rb +0 -20
  193. data/lib/project_types/theme/commands/generate/env.rb +0 -79
  194. data/lib/project_types/theme/forms/connect.rb +0 -34
  195. data/lib/project_types/theme/forms/create.rb +0 -22
  196. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +0 -78
  197. data/lib/project_types/theme/themekit.rb +0 -113
  198. data/lib/shopify-cli/commands/connect.rb +0 -64
  199. data/lib/shopify-cli/commands/create.rb +0 -50
  200. data/lib/shopify-cli/oauth.rb +0 -198
@@ -1,6 +1,6 @@
1
1
  require "shopify_cli"
2
2
 
3
- module Node
3
+ module ShopifyCli
4
4
  module Commands
5
5
  class Populate
6
6
  class Customer < ShopifyCli::AdminAPI::PopulateResourceCommand
@@ -17,13 +17,7 @@ module Node
17
17
  def message(data)
18
18
  ret = data["customerCreate"]["customer"]
19
19
  id = ShopifyCli::API.gid_to_id(ret["id"])
20
- @ctx.message(
21
- "node.populate.customer.added",
22
- ret["displayName"],
23
- ShopifyCli::Project.current.env.shop,
24
- admin_url,
25
- id
26
- )
20
+ @ctx.message("core.populate.customer.added", ret["displayName"], @shop, admin_url, id)
27
21
  end
28
22
  end
29
23
  end
@@ -1,6 +1,6 @@
1
1
  require "shopify_cli"
2
2
 
3
- module Node
3
+ module ShopifyCli
4
4
  module Commands
5
5
  class Populate
6
6
  class DraftOrder < ShopifyCli::AdminAPI::PopulateResourceCommand
@@ -20,7 +20,7 @@ module Node
20
20
  def message(data)
21
21
  ret = data["draftOrderCreate"]["draftOrder"]
22
22
  id = ShopifyCli::API.gid_to_id(ret["id"])
23
- @ctx.message("node.populate.draft_order.added", ShopifyCli::Project.current.env.shop, admin_url, id)
23
+ @ctx.message("core.populate.draft_order.added", @shop, admin_url, id)
24
24
  end
25
25
  end
26
26
  end
@@ -1,6 +1,6 @@
1
1
  require "shopify_cli"
2
2
 
3
- module Node
3
+ module ShopifyCli
4
4
  module Commands
5
5
  class Populate
6
6
  class Product < ShopifyCli::AdminAPI::PopulateResourceCommand
@@ -16,13 +16,7 @@ module Node
16
16
  def message(data)
17
17
  ret = data["productCreate"]["product"]
18
18
  id = ShopifyCli::API.gid_to_id(ret["id"])
19
- @ctx.message(
20
- "node.populate.product.added",
21
- ret["title"],
22
- ShopifyCli::Project.current.env.shop,
23
- admin_url,
24
- id
25
- )
19
+ @ctx.message("core.populate.product.added", ret["title"], @shop, admin_url, id)
26
20
  end
27
21
  end
28
22
  end
@@ -0,0 +1,15 @@
1
+ require "shopify_cli"
2
+
3
+ module ShopifyCli
4
+ module Commands
5
+ class Store < ShopifyCli::Command
6
+ def call(_args, _name)
7
+ @ctx.puts(@ctx.message("core.store.shop", ShopifyCli::AdminAPI.get_shop_or_abort(@ctx)))
8
+ end
9
+
10
+ def self.help
11
+ ShopifyCli::Context.message("core.store.help", ShopifyCli::TOOL_NAME)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ require "shopify_cli"
2
+
3
+ module ShopifyCli
4
+ module Commands
5
+ class Switch < ShopifyCli::Command
6
+ options do |parser, flags|
7
+ parser.on("--store=STORE") { |url| flags[:shop] = url }
8
+ # backwards compatibility allow 'shop' for now
9
+ parser.on("--shop=SHOP") { |url| flags[:shop] = url }
10
+ end
11
+
12
+ def call(*)
13
+ if Shopifolk.acting_as_shopify_organization?
14
+ @ctx.puts(@ctx.message("core.switch.disabled_as_shopify_org"))
15
+ return
16
+ end
17
+
18
+ shop = if options.flags[:shop]
19
+ Login.validate_shop(options.flags[:shop])
20
+ elsif (org_id = DB.get(:organization_id))
21
+ res = ShopifyCli::Tasks::SelectOrgAndShop.call(@ctx, organization_id: org_id)
22
+ res[:shop_domain]
23
+ else
24
+ AdminAPI.get_shop_or_abort(@ctx)
25
+ res = ShopifyCli::Tasks::SelectOrgAndShop.call(@ctx)
26
+ res[:shop_domain]
27
+ end
28
+ DB.set(shop: shop)
29
+ IdentityAuth.new(ctx: @ctx).reauthenticate
30
+
31
+ @ctx.puts(@ctx.message("core.switch.success", shop))
32
+ end
33
+
34
+ def self.help
35
+ ShopifyCli::Context.message("core.switch.help", ShopifyCli::TOOL_NAME)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -20,6 +20,7 @@ module ShopifyCli
20
20
  display_environment if show_all_details
21
21
 
22
22
  display_cli_constants(show_all_details)
23
+ display_shopify_store(show_all_details)
23
24
  display_cli_ruby(show_all_details)
24
25
  display_utility_commands(show_all_details)
25
26
  display_project_commands(show_all_details)
@@ -59,6 +60,17 @@ module ShopifyCli
59
60
  end
60
61
  end
61
62
 
63
+ def display_shopify_store(_show_all_details)
64
+ shop = if ShopifyCli::DB.exists?(:shop)
65
+ ShopifyCli::AdminAPI.get_shop_or_abort(@ctx)
66
+ else
67
+ @ctx.message("core.populate.error.no_shop", ShopifyCli::TOOL_NAME)
68
+ end
69
+
70
+ @ctx.puts("\n" + @ctx.message("core.system.shop_header"))
71
+ @ctx.puts(" " + shop)
72
+ end
73
+
62
74
  def display_cli_ruby(_show_all_details)
63
75
  rbconfig_constants = %w(host RUBY_VERSION_NAME)
64
76
 
@@ -0,0 +1,28 @@
1
+ require "shopify_cli"
2
+
3
+ module ShopifyCli
4
+ module Commands
5
+ class Whoami < ShopifyCli::Command
6
+ def call(_args, _name)
7
+ shop = ShopifyCli::DB.get(:shop)
8
+ org_id = ShopifyCli::DB.get(:organization_id)
9
+ org = ShopifyCli::PartnersAPI::Organizations.fetch(@ctx, id: org_id) unless org_id.nil?
10
+
11
+ output = if shop.nil? && org.nil?
12
+ @ctx.message("core.whoami.not_logged_in", ShopifyCli::TOOL_NAME)
13
+ elsif !shop.nil? && org.nil?
14
+ @ctx.message("core.whoami.logged_in_shop_only", shop)
15
+ elsif shop.nil? && !org.nil?
16
+ @ctx.message("core.whoami.logged_in_partner_only", org["businessName"])
17
+ else
18
+ @ctx.message("core.whoami.logged_in_partner_and_shop", shop, org["businessName"])
19
+ end
20
+ @ctx.puts(output)
21
+ end
22
+
23
+ def self.help
24
+ ShopifyCli::Context.message("core.whoami.help", ShopifyCli::TOOL_NAME)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require "shopify_cli"
2
+
3
+ module ShopifyCli
4
+ class Connect
5
+ def initialize(ctx)
6
+ @ctx = ctx
7
+ end
8
+
9
+ def default_connect(project_type)
10
+ if Project.current&.env
11
+ @ctx.puts(@ctx.message("core.connect.already_connected_warning"))
12
+ end
13
+ org = ShopifyCli::Tasks::EnsureEnv.call(@ctx, regenerate: true)
14
+ write_cli_yml(project_type, org["id"]) unless Project.has_current?
15
+ api_key = Project.current(force_reload: true).env["api_key"]
16
+ get_app(org["apps"], api_key).first["title"]
17
+ end
18
+
19
+ def write_cli_yml(project_type, org_id)
20
+ ShopifyCli::Project.write(
21
+ @ctx,
22
+ project_type: project_type,
23
+ organization_id: org_id,
24
+ )
25
+ @ctx.done(@ctx.message("core.connect.cli_yml_saved"))
26
+ end
27
+
28
+ def get_app(apps, api_key)
29
+ apps.select { |app| app["apiKey"] == api_key }
30
+ end
31
+ end
32
+ end
@@ -61,9 +61,10 @@ module ShopifyCli
61
61
  # will return which operating system that the cli is running on [:mac, :linux]
62
62
  def os
63
63
  host = uname
64
- return :mac if /darwin/.match(host)
65
- return :linux if /linux/.match(host)
66
- return :windows if /mingw32/.match(host)
64
+ return :mac if /darwin/i.match(host)
65
+ return :windows if /mswin|mingw|cygwin/i.match(host)
66
+ return :linux if /linux|bsd/i.match(host)
67
+ :unknown
67
68
  end
68
69
 
69
70
  # will return true if the cli is running on an apple computer.
@@ -81,6 +82,16 @@ module ShopifyCli
81
82
  os == :windows
82
83
  end
83
84
 
85
+ # will return true if the os is unknown
86
+ def unknown_os?
87
+ os == :unknown
88
+ end
89
+
90
+ # will return true if being launched from a tty
91
+ def tty?
92
+ $stdin.tty? && !testing?
93
+ end
94
+
84
95
  # will return true if the cli is being run from an installation, and not a
85
96
  # development instance. The gem installation will not have a 'test' directory.
86
97
  # See `#development?` for checking for development environment.
@@ -106,6 +117,12 @@ module ShopifyCli
106
117
  ENV["CI"]
107
118
  end
108
119
 
120
+ ##
121
+ # will return true if the cli is running with the DEBUG flag
122
+ def debug?
123
+ getenv("DEBUG")
124
+ end
125
+
109
126
  # get a environment variable value by name.
110
127
  #
111
128
  # #### Parameters
@@ -144,6 +161,19 @@ module ShopifyCli
144
161
  File.write(ctx_path(fname), content)
145
162
  end
146
163
 
164
+ # will read a file relative to the context root unless the file path is absolute.
165
+ #
166
+ # #### Parameters
167
+ # * `fname` - filename of the file that you are reading, relative to root unless it is absolute.
168
+ #
169
+ # #### Example
170
+ #
171
+ # @ctx.read('file.txt')
172
+ #
173
+ def read(fname)
174
+ File.read(ctx_path(fname))
175
+ end
176
+
147
177
  # will read a binary file relative to the context root unless the file path is absolute.
148
178
  #
149
179
  # #### Parameters
@@ -286,6 +316,28 @@ module ShopifyCli
286
316
  puts(help)
287
317
  end
288
318
 
319
+ # will output to the console a link for the user to either copy/paste
320
+ # or click on.
321
+ #
322
+ # #### Parameters
323
+ # * `uri` - a http URI to open in a browser
324
+ #
325
+ def open_browser_url!(uri)
326
+ if tty?
327
+ if linux? && which("xdg-open")
328
+ system("xdg-open", uri.to_s)
329
+ elsif windows?
330
+ system("start \"\" \"#{uri}\"")
331
+ elsif mac?
332
+ system("open", uri.to_s)
333
+ else
334
+ open_url!(uri)
335
+ end
336
+ else
337
+ open_url!(uri)
338
+ end
339
+ end
340
+
289
341
  # will output a message, prefixed by a yellow star, indicating that task
290
342
  # started.
291
343
  #
@@ -305,6 +357,15 @@ module ShopifyCli
305
357
  Kernel.puts(CLI::UI.fmt(*args))
306
358
  end
307
359
 
360
+ # a wrapper around Kernel.warn to allow for easy formatting
361
+ #
362
+ # #### Parameters
363
+ # * `text` - a string message to output
364
+ #
365
+ def warn(*args)
366
+ Kernel.warn(CLI::UI.fmt(*args))
367
+ end
368
+
308
369
  # outputs a message, prefixed by a checkmark indicating that something completed
309
370
  #
310
371
  # #### Parameters
@@ -331,7 +392,7 @@ module ShopifyCli
331
392
  # * `text` - a string message to output
332
393
  #
333
394
  def debug(text)
334
- puts("{{red:DEBUG}} #{text}") if getenv("DEBUG")
395
+ puts("{{red:DEBUG}} #{text}") if debug?
335
396
  end
336
397
 
337
398
  # proxy call to Context.message.
@@ -5,35 +5,16 @@ module ShopifyCli
5
5
  module EntryPoint
6
6
  class << self
7
7
  def call(args, ctx = Context.new)
8
- # Check if the shim is set up by checking whether the old Finalizer FD exists
9
- begin
10
- is_shell_shim = false
11
- IO.open(9) { is_shell_shim = true }
12
- rescue Errno::EBADF
13
- # This is expected if the descriptor doesn't exist
14
- rescue ArgumentError => e
15
- # This can happen on RVM, because it can use fd 9 itself and block access to it. That only happens if the fd
16
- # did not exist beforehand, so that means there was no fd 9 before Ruby started.
17
- unless e.message == "The given fd is not accessible because RubyVM reserves it"
18
- raise e
19
- end
20
- end
21
-
22
- if !ctx.testing? && is_shell_shim
23
- ctx.puts(ctx.message("core.warning.shell_shim"))
24
- return
25
- end
26
-
27
8
  if ctx.development?
28
- ctx.puts(
9
+ ctx.warn(
29
10
  ctx.message("core.warning.development_version", File.join(ShopifyCli::ROOT, "bin", ShopifyCli::TOOL_NAME))
30
11
  )
31
12
  elsif !ctx.testing?
32
13
  new_version = ctx.new_version
33
- ctx.puts(ctx.message("core.warning.new_version", ShopifyCli::VERSION, new_version)) unless new_version.nil?
14
+ ctx.warn(ctx.message("core.warning.new_version", ShopifyCli::VERSION, new_version)) unless new_version.nil?
34
15
  end
35
16
 
36
- ProjectType.load_type(Project.current_project_type)
17
+ ProjectType.load_all
37
18
 
38
19
  task_registry = ShopifyCli::Tasks::Registry
39
20
 
@@ -90,7 +90,7 @@ module ShopifyCli
90
90
  {
91
91
  schema_id: INVOCATIONS_SCHEMA,
92
92
  payload: {
93
- project_type: Project.current_project_type.to_s,
93
+ project_type: project_type_from_dir_or_cmd(commands[0]).to_s,
94
94
  command: commands.join(" "),
95
95
  args: args.join(" "),
96
96
  time_start: start_time,
@@ -104,7 +104,7 @@ module ShopifyCli
104
104
  is_employee: ShopifyCli::Shopifolk.acting_as_shopify_organization?,
105
105
  }.tap do |payload|
106
106
  payload[:api_key] = metadata.delete(:api_key)
107
- payload[:partner_id] = metadata.delete(:organization_id)
107
+ payload[:partner_id] = metadata.delete(:organization_id) || ShopifyCli::DB.get(:organization_id)
108
108
  if Project.has_current?
109
109
  project = Project.current(force_reload: true)
110
110
  payload[:api_key] = project.env&.api_key
@@ -114,6 +114,10 @@ module ShopifyCli
114
114
  end,
115
115
  }
116
116
  end
117
+
118
+ def project_type_from_dir_or_cmd(command)
119
+ Project.current_project_type || (command unless ShopifyCli::Commands.core_command?(command)) || nil
120
+ end
117
121
  end
118
122
  end
119
123
  end
@@ -42,7 +42,7 @@ module ShopifyCli
42
42
  #
43
43
  # #### Usage
44
44
  #
45
- # exists = ShopifyCli::DB.exists?('admin_access_token')
45
+ # exists = ShopifyCli::DB.exists?('shopify_exchange_token')
46
46
  #
47
47
  def exists?(key)
48
48
  db.transaction(true) { db.root?(key) }
@@ -55,7 +55,7 @@ module ShopifyCli
55
55
  #
56
56
  # #### Usage
57
57
  #
58
- # ShopifyCli::DB.set(admin_access_token: 'token', metric_consent: true)
58
+ # ShopifyCli::DB.set(shopify_exchange_token: 'token', metric_consent: true)
59
59
  #
60
60
  def set(**args)
61
61
  db.transaction do
@@ -80,7 +80,7 @@ module ShopifyCli
80
80
  #
81
81
  # #### Usage
82
82
  #
83
- # ShopifyCli::DB.get(:admin_access_token)
83
+ # ShopifyCli::DB.get(:shopify_exchange_token)
84
84
  #
85
85
  def get(key)
86
86
  val = db.transaction(true) { db[key] }
@@ -95,7 +95,7 @@ module ShopifyCli
95
95
  #
96
96
  # #### Usage
97
97
  #
98
- # ShopifyCli::DB.del(:admin_access_token)
98
+ # ShopifyCli::DB.del(:shopify_exchange_token)
99
99
  #
100
100
  def del(*args)
101
101
  db.transaction { args.each { |key| db.delete(key) } }
@@ -1,4 +1,5 @@
1
1
  require "net/http"
2
+ require "openssl"
2
3
 
3
4
  module ShopifyCli
4
5
  class HttpRequest
@@ -8,14 +9,29 @@ module ShopifyCli
8
9
  request(uri, body, headers, req)
9
10
  end
10
11
 
12
+ def put(uri, body, headers)
13
+ req = ::Net::HTTP::Put.new(uri.request_uri)
14
+ request(uri, body, headers, req)
15
+ end
16
+
11
17
  def get(uri, body, headers)
12
18
  req = ::Net::HTTP::Get.new(uri.request_uri)
13
19
  request(uri, body, headers, req)
14
20
  end
15
21
 
22
+ def delete(uri, body, headers)
23
+ req = ::Net::HTTP::Delete.new(uri.request_uri)
24
+ request(uri, body, headers, req)
25
+ end
26
+
16
27
  def request(uri, body, headers, req)
28
+ cert_store = OpenSSL::X509::Store.new
29
+ cert_store.set_default_paths
30
+
17
31
  http = ::Net::HTTP.new(uri.host, uri.port)
18
32
  http.use_ssl = true
33
+ http.cert_store = cert_store
34
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ENV["SSL_VERIFY_NONE"]
19
35
 
20
36
  req.body = body unless body.nil?
21
37
  req["Content-Type"] = "application/json"