shopify-cli 1.12.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) 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 +52 -21
  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 +31 -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 -59
  50. data/lib/project_types/extension/features/argo_serve.rb +25 -21
  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 +13 -13
  58. data/lib/project_types/extension/models/specification_handlers/theme_app_extension.rb +89 -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 +37 -16
  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 +16 -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/init.rb +42 -0
  112. data/lib/project_types/theme/commands/language_server.rb +16 -0
  113. data/lib/project_types/theme/commands/package.rb +55 -0
  114. data/lib/project_types/theme/commands/publish.rb +43 -0
  115. data/lib/project_types/theme/commands/pull.rb +51 -0
  116. data/lib/project_types/theme/commands/push.rb +58 -32
  117. data/lib/project_types/theme/commands/serve.rb +8 -16
  118. data/lib/project_types/theme/forms/confirm_store.rb +15 -0
  119. data/lib/project_types/theme/forms/select.rb +59 -0
  120. data/lib/project_types/theme/messages/messages.rb +117 -102
  121. data/lib/project_types/theme/ui/sync_progress_bar.rb +20 -0
  122. data/lib/shopify-cli/admin_api.rb +53 -35
  123. data/lib/shopify-cli/admin_api/populate_resource_command.rb +6 -14
  124. data/lib/shopify-cli/admin_api/schema.rb +1 -10
  125. data/lib/shopify-cli/api.rb +29 -14
  126. data/lib/shopify-cli/command.rb +15 -3
  127. data/lib/shopify-cli/commands.rb +7 -2
  128. data/lib/shopify-cli/commands/help.rb +2 -29
  129. data/lib/shopify-cli/commands/login.rb +95 -0
  130. data/lib/shopify-cli/commands/logout.rb +24 -8
  131. data/lib/shopify-cli/commands/populate.rb +23 -0
  132. data/lib/{project_types/node → shopify-cli}/commands/populate/customer.rb +2 -8
  133. data/lib/{project_types/node → shopify-cli}/commands/populate/draft_order.rb +2 -2
  134. data/lib/{project_types/node → shopify-cli}/commands/populate/product.rb +2 -8
  135. data/lib/shopify-cli/commands/store.rb +15 -0
  136. data/lib/shopify-cli/commands/switch.rb +39 -0
  137. data/lib/shopify-cli/commands/system.rb +12 -0
  138. data/lib/shopify-cli/commands/whoami.rb +28 -0
  139. data/lib/shopify-cli/connect.rb +32 -0
  140. data/lib/shopify-cli/context.rb +65 -4
  141. data/lib/shopify-cli/core/entry_point.rb +3 -22
  142. data/lib/shopify-cli/db.rb +4 -4
  143. data/lib/shopify-cli/http_request.rb +16 -0
  144. data/lib/shopify-cli/identity_auth.rb +282 -0
  145. data/lib/shopify-cli/{oauth → identity_auth}/servlet.rb +11 -12
  146. data/lib/shopify-cli/messages/messages.rb +133 -39
  147. data/lib/shopify-cli/partners_api.rb +21 -41
  148. data/lib/shopify-cli/partners_api/organizations.rb +8 -0
  149. data/lib/shopify-cli/project_commands.rb +16 -0
  150. data/lib/shopify-cli/project_type.rb +0 -31
  151. data/lib/shopify-cli/resources/env_file.rb +1 -1
  152. data/lib/shopify-cli/shopifolk.rb +8 -11
  153. data/lib/shopify-cli/sub_command.rb +1 -0
  154. data/lib/shopify-cli/tasks.rb +3 -0
  155. data/lib/shopify-cli/tasks/confirm_store.rb +18 -0
  156. data/lib/shopify-cli/tasks/create_api_client.rb +2 -2
  157. data/lib/shopify-cli/tasks/ensure_authenticated.rb +13 -0
  158. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +1 -1
  159. data/lib/shopify-cli/tasks/ensure_project_type.rb +12 -0
  160. data/lib/shopify-cli/tasks/select_org_and_shop.rb +0 -3
  161. data/lib/shopify-cli/theme/dev_server.rb +98 -0
  162. data/lib/shopify-cli/theme/dev_server/certificate_manager.rb +79 -0
  163. data/lib/shopify-cli/theme/dev_server/header_hash.rb +94 -0
  164. data/lib/shopify-cli/theme/dev_server/hot-reload.js +93 -0
  165. data/lib/shopify-cli/theme/dev_server/hot_reload.rb +76 -0
  166. data/lib/shopify-cli/theme/dev_server/local_assets.rb +87 -0
  167. data/lib/shopify-cli/theme/dev_server/proxy.rb +205 -0
  168. data/lib/shopify-cli/theme/dev_server/sse.rb +75 -0
  169. data/lib/shopify-cli/theme/dev_server/watcher.rb +59 -0
  170. data/lib/shopify-cli/theme/dev_server/web_server.rb +140 -0
  171. data/lib/shopify-cli/theme/development_theme.rb +69 -0
  172. data/lib/shopify-cli/theme/file.rb +112 -0
  173. data/lib/shopify-cli/theme/ignore_filter.rb +109 -0
  174. data/lib/shopify-cli/theme/mime_type.rb +34 -0
  175. data/lib/shopify-cli/theme/syncer.rb +328 -0
  176. data/lib/shopify-cli/theme/theme.rb +204 -0
  177. data/lib/shopify-cli/version.rb +1 -1
  178. data/lib/shopify_cli.rb +18 -11
  179. data/shopify-cli.gemspec +12 -5
  180. data/shopify.fish +1 -1
  181. data/shopify.sh +1 -1
  182. metadata +96 -41
  183. data/.github/workflows/release.yml +0 -61
  184. data/lib/project_types/extension/features/argo_serve_options.rb +0 -41
  185. data/lib/project_types/node/commands/populate.rb +0 -23
  186. data/lib/project_types/rails/commands/populate.rb +0 -23
  187. data/lib/project_types/rails/commands/populate/customer.rb +0 -31
  188. data/lib/project_types/rails/commands/populate/draft_order.rb +0 -28
  189. data/lib/project_types/rails/commands/populate/product.rb +0 -30
  190. data/lib/project_types/script/layers/domain/config_ui.rb +0 -16
  191. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +0 -95
  192. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +0 -101
  193. data/lib/project_types/script/layers/infrastructure/project_creator.rb +0 -24
  194. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +0 -71
  195. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +0 -58
  196. data/lib/project_types/script/layers/infrastructure/task_runner.rb +0 -19
  197. data/lib/project_types/theme/commands/connect.rb +0 -54
  198. data/lib/project_types/theme/commands/create.rb +0 -48
  199. data/lib/project_types/theme/commands/deploy.rb +0 -38
  200. data/lib/project_types/theme/commands/generate.rb +0 -20
  201. data/lib/project_types/theme/commands/generate/env.rb +0 -79
  202. data/lib/project_types/theme/forms/connect.rb +0 -34
  203. data/lib/project_types/theme/forms/create.rb +0 -22
  204. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +0 -78
  205. data/lib/project_types/theme/themekit.rb +0 -113
  206. data/lib/shopify-cli/commands/connect.rb +0 -64
  207. data/lib/shopify-cli/commands/create.rb +0 -50
  208. data/lib/shopify-cli/oauth.rb +0 -198
