shopify-cli 1.7.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) 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/.rubocop_todo.yml +15 -2
  5. data/CHANGELOG.md +25 -0
  6. data/Gemfile.lock +15 -15
  7. data/README.md +2 -1
  8. data/dev.yml +3 -0
  9. data/lib/docgen/markdown.rb +1 -1
  10. data/lib/graphql/extension_create.graphql +17 -2
  11. data/lib/graphql/fetch_specifications.graphql +14 -0
  12. data/lib/project_types/extension/cli.rb +8 -10
  13. data/lib/project_types/extension/commands/create.rb +2 -2
  14. data/lib/project_types/extension/commands/extension_command.rb +10 -6
  15. data/lib/project_types/extension/commands/push.rb +2 -2
  16. data/lib/project_types/extension/commands/register.rb +6 -5
  17. data/lib/project_types/extension/commands/serve.rb +64 -22
  18. data/lib/project_types/extension/commands/tunnel.rb +3 -1
  19. data/lib/project_types/extension/extension_project.rb +20 -4
  20. data/lib/project_types/extension/extension_project_keys.rb +2 -1
  21. data/lib/project_types/extension/features/argo.rb +19 -44
  22. data/lib/project_types/extension/features/argo_runtime.rb +63 -0
  23. data/lib/project_types/extension/features/argo_serve.rb +79 -0
  24. data/lib/project_types/extension/features/argo_serve_options.rb +40 -0
  25. data/lib/project_types/extension/features/argo_setup.rb +1 -1
  26. data/lib/project_types/extension/forms/questions/ask_type.rb +16 -5
  27. data/lib/project_types/extension/messages/message_loading.rb +3 -1
  28. data/lib/project_types/extension/messages/messages.rb +9 -6
  29. data/lib/project_types/extension/models/npm_package.rb +14 -0
  30. data/lib/project_types/extension/models/registration.rb +1 -0
  31. data/lib/project_types/extension/models/specification.rb +7 -2
  32. data/lib/project_types/extension/models/specification_handlers/checkout_argo_extension.rb +18 -0
  33. data/lib/project_types/extension/models/specification_handlers/default.rb +35 -2
  34. data/lib/project_types/extension/models/specifications.rb +12 -1
  35. data/lib/project_types/extension/models/version.rb +1 -1
  36. data/lib/project_types/extension/tasks/choose_next_available_port.rb +36 -0
  37. data/lib/project_types/extension/tasks/configure_features.rb +5 -1
  38. data/lib/project_types/extension/tasks/converters/registration_converter.rb +2 -0
  39. data/lib/project_types/extension/tasks/fetch_specifications.rb +8 -28
  40. data/lib/project_types/extension/tasks/find_npm_packages.rb +106 -0
  41. data/lib/project_types/node/commands/generate.rb +0 -22
  42. data/lib/project_types/node/forms/create.rb +10 -1
  43. data/lib/project_types/node/messages/messages.rb +5 -4
  44. data/lib/project_types/rails/forms/create.rb +11 -1
  45. data/lib/project_types/rails/messages/messages.rb +5 -4
  46. data/lib/project_types/script/cli.rb +7 -8
  47. data/lib/project_types/script/commands/create.rb +0 -7
  48. data/lib/project_types/script/commands/push.rb +3 -3
  49. data/lib/project_types/script/config/extension_points.yml +17 -0
  50. data/lib/project_types/script/errors.rb +0 -19
  51. data/lib/project_types/script/forms/create.rb +3 -14
  52. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +5 -5
  53. data/lib/project_types/script/graphql/get_app_scripts.graphql +6 -0
  54. data/lib/project_types/script/graphql/script_service_proxy.graphql +1 -2
  55. data/lib/project_types/script/layers/application/build_script.rb +1 -2
  56. data/lib/project_types/script/layers/application/create_script.rb +32 -49
  57. data/lib/project_types/script/layers/application/extension_points.rb +3 -2
  58. data/lib/project_types/script/layers/application/push_script.rb +5 -5
  59. data/lib/project_types/script/layers/domain/errors.rb +0 -2
  60. data/lib/project_types/script/layers/domain/extension_point.rb +60 -45
  61. data/lib/project_types/script/layers/domain/metadata.rb +18 -25
  62. data/lib/project_types/script/layers/domain/push_package.rb +4 -4
  63. data/lib/project_types/script/layers/domain/script_project.rb +54 -0
  64. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +39 -14
  65. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +14 -43
  66. data/lib/project_types/script/layers/infrastructure/command_runner.rb +19 -0
  67. data/lib/project_types/script/layers/infrastructure/errors.rb +40 -20
  68. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +12 -13
  69. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +9 -10
  70. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +6 -7
  71. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +172 -0
  72. data/lib/project_types/script/layers/infrastructure/script_service.rb +25 -76
  73. data/lib/project_types/script/messages/messages.rb +20 -53
  74. data/lib/project_types/script/tasks/ensure_env.rb +85 -0
  75. data/lib/project_types/script/ui/error_handler.rb +32 -41
  76. data/lib/shopify-cli/context.rb +28 -0
  77. data/lib/shopify-cli/js_system.rb +2 -2
  78. data/lib/shopify-cli/messages/messages.rb +50 -45
  79. data/lib/shopify-cli/method_object.rb +4 -4
  80. data/lib/shopify-cli/oauth.rb +9 -3
  81. data/lib/shopify-cli/packager.rb +1 -1
  82. data/lib/shopify-cli/partners_api/organizations.rb +3 -3
  83. data/lib/shopify-cli/resolve_constant.rb +1 -1
  84. data/lib/shopify-cli/resources/env_file.rb +1 -1
  85. data/lib/shopify-cli/tasks/ensure_dev_store.rb +1 -1
  86. data/lib/shopify-cli/tasks/select_org_and_shop.rb +6 -4
  87. data/lib/shopify-cli/transform_data_structure.rb +2 -2
  88. data/lib/shopify-cli/tunnel.rb +22 -1
  89. data/lib/shopify-cli/version.rb +1 -1
  90. data/lib/shopify_cli.rb +0 -1
  91. data/vendor/deps/smart_properties/REVISION +1 -1
  92. data/vendor/deps/smart_properties/lib/smart_properties/property.rb +7 -1
  93. data/vendor/deps/smart_properties/lib/smart_properties/version.rb +1 -1
  94. metadata +17 -12
  95. data/.travis.yml +0 -14
  96. data/lib/project_types/script/commands/disable.rb +0 -25
  97. data/lib/project_types/script/commands/enable.rb +0 -80
  98. data/lib/project_types/script/graphql/shop_script_delete.graphql +0 -14
  99. data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +0 -28
  100. data/lib/project_types/script/layers/application/disable_script.rb +0 -21
  101. data/lib/project_types/script/layers/application/enable_script.rb +0 -23
  102. data/lib/project_types/script/layers/infrastructure/config_ui_repository.rb +0 -46
  103. data/lib/project_types/script/script_project.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 810ed674eed1f0938f1e4fdb55703fe8bcbcf10d13293a27f7e59f28cc39d384
