shopify-cli 1.9.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +1 -0
  3. data/.github/workflows/build.yml +28 -0
  4. data/.github/workflows/release.yml +2 -4
  5. data/CHANGELOG.md +27 -0
  6. data/Gemfile.lock +1 -1
  7. data/README.md +2 -1
  8. data/lib/project_types/extension/cli.rb +7 -1
  9. data/lib/project_types/extension/commands/serve.rb +69 -1
  10. data/lib/project_types/extension/commands/tunnel.rb +3 -1
  11. data/lib/project_types/extension/extension_project.rb +1 -0
  12. data/lib/project_types/extension/features/argo.rb +18 -49
  13. data/lib/project_types/extension/features/argo_runtime.rb +81 -0
  14. data/lib/project_types/extension/features/argo_serve.rb +35 -27
  15. data/lib/project_types/extension/features/argo_serve_options.rb +41 -0
  16. data/lib/project_types/extension/features/argo_setup.rb +1 -1
  17. data/lib/project_types/extension/messages/messages.rb +5 -4
  18. data/lib/project_types/extension/models/npm_package.rb +14 -0
  19. data/lib/project_types/extension/models/specification.rb +3 -2
  20. data/lib/project_types/extension/models/specification_handlers/checkout_argo_extension.rb +18 -0
  21. data/lib/project_types/extension/models/specification_handlers/default.rb +33 -3
  22. data/lib/project_types/extension/models/version.rb +1 -1
  23. data/lib/project_types/extension/tasks/choose_next_available_port.rb +36 -0
  24. data/lib/project_types/extension/tasks/configure_features.rb +2 -0
  25. data/lib/project_types/extension/tasks/find_npm_packages.rb +106 -0
  26. data/lib/project_types/node/messages/messages.rb +4 -4
  27. data/lib/project_types/rails/messages/messages.rb +4 -4
  28. data/lib/project_types/script/cli.rb +17 -12
  29. data/lib/project_types/script/commands/push.rb +1 -1
  30. data/lib/project_types/script/config/extension_points.yml +2 -3
  31. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +5 -2
  32. data/lib/project_types/script/graphql/get_app_scripts.graphql +6 -0
  33. data/lib/project_types/script/layers/application/create_script.rb +2 -2
  34. data/lib/project_types/script/layers/application/push_script.rb +6 -3
  35. data/lib/project_types/script/layers/domain/errors.rb +0 -2
  36. data/lib/project_types/script/layers/domain/push_package.rb +4 -0
  37. data/lib/project_types/script/layers/domain/script_project.rb +21 -1
  38. data/lib/project_types/script/layers/infrastructure/command_runner.rb +19 -0
  39. data/lib/project_types/script/layers/infrastructure/errors.rb +30 -3
  40. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_project_creator.rb +97 -0
  41. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb +103 -0
  42. data/lib/project_types/script/layers/infrastructure/languages/project_creator.rb +26 -0
  43. data/lib/project_types/script/layers/infrastructure/languages/rust_project_creator.rb +73 -0
  44. data/lib/project_types/script/layers/infrastructure/languages/rust_task_runner.rb +60 -0
  45. data/lib/project_types/script/layers/infrastructure/languages/task_runner.rb +21 -0
  46. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +6 -5
  47. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +61 -34
  48. data/lib/project_types/script/layers/infrastructure/script_service.rb +14 -2
  49. data/lib/project_types/script/messages/messages.rb +20 -3
  50. data/lib/project_types/script/tasks/ensure_env.rb +85 -0
  51. data/lib/project_types/script/ui/error_handler.rb +25 -6
  52. data/lib/shopify-cli/admin_api.rb +7 -4
  53. data/lib/shopify-cli/js_system.rb +2 -2
  54. data/lib/shopify-cli/messages/messages.rb +51 -45
  55. data/lib/shopify-cli/method_object.rb +4 -4
  56. data/lib/shopify-cli/oauth.rb +9 -3
  57. data/lib/shopify-cli/packager.rb +1 -1
  58. data/lib/shopify-cli/partners_api.rb +7 -4
  59. data/lib/shopify-cli/partners_api/organizations.rb +3 -3
  60. data/lib/shopify-cli/resolve_constant.rb +1 -1
  61. data/lib/shopify-cli/resources/env_file.rb +2 -2
  62. data/lib/shopify-cli/shopifolk.rb +1 -1
  63. data/lib/shopify-cli/tasks/select_org_and_shop.rb +6 -4
  64. data/lib/shopify-cli/transform_data_structure.rb +1 -1
  65. data/lib/shopify-cli/tunnel.rb +22 -1
  66. data/lib/shopify-cli/version.rb +1 -1
  67. data/lib/shopify_cli.rb +0 -1
  68. data/vendor/deps/smart_properties/REVISION +1 -1
  69. data/vendor/deps/smart_properties/lib/smart_properties/property.rb +7 -1
  70. data/vendor/deps/smart_properties/lib/smart_properties/version.rb +1 -1
  71. metadata +19 -11
  72. data/.travis.yml +0 -14
  73. data/lib/project_types/extension/features/argo_renderer_package.rb +0 -32
  74. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +0 -100
  75. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +0 -95
  76. data/lib/project_types/script/layers/infrastructure/project_creator.rb +0 -24
  77. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +0 -72
  78. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +0 -59
  79. data/lib/project_types/script/layers/infrastructure/task_runner.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1eb0f785e6ead5199faf7921e48209506987a24d942568e24661e96f2bc0861
