shopify-cli 1.7.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +28 -0
  3. data/.rubocop_todo.yml +15 -2
  4. data/CHANGELOG.md +21 -0
  5. data/Gemfile.lock +14 -14
  6. data/README.md +2 -1
  7. data/dev.yml +3 -0
  8. data/lib/docgen/markdown.rb +1 -1
  9. data/lib/graphql/extension_create.graphql +17 -2
  10. data/lib/graphql/fetch_specifications.graphql +14 -0
  11. data/lib/project_types/extension/cli.rb +4 -10
  12. data/lib/project_types/extension/commands/create.rb +2 -2
  13. data/lib/project_types/extension/commands/extension_command.rb +10 -6
  14. data/lib/project_types/extension/commands/push.rb +2 -2
  15. data/lib/project_types/extension/commands/register.rb +6 -5
  16. data/lib/project_types/extension/commands/serve.rb +1 -7
  17. data/lib/project_types/extension/extension_project.rb +19 -4
  18. data/lib/project_types/extension/extension_project_keys.rb +2 -1
  19. data/lib/project_types/extension/features/argo.rb +18 -34
  20. data/lib/project_types/extension/features/argo_renderer_package.rb +47 -0
  21. data/lib/project_types/extension/features/argo_serve.rb +69 -0
  22. data/lib/project_types/extension/features/argo_setup.rb +1 -1
  23. data/lib/project_types/extension/forms/questions/ask_type.rb +16 -5
  24. data/lib/project_types/extension/messages/message_loading.rb +3 -1
  25. data/lib/project_types/extension/messages/messages.rb +6 -6
  26. data/lib/project_types/extension/models/registration.rb +1 -0
  27. data/lib/project_types/extension/models/specification.rb +6 -2
  28. data/lib/project_types/extension/models/specification_handlers/default.rb +9 -1
  29. data/lib/project_types/extension/models/specifications.rb +12 -1
  30. data/lib/project_types/extension/models/version.rb +1 -1
  31. data/lib/project_types/extension/tasks/configure_features.rb +3 -1
  32. data/lib/project_types/extension/tasks/converters/registration_converter.rb +2 -0
  33. data/lib/project_types/extension/tasks/fetch_specifications.rb +8 -28
  34. data/lib/project_types/node/commands/generate.rb +0 -22
  35. data/lib/project_types/node/forms/create.rb +10 -1
  36. data/lib/project_types/node/messages/messages.rb +5 -4
  37. data/lib/project_types/rails/forms/create.rb +11 -1
  38. data/lib/project_types/rails/messages/messages.rb +5 -4
  39. data/lib/project_types/script/cli.rb +7 -7
  40. data/lib/project_types/script/commands/create.rb +2 -7
  41. data/lib/project_types/script/commands/push.rb +3 -3
  42. data/lib/project_types/script/config/extension_points.yml +27 -10
  43. data/lib/project_types/script/errors.rb +0 -35
  44. data/lib/project_types/script/forms/create.rb +3 -14
  45. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +5 -5
  46. data/lib/project_types/script/graphql/get_app_scripts.graphql +6 -0
  47. data/lib/project_types/script/graphql/script_service_proxy.graphql +1 -2
  48. data/lib/project_types/script/layers/application/create_script.rb +32 -22
  49. data/lib/project_types/script/layers/application/extension_points.rb +3 -2
  50. data/lib/project_types/script/layers/application/push_script.rb +6 -3
  51. data/lib/project_types/script/layers/domain/config_ui.rb +16 -0
  52. data/lib/project_types/script/layers/domain/errors.rb +16 -0
  53. data/lib/project_types/script/layers/domain/extension_point.rb +60 -45
  54. data/lib/project_types/script/layers/domain/metadata.rb +18 -25
  55. data/lib/project_types/script/layers/domain/push_package.rb +4 -4
  56. data/lib/project_types/script/layers/domain/script_project.rb +54 -0
  57. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +37 -8
  58. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +5 -40
  59. data/lib/project_types/script/layers/infrastructure/errors.rb +50 -19
  60. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +8 -9
  61. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +1 -1
  62. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +198 -0
  63. data/lib/project_types/script/layers/infrastructure/script_service.rb +27 -66
  64. data/lib/project_types/script/messages/messages.rb +28 -51
  65. data/lib/project_types/script/tasks/ensure_env.rb +77 -0
  66. data/lib/project_types/script/ui/error_handler.rb +63 -47
  67. data/lib/shopify-cli/context.rb +28 -0
  68. data/lib/shopify-cli/js_system.rb +2 -2
  69. data/lib/shopify-cli/messages/messages.rb +3 -2
  70. data/lib/shopify-cli/method_object.rb +1 -1
  71. data/lib/shopify-cli/oauth.rb +2 -2
  72. data/lib/shopify-cli/packager.rb +1 -1
  73. data/lib/shopify-cli/resolve_constant.rb +1 -1
  74. data/lib/shopify-cli/resources/env_file.rb +1 -1
  75. data/lib/shopify-cli/result.rb +3 -3
  76. data/lib/shopify-cli/tasks/ensure_dev_store.rb +1 -1
  77. data/lib/shopify-cli/transform_data_structure.rb +2 -2
  78. data/lib/shopify-cli/version.rb +1 -1
  79. data/lib/shopify_cli.rb +0 -1
  80. data/vendor/deps/smart_properties/REVISION +1 -1
  81. data/vendor/deps/smart_properties/lib/smart_properties/property.rb +7 -1
  82. data/vendor/deps/smart_properties/lib/smart_properties/version.rb +1 -1
  83. metadata +11 -10
  84. data/.travis.yml +0 -14
  85. data/lib/project_types/script/commands/disable.rb +0 -25
  86. data/lib/project_types/script/commands/enable.rb +0 -80
  87. data/lib/project_types/script/graphql/shop_script_delete.graphql +0 -14
  88. data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +0 -28
  89. data/lib/project_types/script/layers/application/disable_script.rb +0 -21
  90. data/lib/project_types/script/layers/application/enable_script.rb +0 -23
  91. data/lib/project_types/script/script_project.rb +0 -85