4
- data.tar.gz: 0f7572e8d715e589bbe3cc23d6835e6256063a54b99504f3f6975b5008a0ed24
3
+ metadata.gz: e1ca8221a25313b8cd908a02e4c5c68dc9f74ed38e7472804346419e45d8d9d8
4
+ data.tar.gz: b0658aae7cb7ca368b78aa80f3fab364867bc1d6ae36515c07f3692bb87730cb
5
5
  SHA512:
6
- metadata.gz: 7681161d8502e8e728bac04b339b06d84334b1ec0edfc8a58c3f8eb5d4a85ba873c79810c63d30e784508cb9b155c3f39d672e88689b53fc0dd5cff32be865ff
7
- data.tar.gz: ac283b1b16d617b27c2f61dc948e77adead2910f218c0649783884ee6debc6c4135c18dccf35bf73931ded907dadab0ba9c70598238874d941107fa471970041
6
+ metadata.gz: 54fde8fed1098f483c817cfb0dd8d9ab291556da026dabcc7d0e0dc934fb9c2e97dd2865d72257ca75a2c5d1560759e4ece27c8acc76a8a56f299e8f004594f0
7
+ data.tar.gz: b193f5f389c2a03875e98d4636aa3cd16c7bfe212d798defed234233b0aad410382e3f56d83b58f63189b6f8256be762518c4439bfe732961c682db8fd81cb25
@@ -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 incrmenting 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
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,24 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-12-01 16:33:09 UTC using RuboCop version 1.4.1.
3
+ # on 2021-04-08 18:25:36 UTC using RuboCop version 1.12.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 30
9
+ # Offense count: 35
10
10
  Minitest/MultipleAssertions:
