shopify-cli 2.0.0 → 2.2.0

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/Gemfile.lock +4 -4
  4. data/README.md +3 -1
  5. data/RELEASING.md +2 -0
  6. data/THEMEKIT_MIGRATION.md +18 -0
  7. data/lib/graphql/api_versions.graphql +1 -1
  8. data/lib/graphql/get_variant_id.graphql +16 -0
  9. data/lib/project_types/extension/cli.rb +10 -1
  10. data/lib/project_types/extension/commands/check.rb +44 -0
  11. data/lib/project_types/extension/commands/serve.rb +8 -2
  12. data/lib/project_types/extension/extension_project.rb +39 -1
  13. data/lib/project_types/extension/extension_project_keys.rb +1 -0
  14. data/lib/project_types/extension/features/argo_runtime.rb +6 -38
  15. data/lib/project_types/extension/features/argo_serve.rb +30 -1
  16. data/lib/project_types/extension/features/runtimes/admin.rb +29 -0
  17. data/lib/project_types/extension/features/runtimes/base.rb +19 -0
  18. data/lib/project_types/extension/features/runtimes/checkout_post_purchase.rb +23 -0
  19. data/lib/project_types/extension/features/runtimes/checkout_ui_extension.rb +29 -0
  20. data/lib/project_types/extension/messages/messages.rb +19 -6
  21. data/lib/project_types/extension/models/product.rb +12 -0
  22. data/lib/project_types/extension/models/specification_handlers/checkout_ui_extension.rb +10 -2
  23. data/lib/project_types/extension/models/specification_handlers/default.rb +13 -4
  24. data/lib/project_types/extension/models/specification_handlers/theme_app_extension.rb +15 -0
  25. data/lib/project_types/extension/tasks/configure_features.rb +1 -0
  26. data/lib/project_types/extension/tasks/converters/product_converter.rb +21 -0
  27. data/lib/project_types/extension/tasks/get_product.rb +22 -0
  28. data/lib/project_types/node/messages/messages.rb +1 -1
  29. data/lib/project_types/rails/messages/messages.rb +18 -18
  30. data/lib/project_types/script/commands/create.rb +1 -1
  31. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +3 -3
  32. data/lib/project_types/script/layers/infrastructure/script_service.rb +17 -2
  33. data/lib/project_types/theme/cli.rb +1 -0
  34. data/lib/project_types/theme/commands/init.rb +42 -0
  35. data/lib/project_types/theme/commands/serve.rb +3 -1
  36. data/lib/project_types/theme/forms/select.rb +1 -1
  37. data/lib/project_types/theme/messages/messages.rb +14 -3
  38. data/lib/shopify-cli/admin_api.rb +6 -2
  39. data/lib/shopify-cli/api.rb +2 -2
  40. data/lib/shopify-cli/context.rb +1 -1
  41. data/lib/shopify-cli/core/monorail.rb +8 -3
  42. data/lib/shopify-cli/http_request.rb +6 -0
  43. data/lib/shopify-cli/messages/messages.rb +9 -8
  44. data/lib/shopify-cli/packager.rb +5 -5
  45. data/lib/shopify-cli/theme/dev_server.rb +5 -5
  46. data/lib/shopify-cli/theme/dev_server/local_assets.rb +1 -1
  47. data/lib/shopify-cli/theme/file.rb +2 -2
  48. data/lib/shopify-cli/theme/syncer.rb +9 -5
  49. data/lib/shopify-cli/theme/theme.rb +5 -5
  50. data/lib/shopify-cli/tunnel.rb +1 -1
  51. data/lib/shopify-cli/version.rb +1 -1
  52. data/shopify-cli.gemspec +1 -1
  53. metadata +15 -4