4
- data.tar.gz: 06e4effc8a4b95bf78404630b452e4cf364407019846660b0d293cace45ae245
3
+ metadata.gz: efb6500804d976bce67276002bd2e95343cc080c7278fc7c510017676abb24a0
4
+ data.tar.gz: 3f0ab9095319fb4743fb37d19db43195c4fd4c737122ceada5958c00bad01b84
5
5
  SHA512:
6
- metadata.gz: 65df9edf44e3c2ce1263acb79d619736ffc6c4b30c50d9d71f6943dfa7c740dd0a9c9440a6879d46c59387f9bc2db6671cd65a31f700bf964b65bfb9dc1da2dc
7
- data.tar.gz: a1b9f5a17dc58b2570294205e33dd3fc1cb0a198bb4b7ca9594d91366d6169d4c92f7c9b7df0cbf8401f9a81123e78b55331ef8afd909247889a17cc046e58a2
6
+ metadata.gz: 27cf1b9e1256bb8732fbc291eb423a26ec1570e79cd960c9cc508e387ca58edeb5559680183f5a94009255b17f970e78ed4e1aee591f2782a29be2b9ab9b79b2
7
+ data.tar.gz: d6e489fc945ce4f27f3800238ff62b24b23073debfe29e48a196c972f7c7ebb34cea7f0affe7d7d326e48573e6df61c7ff68d062e261e83844fbd72cb0ce29ab
@@ -29,3 +29,4 @@ Fixes #0000 <!-- link to issue if one exists -->
29
29
  -->
30
30
  - [ ] I've added a CHANGELOG entry for this PR (if the change is public-facing)
31
31
  - [ ] I've considered possible cross-platform impacts (Mac, Linux, Windows).
32
+ - [ ] I've left the version number as is (we'll handle incrementing this when releasing).
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ name: Ruby ${{ matrix.version }}
8
+ runs-on: macos-latest
9
+ strategy:
10
+ matrix:
11
+ version:
12
+ - 3.0.0
13
+ - 2.6.6
14
+ - 2.7.1
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+
18
+ - name: Set up Ruby ${{ matrix.version }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.version }}
22
+ bundler-cache: true
23
+
24
+ - name: Install Dependencies
25
+ run: bundle install
26
+
27
+ - name: Run Tests
28
+ run: bundle exec rake
@@ -15,12 +15,10 @@ jobs:
15
15
  - uses: actions/checkout@v2