@@ -1,23 +1,39 @@
1
1
  require "shopify_cli"
2
+ require "shopify-cli/theme/development_theme"
2
3
 
3
4
  module ShopifyCli
4
5
  module Commands
5
6
  class Logout < ShopifyCli::Command
6
- LOGIN_TOKENS = [
7
- :identity_access_token, :identity_refresh_token, :identity_exchange_token,
8
- :admin_access_token, :admin_refresh_token, :admin_exchange_token
9
- ]
10
-
11
7
  def call(*)
12
- LOGIN_TOKENS.each do |token|
13
- ShopifyCli::DB.del(token) if ShopifyCli::DB.exists?(token)
14
- end
8
+ try_delete_development_theme
9
+ ShopifyCli::IdentityAuth.delete_tokens_and_keys
10
+ ShopifyCli::DB.del(:shop) if has_shop?
11
+ ShopifyCli::DB.del(:organization_id) if has_organization_id?
12
+ ShopifyCli::Shopifolk.reset
15
13
  @ctx.puts(@ctx.message("core.logout.success"))
16
14
  end
17
15
 
18
16
  def self.help
19
17
  ShopifyCli::Context.message("core.logout.help", ShopifyCli::TOOL_NAME)
20
18
  end
19
+
20
+ private
21
+
22
+ def has_shop?
23
+ ShopifyCli::DB.exists?(:shop)
24
+ end
25
+
26
+ def has_organization_id?
27
+ ShopifyCli::DB.exists?(:organization_id)
28
+ end
29
+
30
+ def try_delete_development_theme
31
+ return unless has_shop?
32
+
33
+ ShopifyCli::Theme::DevelopmentTheme.delete(@ctx)
34
+ rescue ShopifyCli::API::APIRequestError
35
+ # Ignore since we can't delete it
36
+ end
21
37
  end
22
38
  end
23
39
  end
@@ -0,0 +1,23 @@
1
+ require "shopify_cli"
2
+
3
+ module ShopifyCli
4
+ module Commands
5
+ class Populate < ShopifyCli::Command
6
+ subcommand :Customer, "customers", "shopify-cli/commands/populate/customer"
7
+ subcommand :DraftOrder, "draftorders", "shopify-cli/commands/populate/draft_order"
8
+ subcommand :Product, "products", "shopify-cli/commands/populate/product"
9
+
10
+ def call(_args, _name)
11
+ @ctx.puts(self.class.help)
12
+ end
13
+
14
+ def self.help
15
+ ShopifyCli::Context.message("core.populate.help", ShopifyCli::TOOL_NAME)
16
+ end
17
+
18
+ def self.extended_help
19
+ ShopifyCli::Context.message("core.populate.extended_help", ShopifyCli::TOOL_NAME)
20
+ end
21
+ end
22
+ end
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 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
 
@@ -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) } }