@@ -0,0 +1,29 @@
1
+ module Extension
2
+ module Features
3
+ module Runtimes
4
+ class Admin < Base
5
+ ADMIN_UI_EXTENSIONS_RUN = "@shopify/admin-ui-extensions-run"
6
+ PRODUCT_SUBSCRIPTION = "PRODUCT_SUBSCRIPTION"
7
+
8
+ AVAILABLE_FLAGS = [
9
+ :api_key,
10
+ :name,
11
+ :port,
12
+ :public_url,
13
+ :renderer_version,
14
+ :resource_url,
15
+ :shop,
16
+ :uuid,
17
+ ]
18
+
19
+ def available_flags
20
+ AVAILABLE_FLAGS
21
+ end
22
+
23
+ def active_runtime?(cli_package, identifier)
24
+ cli_package.name == ADMIN_UI_EXTENSIONS_RUN && identifier == PRODUCT_SUBSCRIPTION
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module Extension
2
+ module Features
3
+ module Runtimes
4
+ class Base
5
+ def available_flags
6
+ []
7
+ end
8
+
9
+ def supports?(flag)
10
+ available_flags.include?(flag)
11
+ end
12
+
13
+ def active_runtime?(cli_package, identifier)
14
+ raise NotImplementedError
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Extension
2
+ module Features
3
+ module Runtimes
4
+ class CheckoutPostPurchase < Base
5
+ CHECKOUT_UI_EXTENSIONS_RUN = "@shopify/checkout-ui-extensions-run"
6
+ CHECKOUT_POST_PURCHASE = "CHECKOUT_POST_PURCHASE"
7
+
8
+ AVAILABLE_FLAGS = [
9
+ :port,
10
+ :public_url,
11
+ ]
12
+
13
+ def available_flags
14
+ AVAILABLE_FLAGS
15
+ end
16
+
17
+ def active_runtime?(cli_package, identifier)
18
+ cli_package.name == CHECKOUT_UI_EXTENSIONS_RUN && identifier == CHECKOUT_POST_PURCHASE
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module Extension
2
+ module Features
3
+ module Runtimes
4
+ class CheckoutUiExtension < Base
5
+ CHECKOUT_UI_EXTENSIONS_RUN = "@shopify/checkout-ui-extensions-run"
6
+
7
+ IDENTIFIERS = [
8
+ "CHECKOUT_ARGO_EXTENSION",
9
+ "CHECKOUT_UI_EXTENSION",
10
+ ]
11
+
12
+ AVAILABLE_FLAGS = [
13
+ :port,
14
+ :public_url,
15
+ :resource_url,
16
+ :shop,
17
+ ]
18
+
19
+ def available_flags
20
+ AVAILABLE_FLAGS
21
+ end
22
+
23
+ def active_runtime?(cli_package, identifier)
24
+ cli_package.name == CHECKOUT_UI_EXTENSIONS_RUN && IDENTIFIERS.include?(identifier)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -43,7 +43,7 @@ module Extension
43
43
  no_apps: "{{x}} You don’t have any apps.",
44
44
  learn_about_apps: "{{*}} Learn more about building apps at <https://shopify.dev/concepts/apps>, " \
45
45
  "or try creating a new app using {{command:shopify [node|rails] create}}.",
46
- loading_apps: "Loading your apps...",
46
+ loading_apps: "Loading your apps",
47
47
  no_available_extensions: "{{x}} There are no available extensions for this app.",
48
48
  },
49
49
  connect: {
@@ -51,7 +51,7 @@ module Extension
51
51
  incomplete_configuration: "Cannot connect extension due to missing configuration information",
52
52
  invalid_api_key: "The API key %s does not match any of your apps.",
53
53
  ask_registration: "Which extension would you like to connect to?",
54
- loading_extensions: "Loading your extensions...",
54
+ loading_extensions: "Loading your extensions",
55
55
  no_extensions: "{{x}} You don't have any extensions of type %s",
56
56
  learn_about_extensions: "{{*}} Learn more about building extensions at <https://shopify.dev/concepts/apps>, " \
57
57
  "or try creating a new extension using {{command:shopify extension create}}.",
@@ -65,7 +65,7 @@ module Extension
65
65
  Build your extension to prepare for deployment.
66
66
  Usage: {{command:%s extension build}}
67
67
  HELP
68
- frame_title: "Building extension with: %s...",
68
+ frame_title: "Building extension with: %s",
69
69
  build_failure_message: "Failed to build extension code.",
70
70
  },