@@ -1,7 +1,6 @@
1
- query ProxyRequest($api_key: String, $shop_domain: String, $query: String!, $variables: String) {
1
+ query ProxyRequest($api_key: String, $query: String!, $variables: String) {
2
2
  scriptServiceProxy(
3
3
  apiKey: $api_key
4
- shopDomain: $shop_domain
5
4
  query: $query
6
5
  variables: $variables
7
6
  )
@@ -7,32 +7,27 @@ module Script
7
7
  module Application
8
8
  class CreateScript
9
9
  class << self
10
- def call(ctx:, language:, script_name:, extension_point_type:, description:)
11
- extension_point = ExtensionPoints.get(type: extension_point_type)
12
- project = setup_project(ctx, language, script_name, extension_point, description)
13
- project_creator = Infrastructure::ProjectCreator
14
- .for(ctx, language, extension_point, script_name, project.directory)
15
- install_dependencies(ctx, language, script_name, project_creator)
16
- bootstrap(ctx, project_creator)
17
- project
10
+ def call(ctx:, language:, script_name:, extension_point_type:, no_config_ui:)
11
+ raise Infrastructure::Errors::ScriptProjectAlreadyExistsError, script_name if ctx.dir_exist?(script_name)
12
+
13
+ in_new_directory_context(ctx, script_name) do
14
+ extension_point = ExtensionPoints.get(type: extension_point_type)
15
+ project = Infrastructure::ScriptProjectRepository.new(ctx: ctx).create(
16
+ script_name: script_name,
17
+ extension_point_type: extension_point_type,
18
+ language: language,
19
+ no_config_ui: no_config_ui
20
+ )
21
+ project_creator = Infrastructure::ProjectCreator
22
+ .for(ctx, language, extension_point, script_name, project.id)
23
+ install_dependencies(ctx, language, script_name, project_creator)
24
+ bootstrap(ctx, project_creator)
25
+ project
26
+ end
18
27
  end
19
28
 
20
29
  private
21
30
 
22
- def setup_project(ctx, language, script_name, extension_point, description)
23
- ScriptProject.create(ctx, script_name)
24
- ScriptProject.write(
25
- ctx,
26
- project_type: :script,
27
- organization_id: nil, # TODO: can you provide this at creation
28
- extension_point_type: extension_point.type,
29
- script_name: script_name,
30
- language: language,
31
- description: description
32
- )
33
- ScriptProject.current
34
- end
35
-
36
31
  def install_dependencies(ctx, language, script_name, project_creator)
37
32
  task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name)
38
33
  project_creator.setup_dependencies
@@ -45,6 +40,21 @@ module Script
45
40
  spinner.update_title(ctx.message("script.create.created"))
46
41
  end
47
42
  end
43
+
44
+ def in_new_directory_context(ctx, directory)
45
+ initial_directory = ctx.root
46
+ begin
47
+ ctx.mkdir_p(directory)
48
+ ctx.chdir(directory)
49
+ yield
50
+ rescue
51
+ ctx.chdir(initial_directory)
52
+ ctx.rm_r(directory)
53
+ raise
54
+ ensure
55
+ ctx.chdir(initial_directory)
56
+ end
57
+ end
48
58
  end
49
59
  end
50
60
  end
@@ -12,9 +12,10 @@ module Script
12
12
  Infrastructure::ExtensionPointRepository.new.extension_point_types
13
13
  end
14
14
 
15
- def self.non_deprecated_types
15
+ def self.available_types
16
16
  Infrastructure::ExtensionPointRepository.new.extension_points.select do |ep|
17
- !ep.deprecated?
17
+ next false if ep.deprecated?
18
+ !ep.beta? || ShopifyCli::Feature.enabled?(:scripts_beta_extension_points)
18
19
  end.map(&:type)
19
20
  end
20
21
 
@@ -6,8 +6,10 @@ module Script
6
6
  class PushScript
7
7
  class << self
8
8
  def call(ctx:, force:)
9
- script_project = ScriptProject.current
9
+ script_project_repo = Infrastructure::ScriptProjectRepository.new(ctx: ctx)
10
+ script_project = script_project_repo.get
10
11
  task_runner = Infrastructure::TaskRunner.for(ctx, script_project.language, script_project.script_name)
12
+
11
13
  ProjectDependencies.install(ctx: ctx, task_runner: task_runner)
12
14
  BuildScript.call(ctx: ctx, task_runner: task_runner, script_project: script_project)
13
15
 
@@ -15,9 +17,10 @@ module Script
15
17
  package = Infrastructure::PushPackageRepository.new(ctx: p_ctx).get_push_package(
16
18
  script_project: script_project,
17
19
  compiled_type: task_runner.compiled_type,
18
- metadata: task_runner.metadata
20
+ metadata: task_runner.metadata,
19
21
  )
20
- package.push(Infrastructure::ScriptService.new(ctx: p_ctx), script_project.api_key, force)
22
+ uuid = package.push(Infrastructure::ScriptService.new(ctx: p_ctx), script_project.api_key, force)
23
+ script_project_repo.update_env(uuid: uuid)
21
24
  spinner.update_title(p_ctx.message("script.application.pushed"))
22
25
  end
23
26
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Domain
6
+ class ConfigUi
7
+ attr_reader :filename, :content
8
+
9
+ def initialize(filename:, content:)
10
+ @filename = filename
11
+ @content = content
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -14,6 +14,22 @@ module Script
14
14
  end
15
15
  end
16
16
 
17
+ class InvalidConfigUiDefinitionError < ScriptProjectError
18
+ attr_reader :filename
19
+ def initialize(filename)
20
+ super()
21
+ @filename = filename
22
+ end
23
+ end
24
+
25
+ class MissingSpecifiedConfigUiDefinitionError < ScriptProjectError
26
+ attr_reader :filename
27
+ def initialize(filename)
28
+ super()
29
+ @filename = filename
30
+ end
31
+ end
32
+
17
33
  class ScriptNotFoundError < ScriptProjectError
18
34
  attr_reader :script_name, :extension_point_type
19
35
  def initialize(extension_point_type, script_name)
@@ -4,79 +4,94 @@ module Script
4
4
  module Layers
5
5
  module Domain
6
6
  class ExtensionPoint
7
- attr_reader :type, :deprecated, :sdks
7
+ attr_reader :type, :beta, :deprecated, :sdks, :domain
8
8
 
9
9
  def initialize(type, config)
10
10
  @type = type
11
+ @beta = config["beta"] || false
11
12
  @deprecated = config["deprecated"] || false
13
+ @domain = config["domain"] || nil
12
14
  @sdks = ExtensionPointSDKs.new(config)
13
15
  end
14
16
 
17
+ def beta?
18
+ @beta
19
+ end
20
+
15
21
  def deprecated?
16
22
  @deprecated
17
23
  end
18
- end
19
24
 
20
- class ExtensionPointSDKs
21
- def initialize(config)
22
- @config = config
25
+ def dasherize_type
26
+ @type.gsub("_", "-")
23
27
  end
24
28
 
25
- def all
26
- [assemblyscript, rust].compact
27
- end
29
+ class ExtensionPointSDKs
30
+ def initialize(config)
31
+ @config = config
32
+ end
28
33
 
29
- def assemblyscript
30
- @assemblyscript ||= new_sdk(ExtensionPointAssemblyScriptSDK)
31
- end
34
+ def all
35
+ [assemblyscript, rust].compact
36
+ end
32
37
 
33
- def rust
34
- @rust ||= new_sdk(ExtensionPointRustSDK)
35
- end
38
+ def assemblyscript
39
+ @assemblyscript ||= new_sdk(ExtensionPointAssemblyScriptSDK)
40
+ end
41
+
42
+ def rust
43
+ @rust ||= new_sdk(ExtensionPointRustSDK)
44
+ end
36
45
 
37
- private
46
+ private
38
47
 
39
- def new_sdk(klass)
40
- config = @config[klass.language]
41
- return nil if config.nil?
42
- klass.new(config)
48
+ def new_sdk(klass)
49
+ config = @config[klass.language]
50
+ return nil if config.nil?
51
+ klass.new(config)
52
+ end
43
53
  end
44
- end
45
54
 
46
- class ExtensionPointSDK
47
- attr_reader :beta, :package
55
+ class ExtensionPointSDK
56
+ attr_reader :version, :beta, :package
48
57
 
49
- def initialize(config)
50
- @beta = config["beta"] || false
51
- @package = config["package"]
52
- end
58
+ def initialize(config)
59
+ @beta = config["beta"] || false
60
+ @package = config["package"]
61
+ @version = config["package-version"]
62
+ end
53
63
 
54
- def beta?
55
- @beta
56
- end
64
+ def beta?
65
+ @beta
66
+ end
67
+
68
+ def versioned?
69
+ @version
70
+ end
57
71
 
58
- def self.language
59
- raise NotImplementedError
72
+ def self.language
73
+ raise NotImplementedError
74
+ end
60
75
  end
61
- end
62
76
 
63
- class ExtensionPointAssemblyScriptSDK < ExtensionPointSDK
64
- attr_reader :sdk_version, :toolchain_version
77
+ class ExtensionPointAssemblyScriptSDK < ExtensionPointSDK
78
+ attr_reader :sdk_version, :toolchain_version
65
79
 
66
- def initialize(config)
67
- super
68
- @sdk_version = config["sdk-version"]
69
- @toolchain_version = config["toolchain-version"]
70
- end
80
+ def initialize(config)
81
+ super
82
+ @sdk_version = config["sdk-version"]
83
+ @toolchain_version = config["toolchain-version"]
84
+ end
71
85
 
72
- def self.language
73
- "assemblyscript"
86
+ def self.language
87
+ "assemblyscript"
88
+ end
74
89
  end
75
- end
76
90
 
77
- class ExtensionPointRustSDK < ExtensionPointSDK
78
- def self.language
79
- "rust"
91
+ class ExtensionPointRustSDK < ExtensionPointSDK
92
+ def self.language
93
+ "rust"
94
+ end
80
95
  end
81
96
  end
82
97
  end
@@ -14,39 +14,32 @@ module Script
14
14
 
15
15
  class << self
16
16
  def create_from_json(ctx, metadata_json)
17
+ err_tag = nil
17
18
  metadata_hash = JSON.parse(metadata_json)
18
- schema_versions = metadata_hash["schemaVersions"]
19
- if schema_versions.nil?
20
- err_msg = "script.error.metadata_schema_versions_missing"
21
- raise ::Script::Layers::Domain::Errors::MetadataValidationError, ctx.message(err_msg)
22
- end
23
- # Scripts may be attached to more than one EP in the future but not right now
24
- unless schema_versions.count == 1
25
- err_msg = "script.error.metadata_schema_versions_single_key"
26
- raise ::Script::Layers::Domain::Errors::MetadataValidationError, ctx.message(err_msg)
27
- end
28
19
 
29
- _, version = schema_versions.first
20
+ use_msgpack = !!metadata_hash.dig("flags", "use_msgpack")
21
+ schema_versions = metadata_hash["schemaVersions"] || {}
22
+
23
+ version = schema_versions.values.first || {}
30
24
  schema_major_version = version["major"]
31
25
  schema_minor_version = version["minor"]
32
- if schema_major_version.nil?
33
- err_msg = "script.error.metadata_schema_versions_missing_major"
34
- raise ::Script::Layers::Domain::Errors::MetadataValidationError, ctx.message(err_msg)
35
- end
36
26
 
37
- if schema_minor_version.nil?
38
- err_msg = "script.error.metadata_schema_versions_missing_minor"
39
- raise ::Script::Layers::Domain::Errors::MetadataValidationError, ctx.message(err_msg)
27
+ if schema_versions.empty?
28
+ err_tag = "script.error.metadata_schema_versions_missing"
29
+ elsif schema_versions.count != 1
30
+ # Scripts may be attached to more than one EP in the future but not right now
31
+ err_tag = "script.error.metadata_schema_versions_single_key"
32
+ elsif schema_major_version.nil?
33
+ err_tag = "script.error.metadata_schema_versions_missing_major"
34
+ elsif schema_minor_version.nil?
35
+ err_tag = "script.error.metadata_schema_versions_missing_minor"
40
36
  end
41
37
 
42
- use_msgpack = !!metadata_hash.dig("flags", "use_msgpack")
43
-
44
38
  Metadata.new(schema_major_version, schema_minor_version, use_msgpack)
45
- rescue ::Script::Layers::Domain::Errors::MetadataValidationError
46
- raise
47
- rescue
48
- err_msg = "script.error.metadata_validation_cause"
49
- raise ::Script::Layers::Domain::Errors::MetadataValidationError, ctx.message(err_msg)
39
+ rescue JSON::ParserError
40
+ err_tag = "script.error.metadata_validation_cause"
41
+ ensure
42
+ raise Errors::MetadataValidationError, ctx.message(err_tag) if err_tag
50
43
  end
51
44
  end
52
45
  end
@@ -5,9 +5,9 @@ module Script
5
5
  module Domain
6
6
  class PushPackage
7
7
  attr_reader :id,
8
+ :uuid,
8
9
  :extension_point_type,
9
10
  :script_name,
10
- :description,
11
11
  :config_ui,
12
12
  :script_content,
13
13
  :compiled_type,
@@ -15,18 +15,18 @@ module Script
15
15
 
16
16
  def initialize(
17
17
  id:,
18
+ uuid:,
18
19
  extension_point_type:,
19
20
  script_name:,
20
- description:,
21
21
  script_content:,
22
22
  compiled_type:,
23
23
  metadata:,
24
24
  config_ui:
25
25
  )
26
26
  @id = id
27
+ @uuid = uuid
27
28
  @extension_point_type = extension_point_type
28
29
  @script_name = script_name
29
- @description = description
30
30
  @script_content = script_content
31
31
  @compiled_type = compiled_type
32
32
  @metadata = metadata
@@ -35,9 +35,9 @@ module Script
35
35
 
36
36
  def push(script_service, api_key, force)
37
37
  script_service.push(
38
+ uuid: @uuid,
38
39
  extension_point_type: @extension_point_type,
39
40
  script_name: @script_name,
40
- description: @description,
41
41
  script_content: @script_content,
42
42
  compiled_type: @compiled_type,
43
43
  api_key: api_key,
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Domain
6
+ class ScriptProject
7
+ include SmartProperties
8
+
9
+ UUID_ENV_KEY = "UUID"
10
+
11
+ property! :id, accepts: String
12
+ property :env, accepts: ShopifyCli::Resources::EnvFile
13
+
14
+ property! :extension_point_type, accepts: String
15
+ property! :script_name, accepts: String
16
+ property! :language, accepts: String
17
+
18
+ property :config_ui, accepts: ConfigUi
19
+
20
+ def initialize(*)
21
+ super
22
+
23
+ ShopifyCli::Core::Monorail.metadata = {
24
+ "script_name" => script_name,
25
+ "extension_point_type" => extension_point_type,
26
+ "language" => language,
27
+ }
28
+ end
29
+
30
+ def api_key
31
+ env&.api_key
32
+ end
33
+
34
+ def api_secret
35
+ env&.secret
36
+ end
37
+
38
+ def uuid
39
+ uuid_defined? && !raw_uuid.empty? ? raw_uuid : nil
40
+ end
41
+
42
+ def uuid_defined?
43
+ !raw_uuid.nil?
44
+ end
45
+
46
+ private
47
+
48
+ def raw_uuid
49
+ env&.extra&.[](UUID_ENV_KEY)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end