16
16
 
17
17
  - name: Set up Ruby
18
- uses: actions/setup-ruby@v1.1.2
18
+ uses: ruby/setup-ruby@v1
19
19
  with:
20
20
  ruby-version: 2.6
21
-
22
- - name: Install dependencies
23
- run: bundle install
21
+ bundler-cache: true
24
22
 
25
23
  - name: Create package
26
24
  run: bundle exec rake package
data/CHANGELOG.md CHANGED
@@ -1,6 +1,33 @@
1
1
  Unreleased
2
2
  ------
3
3
 
4
+ Version 1.13.0
5
+ --------------
6
+
7
+ * [1266](https://github.com/Shopify/shopify-app-cli/pull/1266): Developer Console release
8
+ * [1265](https://github.com/Shopify/shopify-app-cli/pull/1265): Fix bug where commands hang after an unsuccessful authentication
9
+
10
+ Version 1.12.0
11
+ --------------
12
+ * [1255](https://github.com/Shopify/shopify-app-cli/pull/1255): Fix beta flag checks when running `shopify serve`
13
+
14
+ Version 1.11.0
15
+ --------------
16
+ * [#1221](https://github.com/Shopify/shopify-app-cli/pull/1221): Prioritizes returning an HTTPS URL over HTTP from `shopify tunnel status`.
17
+ * [#1223](https://github.com/Shopify/shopify-app-cli/pull/1233): Running `shopify serve` in an extension project now automatically runs `shopify tunnel`.
18
+ * [#1225](https://github.com/Shopify/shopify-app-cli/pull/1225): Improved handling of "account not found" scenario, plus improvements to related tests and UX messaging
19
+ * [#1229](https://github.com/Shopify/shopify-app-cli/pull/1229): Allows Checkout Extensions to specify configuration attributes in their extension.config.yml file.
20
+ * [#1238](https://github.com/Shopify/shopify-app-cli/pull/1238): Auto Tunnel Support for Checkout Extension
21
+ * [#1256](https://github.com/Shopify/shopify-app-cli/pull/1256): Allow using spaces around the equal sign on .env file.
22
+
23
+ Version 1.10.0
24
+ --------------
25
+ * Updating internal features in development
26
+
27
+ Version 1.9.1
28
+ -------------
29
+ * [1201](https://github.com/Shopify/shopify-app-cli/pull/1201) Determine Argo Renderer Dynamically. This fixes `shopify serve` and `shopify push` for extensions.
30
+
4
31
  Version 1.9.0
5
32
  -------------
6
33
  * [1181](https://github.com/Shopify/shopify-app-cli/pull/1181): Remove the subcommand references of the `generate` command for node apps (fixes [1176](https://github.com/Shopify/shopify-app-cli/issues/1176))
data/Gemfile.lock CHANGED
@@ -76,4 +76,4 @@ DEPENDENCIES
76
76
  webmock
77
77
 
78
78
  BUNDLED WITH
79
- 1.17.3
79
+ 2.1.4
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # [Shopify App CLI](https://shopify.dev/tools/cli)
2
2
 
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md)[![Build Status](https://travis-ci.com/Shopify/shopify-app-cli.svg?token=qtPazgjyosjEEgxgq7VZ&branch=master)](https://travis-ci.com/Shopify/shopify-app-cli)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md)
4
+ [![Build Status](https://github.com/Shopify/shopify-app-cli/workflows/CI/badge.svg)](https://github.com/Shopify/shopify-app-cli/actions)
4
5
 
5
6
  Shopify App CLI helps you build Shopify apps faster. It quickly generates Node.js and Ruby on Rails apps and automates many common development tasks.
6
7
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Extension
4
+ class PackageResolutionFailed < RuntimeError; end
5
+
4
6
  class Project < ShopifyCli::ProjectType
5
7
  hidden_feature
6
8
  title("App Extension")
@@ -36,6 +38,8 @@ module Extension
36
38
  autoload :UpdateDraft, Project.project_filepath("tasks/update_draft")
37
39
  autoload :FetchSpecifications, Project.project_filepath("tasks/fetch_specifications")
38
40
  autoload :ConfigureFeatures, Project.project_filepath("tasks/configure_features")
41
+ autoload :ChooseNextAvailablePort, Project.project_filepath("tasks/choose_next_available_port")
42
+ autoload :FindNpmPackages, Project.project_filepath("tasks/find_npm_packages")
39
43
 
40
44
  module Converters
41
45
  autoload :RegistrationConverter, Project.project_filepath("tasks/converters/registration_converter")
@@ -57,13 +61,14 @@ module Extension
57
61
  end
58
62
 
59
63
  module Features
60
- autoload :ArgoRendererPackage, Project.project_filepath("features/argo_renderer_package")
61
64
  autoload :ArgoServe, Project.project_filepath("features/argo_serve")
65
+ autoload :ArgoServeOptions, Project.project_filepath("features/argo_serve_options")
62
66
  autoload :ArgoSetup, Project.project_filepath("features/argo_setup")
63
67
  autoload :ArgoSetupStep, Project.project_filepath("features/argo_setup_step")
64
68
  autoload :ArgoSetupSteps, Project.project_filepath("features/argo_setup_steps")
65
69
  autoload :ArgoDependencies, Project.project_filepath("features/argo_dependencies")
66
70
  autoload :ArgoConfig, Project.project_filepath("features/argo_config")
71
+ autoload :ArgoRuntime, Project.project_filepath("features/argo_runtime")
67
72
  autoload :Argo, Project.project_filepath("features/argo")
68
73
  end
69
74
 
@@ -79,6 +84,7 @@ module Extension
79
84
  autoload :Specification, Project.project_filepath("models/specification")
80
85
  autoload :Specifications, Project.project_filepath("models/specifications")
81
86
  autoload :LazySpecificationHandler, Project.project_filepath("models/lazy_specification_handler")
87
+ autoload :NpmPackage, Project.project_filepath("models/npm_package")
82
88
  end
83
89
 
84
90
  autoload :ExtensionProjectKeys, Project.project_filepath("extension_project_keys")
@@ -3,16 +3,84 @@
3
3
  module Extension
4
4
  module Commands
5
5
  class Serve < ExtensionCommand
6
+ DEFAULT_PORT = 39351
7
+
8
+ options do |parser, flags|
9
+ parser.on("-t", "--[no-]tunnel", "Establish an ngrok tunnel") { |tunnel| flags[:tunnel] = tunnel }
10
+ end
11
+
12
+ class RuntimeConfiguration
13
+ include SmartProperties
14
+
15
+ property! :tunnel_url, accepts: String, default: ""
16
+ property! :tunnel_requested, accepts: [true, false], reader: :tunnel_requested?, default: true
17
+ property! :port, accepts: (1...(2**16)), default: DEFAULT_PORT
18
+ end
19
+
6
20
  def call(_args, _command_name)
7
- specification_handler.serve(@ctx)
21
+ config = RuntimeConfiguration.new(
22
+ tunnel_requested: tunnel_requested?
23
+ )
24
+
25
+ ShopifyCli::Result
26
+ .success(config)
27
+ .then(&method(:find_available_port))
28
+ .then(&method(:start_tunnel_if_required))
29
+ .then(&method(:serve))
30
+ .unwrap { |error| raise error }
8
31
  end
9
32
 
10
33
  def self.help
11
34
  <<~HELP
12
35
  Serve your extension in a local simulator for development.
13
36
  Usage: {{command:#{ShopifyCli::TOOL_NAME} serve}}
37
+ Options:
38
+ {{command:--tunnel=TUNNEL}} Establish an ngrok tunnel (default: false)
14
39
  HELP
15
40
  end
41
+
42
+ private
43
+
44
+ def tunnel_requested?
45
+ tunnel = options.flags[:tunnel]
46
+ tunnel.nil? || !!tunnel
47
+ end
48
+
49
+ def find_available_port(runtime_configuration)
50
+ return runtime_configuration unless specification_handler.choose_port?(@ctx)
51
+
52
+ chosen_port = Tasks::ChooseNextAvailablePort
53
+ .call(from: runtime_configuration.port)
54
+ .unwrap { |_error| @ctx.abort(@ctx.message("serve.no_available_ports_found")) }
55
+ runtime_configuration.tap { |c| c.port = chosen_port }
56
+ end
57
+
58
+ def start_tunnel_if_required(runtime_configuration)
59
+ return runtime_configuration unless specification_handler.establish_tunnel?(@ctx)
60
+ return runtime_configuration unless runtime_configuration.tunnel_requested?
61
+
62
+ return start_tunnel(runtime_configuration) if can_start_tunnel?(runtime_configuration)
63
+ @ctx.abort(@ctx.message("serve.tunnel_already_running"))
64
+ end
65
+
66
+ def can_start_tunnel?(runtime_configuration)
67
+ return true if ShopifyCli::Tunnel.urls.empty?
68
+ ShopifyCli::Tunnel.running_on?(runtime_configuration.port)
69
+ end
70
+
71
+ def start_tunnel(runtime_configuration)
72
+ tunnel_url = ShopifyCli::Tunnel.start(@ctx, port: runtime_configuration.port)
73
+ runtime_configuration.tap { |c| c.tunnel_url = tunnel_url }
74
+ end
75
+
76
+ def serve(runtime_configuration)
77
+ specification_handler.serve(
78
+ context: @ctx,
79
+ tunnel_url: runtime_configuration.tunnel_url,
80
+ port: runtime_configuration.port
81
+ )
82
+ runtime_configuration
83
+ end
16
84
  end
17
85
  end
18
86
  end
@@ -37,7 +37,9 @@ module Extension
37
37
  private
38
38
 
39
39
  def status
40
- tunnel_url = ShopifyCli::Tunnel.urls.first
40
+ tunnel_urls = ShopifyCli::Tunnel.urls
41
+ tunnel_url = tunnel_urls.find { |url| url.start_with?("https://") }
42
+ tunnel_url = tunnel_urls.first if tunnel_url.nil?
41
43
 
42
44
  if tunnel_url.nil?
43
45
  @ctx.puts(@ctx.message("tunnel.no_tunnel_running"))
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "shopify_cli"
3
+ require "securerandom"
3
4
 
4
5
  module Extension
5
6
  class ExtensionProject < ShopifyCli::Project
@@ -13,18 +13,22 @@ module Extension
13
13
 
14
14
  SCRIPT_PATH = %w(build main.js).freeze
15
15
 
16
- NPM_LIST_COMMAND = %w(list).freeze
17
- YARN_LIST_COMMAND = %w(list --pattern).freeze
18
- NPM_LIST_PARAMETERS = %w(--prod).freeze
19
- YARN_LIST_PARAMETERS = %w(--production).freeze
20
- private_constant :NPM_LIST_COMMAND, :YARN_LIST_COMMAND, :NPM_LIST_PARAMETERS, :YARN_LIST_PARAMETERS
21
-
22
16
  YARN_INSTALL_COMMAND = %w(install).freeze
23
17
  YARN_INSTALL_PARAMETERS = %w(--silent).freeze
24
18
  YARN_RUN_COMMAND = %w(run).freeze
25
19
  YARN_RUN_SCRIPT_NAME = %w(build).freeze
26
20
  private_constant :YARN_INSTALL_COMMAND, :YARN_INSTALL_PARAMETERS, :YARN_RUN_COMMAND, :YARN_RUN_SCRIPT_NAME
27
21
 
22
+ ARGO_CHECKOUT = "@shopify/argo-checkout"
23
+ ARGO_ADMIN = "@shopify/argo-admin"
24
+ ARGO_POST_PURCHASE = "@shopify/argo-post-purchase"
25
+
26
+ PACKAGE_NAMES = [
27
+ ARGO_CHECKOUT,
28
+ ARGO_ADMIN,
29
+ ARGO_POST_PURCHASE,
30
+ ].freeze
31
+
28
32
  def create(directory_name, identifier, context)
29
33
  Features::ArgoSetup.new(git_template: git_template).call(directory_name, identifier, context)
30
34
  end
@@ -39,7 +43,7 @@ module Extension
39
43
  context.abort(context.message("features.argo.missing_file_error")) unless File.exist?(filepath)
40
44
  begin
41
45
  {
42
- renderer_version: extract_argo_renderer_version(context),
46
+ renderer_version: renderer_package(context).version,
43
47
  serialized_script: Base64.strict_encode64(File.read(filepath).chomp),
44
48
  }
45
49
  rescue StandardError
@@ -48,52 +52,17 @@ module Extension
48
52
  end
49
53
 
50
54
  def renderer_package(context)
51
- Features::ArgoRendererPackage.new(
52
- package_name: renderer_package_name, version: extract_argo_renderer_version(context)
53
- )
54
- end
55
-
56
- private
57
-
58
- def extract_argo_renderer_version(context)
59
- result = run_list_command(context)
60
- found_version = find_version_number(context, result)
61
- context.abort(
62
- context.message("features.argo.dependencies.argo_renderer_package_invalid_version_error")
63
- ) if found_version.nil?
64
- ::Semantic::Version.new(found_version).to_s
65
- rescue ArgumentError
55
+ js_system = ShopifyCli::JsSystem.new(ctx: context)
56
+ Tasks::FindNpmPackages
57
+ .exactly_one_of(*PACKAGE_NAMES, js_system: js_system)
58
+ .unwrap { |err| raise err }
59
+ rescue Extension::PackageResolutionFailed
66
60
  context.abort(
67
- context.message("features.argo.dependencies.argo_renderer_package_invalid_version_error")
61
+ context.message("features.argo.dependencies.argo_missing_renderer_package_error")
68
62
  )
69
63
  end
70
64
 
71
- def find_version_number(context, result)
72
- packages = result.to_json.split('\n')
73
- found_package = packages.find do |package|
74
- package.match(/#{renderer_package_name}@/)
75
- end
76
- if found_package.nil?
77
- error = "'#{renderer_package_name}' not found."
78
- context.abort(
79
- context.message("features.argo.dependencies.argo_missing_renderer_package_error", error)
80
- )
81
- end
82
- found_package.split("@")[2]&.strip
83
- end
84
-
85
- def run_list_command(context)
86
- js_system = ShopifyCli::JsSystem.new(ctx: context)
87
- result, error, status = js_system.call(
88
- yarn: YARN_LIST_COMMAND + [renderer_package_name] + YARN_LIST_PARAMETERS,
89
- npm: NPM_LIST_COMMAND + [renderer_package_name] + NPM_LIST_PARAMETERS,
90
- capture_response: true
91
- )
92
- context.abort(
93
- context.message("features.argo.dependencies.argo_missing_renderer_package_error", error)
94
- ) unless status.success?
95
- result
96
- end
65
+ private
97
66
 
98
67
  def run_yarn_install(context, js_system)
99
68
  _result, error, status = js_system.call(
@@ -0,0 +1,81 @@
1
+ module Extension
2
+ module Features
3
+ class ArgoRuntime
4
+ include SmartProperties
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")
12
+
13
+ property! :renderer, accepts: Models::NpmPackage
14
+ property! :cli, accepts: Models::NpmPackage
15
+
16
+ def accepts_port?
17
+ case cli
18
+ when admin?
19
+ cli >= ARGO_ADMIN_CLI_0_11_0
20
+ 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
49
+ end
50
+ end
51
+
52
+ def accepts_shop?
53
+ case cli
54
+ when admin?
55
+ cli >= ARGO_ADMIN_CLI_0_11_0
56
+ else
57
+ false
58
+ end
59
+ end
60
+
61
+ def accepts_api_key?
62
+ case cli
63
+ when admin?
64
+ cli >= ARGO_ADMIN_CLI_0_11_0
65
+ else
66
+ false
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def admin?
73
+ ->(cli) { cli.name == ARGO_ADMIN_CLI_PACKAGE_NAME }
74
+ end
75
+
76
+ def checkout?
77
+ ->(cli) { cli.name == ARGO_RUN_PACKAGE_NAME }
78
+ end
79
+ end
80
+ end
81
+ end
@@ -4,32 +4,59 @@ module Extension
4
4
  include SmartProperties
5
5
 
6
6
  property! :specification_handler, accepts: Extension::Models::SpecificationHandlers::Default
7
+ property! :argo_runtime, accepts: Features::ArgoRuntime
7
8
  property! :context, accepts: ShopifyCli::Context
8
-
9
- YARN_SERVE_COMMAND = %w(server)
10
- NPM_SERVE_COMMAND = %w(run-script server)
9
+ property! :port, accepts: Integer, default: 39351
10
+ property :tunnel_url, accepts: String, default: ""
11
11
 
12
12
  def call
13
13
  validate_env!
14
14
 
15
15
  CLI::UI::Frame.open(context.message("serve.frame_title")) do
16
- success = ShopifyCli::JsSystem.call(context, yarn: yarn_serve_command, npm: npm_serve_command)
16
+ success = call_js_system(yarn_command: yarn_serve_command, npm_command: npm_serve_command)
17
17
  context.abort(context.message("serve.serve_failure_message")) unless success
18
18
  end
19
19
  end
20
20
 
21
21
  private
22
22
 
23
+ def call_js_system(yarn_command:, npm_command:)
24
+ ShopifyCli::JsSystem.call(context, yarn: yarn_command, npm: npm_command)
25
+ end
26
+
23
27
  def specification
24
28
  specification_handler.specification
25
29
  end
26
30
 
27
- def validate_env!
28
- ExtensionProject.reload
31
+ def renderer_package
32
+ specification_handler.renderer_package(context)
33
+ end
34
+
35
+ def required_fields
36
+ specification.features.argo.required_fields
37
+ end
29
38
 
30
- ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
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
31
49
 
32
- required_fields = specification.features.argo.required_fields
50
+ def yarn_serve_command
51
+ serve_options.yarn_serve_command
52
+ end
53
+
54
+ def npm_serve_command
55
+ serve_options.npm_serve_command
56
+ end
57
+
58
+ def validate_env!
59
+ ExtensionProject.reload
33
60
 
34
61
  return if required_fields.none?
35
62
 
@@ -45,25 +72,6 @@ module Extension
45
72
 
46
73
  context.abort(context.message("serve.serve_missing_information"))
47
74
  end
48
-
49
- def yarn_serve_command
50
- YARN_SERVE_COMMAND + serve_options(specification.features.argo.required_fields)
51
- end
52
-
53
- def npm_serve_command
54
- NPM_SERVE_COMMAND + ["--"] + serve_options(specification.features.argo.required_fields)
55
- end
56
-
57
- def serve_options(required_fields)
58
- renderer_package = specification_handler.renderer_package(context)
59
- project = ExtensionProject.current
60
- @serve_options ||= [].tap do |options|
61
- options << "--shop=#{project.env.shop}" if required_fields.include?(:shop)
62
- options << "--apiKey=#{project.env.api_key}" if required_fields.include?(:api_key)
63
- options << "--argoVersion=#{renderer_package.version}" if renderer_package.admin?
64
- options << "--uuid=#{project.registration_uuid}" if renderer_package.supports_uuid_flag?
65
- end
66
- end
67
75
  end
68
76
  end
69
77
  end