71
71
  register: {
@@ -76,7 +76,7 @@ module Extension
76
76
  {{command:--api-key=API_KEY}} The API key used to register an app with the extension. This can be found on the app page on Partners Dashboard.
77
77
  HELP
78
78
  frame_title: "Registering Extension",
79
- waiting_text: "Registering with Shopify...",
79
+ waiting_text: "Registering with Shopify",
80
80
  already_registered: "Extension is already registered.",
81
81
  confirm_info: "This will create a new extension registration for %s, which can’t be undone.",
82
82
  confirm_question: "Would you like to register this extension? (y/n)",
@@ -90,7 +90,7 @@ module Extension
90
90
  Usage: {{command:%s extension push}}
91
91
  HELP
92
92
  frame_title: "Pushing your extension to Shopify",
93
- waiting_text: "Pushing code to Shopify...",
93
+ waiting_text: "Pushing code to Shopify",
94
94
  pushed_with_errors: "{{x}} Code pushed to Shopify with errors on %s.",
95
95
  push_with_errors_info: "{{*}} Fix these errors and run {{command:shopify extension push}} to " \
96
96
  "revalidate your extension.",
@@ -104,7 +104,7 @@ module Extension
104
104
  Options:
105
105
  {{command:--tunnel=TUNNEL}} Establish an ngrok tunnel (default: false)
106
106
  HELP
107
- frame_title: "Serving extension...",
107
+ frame_title: "Serving extension",
108
108
  no_available_ports_found: "No available ports found to run extension.",
109
109
  serve_failure_message: "Failed to run extension code.",
110
110
  serve_missing_information: "Missing shop or api_key.",
@@ -139,6 +139,10 @@ module Extension
139
139
  Usage: {{command:%1$s extension tunnel status}}
140
140
  HELP
141
141
  },
142
+ check: {
143
+ help: "Check your extension for errors, suggestions, and best practices.",
144
+ unsupported: "{{red:%s projects are not supported for `extension check`}}",
145
+ },
142
146
  features: {
143
147
  argo: {
144
148
  missing_file_error: "Could not find built extension file.",
@@ -162,12 +166,18 @@ module Extension
162
166
  tasks: {
163
167
  errors: {
164
168
  parse_error: "Unable to parse response from Partners Dashboard.",
169
+ store_error: "There was an error getting store data. Try again later.",
165
170
  },
166
171
  },
167
172
  errors: {
168
173
  unknown_type: "Unknown extension type %s",
169
174
  package_not_found: "`%s` package not found.",
170
175
  },
176
+ warnings: {
177
+ resource_url_auto_generation_failed: "{{*}} {{yellow:Warning:}} Unable to auto generate " \
178
+ "the extension resource URL because %s does not have any products. " \
179
+ "Please run {{bold:shopify populate products}} to generate sample products.",
180
+ },
171
181
  }
172
182
 
173
183
  TYPES = {
@@ -196,6 +206,9 @@ module Extension
196
206
  {{*}} You’re ready to start building {{green:%s}}!
197
207
  MESSAGE
198
208
  },
209
+ serve: {
210
+ unsupported: "shopify extension serve is not supported for theme app extensions",
211
+ },
199
212
  },
200
213
  },
201
214
  }
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Extension
4
+ module Models
5
+ class Product
6
+ include SmartProperties
7
+
8
+ property :variant_id, accepts: Integer, converts: :to_i
9
+ property :quantity, accepts: Integer, default: 1
10
+ end
11
+ end
12
+ end
@@ -12,9 +12,17 @@ module Extension
12
12
  **argo.config(context),
13
13
  }
14
14
  end
15
- end
16
15
 
17
- CheckoutArgoExtension = CheckoutUiExtension
16
+ def supplies_resource_url?
17
+ true
18
+ end
19
+
20
+ def build_resource_url(context:, shop:)
21
+ product = Tasks::GetProduct.call(context, shop)
22
+ return unless product
23
+ format("/cart/%<variant_id>d:%<quantity>d", variant_id: product.variant_id, quantity: 1)
24
+ end
25
+ end
18
26
  end
19
27
  end
20
28
  end
@@ -50,13 +50,14 @@ module Extension
50
50
  argo_runtime(context).supports?(:public_url)
51
51
  end
52
52
 