11
11
  Max: 9
12
+
13
+ # Offense count: 1
14
+ # Cop supports --auto-correct.
15
+ Style/PerlBackrefs:
16
+ Exclude:
17
+ - 'lib/docgen/markdown.rb'
18
+
19
+ # Offense count: 2
20
+ # Cop supports --auto-correct.
21
+ Style/RedundantBegin:
22
+ Exclude:
23
+ - 'lib/shopify-cli/shopifolk.rb'
24
+ - 'test/shopify-cli/tunnel_test.rb'
data/CHANGELOG.md CHANGED
@@ -1,12 +1,37 @@
1
1
  Unreleased
2
2
  ------
3
3
 
4
+ Version 1.11.0
5
+ --------------
6
+ * [#1221](https://github.com/Shopify/shopify-app-cli/pull/1221): Prioritizes returning an HTTPS URL over HTTP from `shopify tunnel status`.
7
+ * [#1223](https://github.com/Shopify/shopify-app-cli/pull/1233): Running `shopify serve` in an extension project now automatically runs `shopify tunnel`.
8
+ * [#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
9
+ * [#1229](https://github.com/Shopify/shopify-app-cli/pull/1229): Allows Checkout Extensions to specify configuration attributes in their extension.config.yml file.
10
+ * [#1238](https://github.com/Shopify/shopify-app-cli/pull/1238): Auto Tunnel Support for Checkout Extension
11
+
12
+ Version 1.10.0
13
+ --------------
14
+ * Updating internal features in development
15
+
16
+ Version 1.9.1
17
+ -------------
18
+ * [1201](https://github.com/Shopify/shopify-app-cli/pull/1201) Determine Argo Renderer Dynamically. This fixes `shopify serve` and `shopify push` for extensions.
19
+
20
+ Version 1.9.0
21
+ -------------
22
+ * [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))
23
+
24
+ Version 1.8.0
25
+ -------------
26
+ * [1119](https://github.com/Shopify/shopify-app-cli/pull/1119): Enable guest serialization for scripts
27
+
4
28
  Version 1.7.1
5
29
  ------
6
30
  * Updating internal features in development
7
31
 
8
32
  Version 1.7.0
9
33
  -----
34
+ * [#1109](https://github.com/Shopify/shopify-app-cli/pull/1109): Abort app generation if name contains disallowed text.
10
35
  * [#1075](https://github.com/Shopify/shopify-app-cli/pull/1075): Add support for kebab-case flags
11
36
 
12
37
  Version 1.6.0
data/Gemfile.lock CHANGED
@@ -4,7 +4,7 @@ GEM
4
4
  addressable (2.7.0)
5
5
  public_suffix (>= 2.0.2, < 5.0)
6
6
  ansi (1.5.0)
7
- ast (2.4.1)
7
+ ast (2.4.2)
8
8
  builder (3.2.4)
9
9
  byebug (11.1.3)
10
10
  coderay (1.1.3)
@@ -22,7 +22,7 @@ GEM
22
22
  ruby-progressbar
23
23
  mocha (1.11.2)
24
24
  parallel (1.20.1)
25
- parser (2.7.2.0)
25
+ parser (3.0.1.0)
26
26
  ast (~> 2.4.1)
27
27
  pry (0.13.1)
28
28
  coderay (~> 1.1)
@@ -33,26 +33,26 @@ GEM
33
33
  public_suffix (4.0.6)
34
34
  rainbow (3.0.0)
35
35
  rake (13.0.1)
36
- regexp_parser (1.8.2)
37
- rexml (3.2.4)
38
- rubocop (1.4.1)
36
+ regexp_parser (2.1.1)
37
+ rexml (3.2.5)
38
+ rubocop (1.12.1)
39
39
  parallel (~> 1.10)
40
- parser (>= 2.7.1.5)
40
+ parser (>= 3.0.0.0)
41
41
  rainbow (>= 2.2.2, < 4.0)
42
- regexp_parser (>= 1.8)
42
+ regexp_parser (>= 1.8, < 3.0)
43
43
  rexml
44
- rubocop-ast (>= 1.1.1)
44
+ rubocop-ast (>= 1.2.0, < 2.0)
45
45
  ruby-progressbar (~> 1.7)
46
- unicode-display_width (>= 1.4.0, < 2.0)
47
- rubocop-ast (1.1.1)
46
+ unicode-display_width (>= 1.4.0, < 3.0)
47
+ rubocop-ast (1.4.1)
48
48
  parser (>= 2.7.1.5)
49
49
  rubocop-minitest (0.10.1)
50
50
  rubocop (>= 0.87)
51
- rubocop-shopify (1.0.7)
52
- rubocop (~> 1.4)
53
- ruby-progressbar (1.10.1)
51
+ rubocop-shopify (2.0.1)
52
+ rubocop (~> 1.11)
53
+ ruby-progressbar (1.11.0)
54
54
  timecop (0.9.2)
55
- unicode-display_width (1.7.0)
55
+ unicode-display_width (2.0.0)
56
56
  webmock (3.9.3)
57
57
  addressable (>= 2.3.6)
58
58
  crack (>= 0.3.2)
@@ -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
 
data/dev.yml CHANGED
@@ -5,6 +5,9 @@ type:
5
5
  up:
6
6
  - ruby: 2.5.1
7
7
  - bundler
8
+ - node:
9
+ version: 14.9.0
10
+ yarn: true
8
11
 
9
12
  test:
10
13
  desc: 'Run tests.'
@@ -89,7 +89,7 @@ module RDoc
89
89
  lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment
90
90
  lines.each do |line|
91
91
  next unless line =~ /^ *(?=\S)/
92
- n = $&.length
92
+ n = Regexp.last_match(0).length
93
93
  indent = n if n < indent
94
94
  break if n == 0
95
95
  end
@@ -1,7 +1,22 @@
1
- mutation ExtensionCreate($api_key: String!, $type: ExtensionType!, $title: String!, $config: JSON!, $extension_context: String) {
2
- extensionCreate(input: {apiKey: $api_key, type: $type, title: $title, config: $config, context: $extension_context}) {
1
+ mutation ExtensionCreate(
2
+ $api_key: String!
3
+ $type: ExtensionType!
4
+ $title: String!
5
+ $config: JSON!
6
+ $extension_context: String
7
+ ) {
8
+ extensionCreate(
9
+ input: {
10
+ apiKey: $api_key
11
+ type: $type
12
+ title: $title
13
+ config: $config
14
+ context: $extension_context
15
+ }
16
+ ) {
3
17
  extensionRegistration {
4
18
  id
19
+ uuid
5
20
  type
6
21
  title
7
22
  draftVersion {
@@ -0,0 +1,14 @@
1
+ query fetchSpecifications($api_key: String!) {
2
+ extensionSpecifications(apiKey: $api_key) {
3
+ name
4
+ identifier
5
+ options {
6
+ managementExperience
7
+ }
8
+ features {
9
+ argo {
10
+ surface
11
+ }
12
+ }
13
+ }
14
+ }
@@ -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,11 +61,14 @@ module Extension
57
61
  end
58
62
 
59
63
  module Features
64
+ autoload :ArgoServe, Project.project_filepath("features/argo_serve")
65
+ autoload :ArgoServeOptions, Project.project_filepath("features/argo_serve_options")
60
66
  autoload :ArgoSetup, Project.project_filepath("features/argo_setup")
61
67
  autoload :ArgoSetupStep, Project.project_filepath("features/argo_setup_step")
62
68
  autoload :ArgoSetupSteps, Project.project_filepath("features/argo_setup_steps")
63
69
  autoload :ArgoDependencies, Project.project_filepath("features/argo_dependencies")
64
70
  autoload :ArgoConfig, Project.project_filepath("features/argo_config")
71
+ autoload :ArgoRuntime, Project.project_filepath("features/argo_runtime")
65
72
  autoload :Argo, Project.project_filepath("features/argo")
66
73
  end
67
74
 
@@ -77,18 +84,9 @@ module Extension
77
84
  autoload :Specification, Project.project_filepath("models/specification")
78
85
  autoload :Specifications, Project.project_filepath("models/specifications")
79
86
  autoload :LazySpecificationHandler, Project.project_filepath("models/lazy_specification_handler")
87
+ autoload :NpmPackage, Project.project_filepath("models/npm_package")
80
88
  end
81
89
 
82
90
  autoload :ExtensionProjectKeys, Project.project_filepath("extension_project_keys")
83
91
  autoload :ExtensionProject, Project.project_filepath("extension_project")
84
-
85
- def self.specifications
86
- @specifications ||= Models::Specifications.new(
87
- fetch_specifications: Tasks::FetchSpecifications
88
- )
89
- end
90
-
91
- def self.specifications=(specifications)
92
- @specifications = specifications
93
- end
94
92
  end
@@ -38,8 +38,8 @@ module Extension
38
38
  Usage: {{command:#{ShopifyCli::TOOL_NAME} create extension}}
39
39
  Options:
40
40
  {{command:--type=TYPE}} The type of extension you would like to create.
41
- {{command:--name=NAME}} The name of your extension (50 characters).”
42
- {{command:--api-key=KEY}} The API key of your app.”
41
+ {{command:--name=NAME}} The name of your extension (50 characters).
42
+ {{command:--api-key=KEY}} The API key of your app.
43
43
  HELP
44
44
  end
45
45
 
@@ -8,15 +8,19 @@ module Extension
8
8
  @project ||= ExtensionProject.current
9
9
  end
10
10
 
11
- def extension_type
12
- @extension_type ||= begin
13
- identifier = project.extension_type_identifier
11
+ def specification_handler
12
+ @specification_handler ||= begin
13
+ identifier = project.specification_identifier
14
14
  Models::LazySpecificationHandler.new(identifier) do
15
- unless Extension.specifications.valid?(identifier)
16
- @ctx.abort(@ctx.message("errors.unknown_type", project.extension_type_identifier))
15
+ specifications = Models::Specifications.new(
16
+ fetch_specifications: Tasks::FetchSpecifications.new(api_key: project.app.api_key, context: @ctx)
17
+ )
18
+
19
+ unless specifications.valid?(identifier)
20
+ @ctx.abort(@ctx.message("errors.unknown_type", project.specification_identifier))
17
21
  end
18
22
 
19
- Extension.specifications[identifier]
23
+ specifications[identifier]
20
24
  end
21
25
  end
22
26
  end
@@ -59,8 +59,8 @@ module Extension
59
59
  context: @ctx,
60
60
  api_key: project.app.api_key,
61
61
  registration_id: project.registration_id,
62
- config: extension_type.config(@ctx),
63
- extension_context: extension_type.extension_context(@ctx)
62
+ config: specification_handler.config(@ctx),
63
+ extension_context: specification_handler.extension_context(@ctx)
64
64
  )
65
65
  end
66
66
  end
@@ -12,7 +12,7 @@ module Extension
12
12
 
13
13
  update_project_files(registration)
14
14
 
15
- @ctx.puts(@ctx.message("register.success", project.title, app.title))
15
+ @ctx.puts(@ctx.message("register.success", project.title))
16
16
  @ctx.puts(@ctx.message("register.success_info"))
17
17
  end
18
18
  end
@@ -27,8 +27,8 @@ module Extension
27
27
  private
28
28
 
29
29
  def confirm_registration
30
- @ctx.puts(@ctx.message("register.confirm_info", extension_type.name))
31
- CLI::UI::Prompt.confirm(@ctx.message("register.confirm_question", app.title))
30
+ @ctx.puts(@ctx.message("register.confirm_info", specification_handler.name))
31
+ CLI::UI::Prompt.confirm(@ctx.message("register.confirm_question"))
32
32
  end
33
33
 
34
34
  def register_extension
@@ -37,10 +37,10 @@ module Extension
37
37
  Tasks::CreateExtension.call(
38
38
  context: @ctx,
39
39
  api_key: app.api_key,
40
- type: extension_type.graphql_identifier,
40
+ type: specification_handler.graphql_identifier,
41
41
  title: project.title,
42
42
  config: {},
43
- extension_context: extension_type.extension_context(@ctx)
43
+ extension_context: specification_handler.extension_context(@ctx)
44
44
  )
45
45
  end
46
46
 
@@ -50,6 +50,7 @@ module Extension
50
50
  api_key: app.api_key,
51
51
  api_secret: app.secret,
52
52
  registration_id: registration.id,
53
+ registration_uuid: registration.uuid,
53
54
  title: project.title
54
55
  )
55
56
  end
@@ -3,41 +3,83 @@
3
3
  module Extension
4
4
  module Commands
5
5
  class Serve < ExtensionCommand
6
- YARN_SERVE_COMMAND = %w(server)
7
- NPM_SERVE_COMMAND = %w(run-script server)
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
8
19
 
9
20
  def call(_args, _command_name)
10
- if argo_admin?
11
- ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
12
- ShopifyCli::Tasks::EnsureDevStore.call(@ctx)
13
- end
14
-
15
- CLI::UI::Frame.open(@ctx.message("serve.frame_title")) do
16
- yarn_serve_command = YARN_SERVE_COMMAND
17
- npm_serve_command = NPM_SERVE_COMMAND
18
- if argo_admin?
19
- serve_args = %W(--shop=#{project.env.shop} --apiKey=#{project.env.api_key})
20
- yarn_serve_command += serve_args
21
- npm_serve_command += %w(--) + serve_args
22
- end
23
- success = ShopifyCli::JsSystem.call(@ctx, yarn: yarn_serve_command, npm: npm_serve_command)
24
- @ctx.abort(@ctx.message("serve.serve_failure_message")) unless success
25
- end
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 }
26
31
  end
27
32
 
28
33
  def self.help
29
34
  <<~HELP
30
35
  Serve your extension in a local simulator for development.
31
36
  Usage: {{command:#{ShopifyCli::TOOL_NAME} serve}}
37
+ Options:
38
+ {{command:--tunnel=TUNNEL}} Establish an ngrok tunnel (default: false)
32
39
  HELP
33
40
  end
34
41
 
35
42
  private
36
43
 
37
- def argo_admin?
38
- ShopifyCli::Shopifolk.check &&
39
- ShopifyCli::Feature.enabled?(:argo_admin_beta) &&
40
- extension_type.specification.features&.argo&.surface_area == "admin"
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
41
83
  end
42
84
  end
43
85
  end