53
- def serve(context:, port:, tunnel_url:)
53
+ def serve(context:, port:, tunnel_url:, resource_url:)
54
54
  Features::ArgoServe.new(
55
55
  specification_handler: self,
56
56
  argo_runtime: argo_runtime(context),
57
57
  context: context,
58
58
  port: port,
59
59
  tunnel_url: tunnel_url,
60
+ resource_url: resource_url
60
61
  ).call
61
62
  end
62
63
 
@@ -65,9 +66,9 @@ module Extension
65
66
  end
66
67
 
67
68
  def argo_runtime(context)
68
- @argo_runtime ||= Features::ArgoRuntime.new(
69
- renderer: renderer_package(context),
70
- cli: cli_package(context),
69
+ @argo_runtime ||= Features::ArgoRuntime.find(
70
+ cli_package: cli_package(context),
71
+ identifier: identifier
71
72
  )
72
73
  end
73
74
 
@@ -90,6 +91,14 @@ module Extension
90
91
  end
91
92
  end
92
93
 
94
+ def supplies_resource_url?
95
+ false
96
+ end
97
+
98
+ def build_resource_url(shop)
99
+ raise NotImplementedError
100
+ end
101
+
93
102
  protected
94
103
 
95
104
  def argo
@@ -60,10 +60,25 @@ module Extension
60
60
  "Theme App Extension"
61
61
  end
62
62
 
63
+ def choose_port?(ctx)
64
+ ctx.abort(ctx.message("serve.unsupported"))
65
+ end
66
+
67
+ def establish_tunnel?(ctx)
68
+ ctx.abort(ctx.message("serve.unsupported"))
69
+ end
70
+
71
+ def serve(ctx)
72
+ ctx.abort(ctx.message("serve.unsupported"))
73
+ end
74
+
63
75
  private
64
76
 
65
77
  def validate(filename)
66
78
  dirname = File.dirname(filename)
79
+ # Skip files in the root of the directory tree
80
+ return false if dirname == "."
81
+
67
82
  unless SUPPORTED_BUCKETS.include?(dirname)
68
83
  raise Extension::Errors::InvalidFilenameError, "Invalid directory: #{dirname}"
69
84
  end
@@ -46,6 +46,7 @@ module Extension
46
46
  checkout: {
47
47
  git_template: "https://github.com/Shopify/checkout-ui-extensions-template",
48
48
  renderer_package_name: "@shopify/checkout-ui-extensions",
49
+ required_fields: [:shop],
49
50
  cli_package_name: "@shopify/checkout-ui-extensions-run",
50
51
  },
51
52
  }
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require "shopify_cli"
3
+
4
+ module Extension
5
+ module Tasks
6
+ module Converters
7
+ module ProductConverter
8
+ VARIANT_PATH = ["data", "products", "edges", 0, "node", "variants", "edges", 0, "node", "id"]
9
+
10
+ def self.from_hash(hash)
11
+ return nil if hash.nil?
12
+ variant = hash.dig(*VARIANT_PATH)
13
+ return unless variant
14
+ Models::Product.new(
15
+ variant_id: ShopifyCli::API.gid_to_id(variant)
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require "shopify_cli"
3
+
4
+ module Extension
5
+ module Tasks
6
+ class GetProduct < ShopifyCli::Task
7
+ API_VERSION = "2021-07"
8
+ GRAPHQL_FILE = "get_variant_id"
9
+
10
+ def call(context, shop)
11
+ response = ShopifyCli::AdminAPI.query(
12
+ context,
13
+ GRAPHQL_FILE,
14
+ shop: shop,
15
+ api_version: API_VERSION
16
+ )
17
+ context.abort(context.message("tasks.errors.store_error")) if response.nil?
18
+ Converters::ProductConverter.from_hash(response)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -129,7 +129,7 @@ module Node
129
129
  {{*}} To install and start using your app, open this URL in your browser:
130
130
  {{green:%s}}
131
131
  MESSAGE
132
- running_server: "Running server...",
132
+ running_server: "Running server",
133
133
  },
134
134
 
135
135
  tunnel: {
@@ -17,7 +17,7 @@ module Rails
17
17
  checking_installation_path: "Checking path %s for gem %s",
18
18
  installed: "Installed %s gem",
19
19
  installed_debug: "%s installed: %s",
20
- installing: "Installing %s gem...",
20
+ installing: "Installing %s gem",
21
21
  setting_gem_home: "GEM_HOME being set to %s",
22
22
  setting_gem_path: "GEM_PATH being set to %s",
23
23
  },
@@ -62,15 +62,15 @@ module Rails
62
62
  open_new_shell: "{{*}} {{yellow:After installing %s, please open a new Command Prompt or PowerShell " \
63
63
  "window to continue.}}",
64
64
  },
65
- installing_bundler: "Installing bundler...",
66
- generating_app: "Generating new rails app project in %s...",
67
- adding_shopify_gem: "{{v}} Adding shopify_app gem...",
65
+ installing_bundler: "Installing bundler",
66
+ generating_app: "Generating new rails app project in %s",
67
+ adding_shopify_gem: "{{v}} Adding shopify_app gem",
68
68
  node_version: "node %s",
69
69
  yarn_version: "yarn %s",
70
- running_bundle_install: "Running bundle install...",
71
- running_generator: "Running shopify_app generator...",
72
- running_migrations: "Running migrations...",
73
- running_webpacker_install: "Running webpacker:install...",
70
+ running_bundle_install: "Running bundle install",
71
+ running_generator: "Running shopify_app generator",
72
+ running_migrations: "Running migrations",
73
+ running_webpacker_install: "Running webpacker:install",
74
74
  },
75
75
 
76
76
  deploy: {
@@ -89,18 +89,18 @@ module Rails
89
89
  Deploy the current Rails project to Heroku
90
90
  Usage: {{command:%s rails deploy heroku}}
91
91
  HELP
92
- downloading: "Downloading Heroku CLI...",
92
+ downloading: "Downloading Heroku CLI",
93
93
  downloaded: "Downloaded Heroku CLI",
94
- installing: "Installing Heroku CLI...",
94
+ installing: "Installing Heroku CLI",
95
95
  installed: "Installed Heroku CLI",
96
96
  authenticated_with_account: "{{v}} Authenticated with Heroku as {{green:%s}}",
97
- authenticating: "Authenticating with Heroku...",
97
+ authenticating: "Authenticating with Heroku",
98
98
  authenticated: "{{v}} Authenticated with Heroku",
99
- deploying: "Deploying to Heroku...",
99
+ deploying: "Deploying to Heroku",
100
100
  deployed: "{{v}} Deployed to Heroku",
101
101
  db_check: {
102
- validating: "Validating application...",
103
- checking: "Checking database type...",
102
+ validating: "Validating application",
103
+ checking: "Checking database type",
104
104
  validated: "Database type \"%s\" validated for platform \"Heroku\"",
105
105
  problem: "A problem was encountered while checking your database type.",
106
106
  sqlite: <<~SQLITE,
@@ -110,7 +110,7 @@ module Rails
110
110
  SQLITE
111
111
  },
112
112
  git: {
113
- checking: "Checking git repo...",
113
+ checking: "Checking git repo",
114
114
  initialized: "Git repo initialized",
115
115
  what_branch: "What branch would you like to deploy?",
116
116
  branch_selected: "{{v}} Git branch {{green:%s}} selected for deploy",
@@ -119,10 +119,10 @@ module Rails
119
119
  no_apps_found: "No existing Heroku app found. What would you like to do?",
120
120
  name: "What is your Heroku app’s name?",
121
121
  select: "Specify an existing Heroku app",
122
- selecting: "Selecting Heroku app %s...",
122
+ selecting: "Selecting Heroku app %s",
123
123
  selected: "{{v}} Heroku app {{green:%s}} selected",
124
124
  create: "Create a new Heroku app",
125
- creating: "Creating new Heroku app...",
125
+ creating: "Creating new Heroku app",
126
126
  created: "{{v}} New Heroku app created",
127
127
  },
128
128
  },
@@ -180,7 +180,7 @@ module Rails
180
180
  {{*}} To install and start using your app, open this URL in your browser:
181
181
  {{green:%s}}
182
182
  MESSAGE
183
- running_server: "Running server...",
183
+ running_server: "Running server",
184
184
  },
185
185
 
186
186
  tunnel: {