shopify-cli 1.3.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +2 -2
  3. data/.github/CONTRIBUTING.md +9 -1
  4. data/.github/PULL_REQUEST_TEMPLATE.md +10 -1
  5. data/.github/workflows/release.yml +61 -0
  6. data/.github/workflows/triage.yml +22 -0
  7. data/.gitignore +0 -1
  8. data/.rubocop.yml +61 -8
  9. data/.rubocop_todo.yml +11 -0
  10. data/.travis.yml +1 -0
  11. data/CHANGELOG.md +30 -0
  12. data/Gemfile +3 -2
  13. data/Gemfile.lock +39 -37
  14. data/README.md +39 -7
  15. data/RELEASING.md +19 -29
  16. data/Rakefile +2 -0
  17. data/dev.yml +2 -2
  18. data/docs/_config.yml +1 -18
  19. data/docs/app/node/commands/index.md +2 -80
  20. data/docs/app/node/index.md +2 -33
  21. data/docs/app/rails/commands/index.md +2 -78
  22. data/docs/app/rails/index.md +2 -34
  23. data/docs/core/index.md +2 -84
  24. data/docs/getting-started/index.md +2 -25
  25. data/docs/getting-started/install/index.md +1 -118
  26. data/docs/getting-started/migrate/index.md +2 -94
  27. data/docs/getting-started/uninstall/index.md +2 -35
  28. data/docs/getting-started/upgrade/index.md +2 -39
  29. data/docs/help/start-app/index.md +2 -4
  30. data/docs/index.md +2 -24
  31. data/install.sh +1 -1
  32. data/lib/project_types/extension/cli.rb +21 -11
  33. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  34. data/lib/project_types/extension/features/argo.rb +117 -0
  35. data/lib/project_types/extension/forms/create.rb +2 -2
  36. data/lib/project_types/extension/models/specification.rb +35 -0
  37. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
  38. data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
  39. data/lib/project_types/extension/models/specifications.rb +77 -0
  40. data/lib/project_types/extension/tasks/configure_features.rb +52 -0
  41. data/lib/project_types/extension/tasks/fetch_specifications.rb +38 -0
  42. data/lib/project_types/node/cli.rb +4 -1
  43. data/lib/project_types/node/commands/connect.rb +15 -0
  44. data/lib/project_types/node/commands/create.rb +10 -4
  45. data/lib/project_types/node/commands/generate.rb +2 -11
  46. data/lib/project_types/node/messages/messages.rb +16 -50
  47. data/lib/project_types/rails/cli.rb +4 -1
  48. data/lib/project_types/rails/commands/connect.rb +15 -0
  49. data/lib/project_types/rails/commands/create.rb +15 -12
  50. data/lib/project_types/rails/forms/create.rb +1 -1
  51. data/lib/project_types/rails/gem.rb +1 -1
  52. data/lib/project_types/rails/messages/messages.rb +8 -5
  53. data/lib/project_types/script/cli.rb +9 -5
  54. data/lib/project_types/script/commands/create.rb +6 -4
  55. data/lib/project_types/script/commands/enable.rb +12 -4
  56. data/lib/project_types/script/commands/push.rb +5 -13
  57. data/lib/project_types/script/config/extension_points.yml +17 -12
  58. data/lib/project_types/script/errors.rb +21 -0
  59. data/lib/project_types/script/forms/create.rb +26 -2
  60. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +10 -1
  61. data/lib/project_types/script/layers/application/build_script.rb +18 -17
  62. data/lib/project_types/script/layers/application/create_script.rb +12 -10
  63. data/lib/project_types/script/layers/application/extension_points.rb +24 -0
  64. data/lib/project_types/script/layers/application/push_script.rb +18 -16
  65. data/lib/project_types/script/layers/domain/errors.rb +7 -0
  66. data/lib/project_types/script/layers/domain/extension_point.rb +62 -7
  67. data/lib/project_types/script/layers/domain/metadata.rb +55 -0
  68. data/lib/project_types/script/layers/domain/push_package.rb +25 -6
  69. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +17 -52
  70. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +42 -11
  71. data/lib/project_types/script/layers/infrastructure/errors.rb +16 -0
  72. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +10 -4
  73. data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
  74. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +25 -13
  75. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
  76. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
  77. data/lib/project_types/script/layers/infrastructure/script_service.rb +9 -1
  78. data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
  79. data/lib/project_types/script/messages/messages.rb +55 -4
  80. data/lib/project_types/script/script_project.rb +25 -16
  81. data/lib/project_types/script/ui/error_handler.rb +59 -1
  82. data/lib/project_types/theme/cli.rb +40 -0
  83. data/lib/project_types/theme/commands/connect.rb +54 -0
  84. data/lib/project_types/theme/commands/create.rb +48 -0
  85. data/lib/project_types/theme/commands/deploy.rb +38 -0
  86. data/lib/project_types/theme/commands/generate.rb +20 -0
  87. data/lib/project_types/theme/commands/generate/env.rb +79 -0
  88. data/lib/project_types/theme/commands/push.rb +55 -0
  89. data/lib/project_types/theme/commands/serve.rb +31 -0
  90. data/lib/project_types/theme/forms/connect.rb +34 -0
  91. data/lib/project_types/theme/forms/create.rb +22 -0
  92. data/lib/project_types/theme/messages/messages.rb +147 -0
  93. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
  94. data/lib/project_types/theme/themekit.rb +113 -0
  95. data/lib/shopify-cli/admin_api.rb +42 -2
  96. data/lib/shopify-cli/api.rb +34 -33
  97. data/lib/shopify-cli/commands/config.rb +24 -0
  98. data/lib/shopify-cli/commands/connect.rb +32 -15
  99. data/lib/shopify-cli/commands/system.rb +10 -1
  100. data/lib/shopify-cli/context.rb +23 -2
  101. data/lib/shopify-cli/core/entry_point.rb +1 -1
  102. data/lib/shopify-cli/core/monorail.rb +6 -4
  103. data/lib/shopify-cli/feature.rb +0 -2
  104. data/lib/shopify-cli/http_request.rb +27 -0
  105. data/lib/shopify-cli/js_deps.rb +1 -1
  106. data/lib/shopify-cli/messages/messages.rb +31 -7
  107. data/lib/shopify-cli/method_object.rb +104 -0
  108. data/lib/shopify-cli/partners_api.rb +25 -3
  109. data/lib/shopify-cli/process_supervision.rb +1 -1
  110. data/lib/shopify-cli/project.rb +12 -8
  111. data/lib/shopify-cli/project_type.rb +18 -2
  112. data/lib/shopify-cli/resolve_constant.rb +25 -0
  113. data/lib/shopify-cli/result.rb +432 -0
  114. data/lib/shopify-cli/shopifolk.rb +87 -0
  115. data/lib/shopify-cli/task.rb +8 -0
  116. data/lib/shopify-cli/tasks/create_api_client.rb +13 -2
  117. data/lib/shopify-cli/tasks/ensure_env.rb +3 -0
  118. data/lib/shopify-cli/tasks/select_org_and_shop.rb +10 -5
  119. data/lib/shopify-cli/tunnel.rb +8 -2
  120. data/lib/shopify-cli/version.rb +1 -1
  121. data/lib/shopify_cli.rb +5 -1
  122. data/shopify.fish +1 -1
  123. data/shopify.sh +1 -1
  124. data/vendor/deps/cli-kit/REVISION +1 -1
  125. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
  126. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
  127. data/vendor/deps/cli-ui/REVISION +1 -1
  128. data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
  129. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
  130. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
  131. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
  132. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
  133. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
  134. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
  135. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
  136. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
  137. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
  138. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
  139. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
  140. data/vendor/deps/webrick/.gitignore +9 -0
  141. data/vendor/deps/webrick/Gemfile +3 -0
  142. data/vendor/deps/webrick/LICENSE.txt +22 -0
  143. data/vendor/deps/webrick/README.md +61 -0
  144. data/vendor/deps/webrick/Rakefile +10 -0
  145. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  146. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  147. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  148. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  149. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  150. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  151. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  152. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  153. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  154. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  155. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  156. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  157. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  158. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  159. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  160. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  161. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  162. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  163. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  164. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  165. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  166. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  167. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  168. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  169. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  170. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  171. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  172. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  173. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  174. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  175. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  176. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  177. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  178. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  179. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  180. data/vendor/deps/webrick/webrick.gemspec +74 -0
  181. metadata +77 -27
  182. data/docs/Gemfile +0 -5
  183. data/docs/Gemfile.lock +0 -258
  184. data/docs/_data/nav.yml +0 -35
  185. data/docs/_includes/footer.html +0 -15
  186. data/docs/_includes/head.html +0 -19
  187. data/docs/_includes/sidebar_nav.html +0 -22
  188. data/docs/_includes/toc.html +0 -112
  189. data/docs/_layouts/default.html +0 -79
  190. data/docs/css/docs.css +0 -157
  191. data/docs/images/header.png +0 -0
  192. data/docs/installing-ruby.md +0 -28
  193. data/lib/project_types/extension/features/argo/admin.rb +0 -20
  194. data/lib/project_types/extension/features/argo/base.rb +0 -129
  195. data/lib/project_types/extension/features/argo/checkout.rb +0 -20
  196. data/lib/project_types/extension/models/type.rb +0 -81
  197. data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
  198. data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
  199. data/lib/project_types/node/commands/generate/billing.rb +0 -39
  200. data/lib/project_types/node/commands/generate/page.rb +0 -59
  201. data/lib/project_types/node/commands/generate/webhook.rb +0 -37
  202. data/lib/project_types/script/layers/domain/script.rb +0 -18
  203. data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +0 -38
  204. data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -59
  205. data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
  206. data/lib/project_types/script/templates/ts/as-pect.d.ts +0 -1
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Domain
6
+ class Metadata
7
+ attr_reader :schema_major_version, :schema_minor_version, :use_msgpack
8
+
9
+ def initialize(schema_major_version, schema_minor_version, use_msgpack)
10
+ @schema_major_version = schema_major_version
11
+ @schema_minor_version = schema_minor_version
12
+ @use_msgpack = use_msgpack
13
+ end
14
+
15
+ class << self
16
+ def create_from_json(ctx, metadata_json)
17
+ 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
+
29
+ _, version = schema_versions.first
30
+ schema_major_version = version["major"]
31
+ 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
+
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)
40
+ end
41
+
42
+ use_msgpack = !!metadata_hash.dig("flags", "use_msgpack")
43
+
44
+ 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)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -4,23 +4,42 @@ module Script
4
4
  module Layers
5
5
  module Domain
6
6
  class PushPackage
7
- attr_reader :id, :script, :script_content, :compiled_type
7
+ attr_reader :id,
8
+ :extension_point_type,
9
+ :script_name,
10
+ :description,
11
+ :script_content,
12
+ :compiled_type,
13
+ :metadata
8
14
 
9
- def initialize(id, script, script_content, compiled_type)
15
+ def initialize(
16
+ id:,
17
+ extension_point_type:,
18
+ script_name:,
19
+ description:,
20
+ script_content:,
21
+ compiled_type:,
22
+ metadata:
23
+ )
10
24
  @id = id
11
- @script = script
25
+ @extension_point_type = extension_point_type
26
+ @script_name = script_name
27
+ @description = description
12
28
  @script_content = script_content
13
29
  @compiled_type = compiled_type
30
+ @metadata = metadata
14
31
  end
15
32
 
16
33
  def push(script_service, api_key, force)
17
34
  script_service.push(
18
- extension_point_type: @script.extension_point_type,
19
- script_name: @script.name,
35
+ extension_point_type: @extension_point_type,
36
+ script_name: @script_name,
37
+ description: @description,
20
38
  script_content: @script_content,
21
39
  compiled_type: @compiled_type,
22
40
  api_key: api_key,
23
- force: force
41
+ force: force,
42
+ metadata: @metadata,
24
43
  )
25
44
  end
26
45
  end
@@ -10,11 +10,8 @@ module Script
10
10
  property! :script_name, accepts: String
11
11
  property! :path_to_project, accepts: String
12
12
 
13
- BOOTSTRAP_SRC = "npx --no-install shopify-scripts-bootstrap src %{src_base}"
14
- BOOTSTRAP_TEST = "npx --no-install shopify-scripts-bootstrap test %{test_base}"
15
- SOURCE_DIR = "src"
16
- TEST_DIR = "test"
17
- LANGUAGE = "ts"
13
+ BOOTSTRAP = "npx --no-install shopify-scripts-toolchain-as bootstrap --from %{extension_point} --dest %{base}"
14
+ MIN_NODE_VERSION = "14.5.0"
18
15
 
19
16
  def setup_dependencies
20
17
  write_npmrc
@@ -22,42 +19,12 @@ module Script
22
19
  end
23
20
 
24
21
  def bootstrap
25
- create_src_folder
26
- create_test_folder
27
- end
28
-
29
- private
30
-
31
- def create_src_folder
32
- ctx.mkdir_p(src_base)
33
- out, status = ctx.capture2e(format(BOOTSTRAP_SRC, src_base: src_base))
22
+ type = extension_point.type.gsub('_', '-')
23
+ out, status = ctx.capture2e(format(BOOTSTRAP, extension_point: type, base: path_to_project))
34
24
  raise Domain::Errors::ServiceFailureError, out unless status.success?
35
-
36
- write_tsconfig_file(SOURCE_DIR, ".")
37
- end
38
-
39
- def create_test_folder
40
- ctx.mkdir_p(test_base)
41
- out, status = ctx.capture2e(format(BOOTSTRAP_TEST, test_base: test_base))
42
- raise Domain::Errors::ServiceFailureError, out unless status.success?
43
-
44
- copy_template_file(test_base, 'as-pect.config.js')
45
- copy_template_file(test_base, 'as-pect.d.ts')
46
- write_tsconfig_file(TEST_DIR, "../#{SOURCE_DIR}")
47
25
  end
48
26
 
49
- def test_base
50
- "#{path_to_project}/#{TEST_DIR}"
51
- end
52
-
53
- def src_base
54
- "#{path_to_project}/#{SOURCE_DIR}"
55
- end
56
-
57
- def copy_template_file(destination, name)
58
- template_file = Project.project_filepath("templates/#{LANGUAGE}/#{name}")
59
- ctx.cp(template_file, "#{destination}/#{name}")
60
- end
27
+ private
61
28
 
62
29
  def write_npmrc
63
30
  ctx.system(
@@ -68,12 +35,10 @@ module Script
68
35
  )
69
36
  end
70
37
 
71
- def write_tsconfig_file(dir, path_to_source)
72
- AssemblyScriptTsConfig
73
- .new(dir_to_write_in: dir)
74
- .with_extends_assemblyscript_config(relative_path_to_node_modules: ".")
75
- .with_module_resolution_paths(paths: { "*": ["#{path_to_source}/*.ts"] })
76
- .write
38
+ def extension_point_version
39
+ out, status = ctx.capture2e("npm show #{extension_point.sdks.assemblyscript.package} version --json")
40
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
41
+ JSON.parse(out)
77
42
  end
78
43
 
79
44
  def write_package_json
@@ -82,22 +47,22 @@ module Script
82
47
  "name": "#{script_name}",
83
48
  "version": "1.0.0",
84
49
  "devDependencies": {
85
- "@shopify/scripts-sdk-as": "#{extension_point.sdks[:ts].sdk_version}",
86
- "@shopify/scripts-toolchain-as": "#{extension_point.sdks[:ts].toolchain_version}",
87
- "#{extension_point.sdks[:ts].package}": "#{extension_point.sdks[:ts].version}",
50
+ "@shopify/scripts-sdk-as": "#{extension_point.sdks.assemblyscript.sdk_version}",
51
+ "@shopify/scripts-toolchain-as": "#{extension_point.sdks.assemblyscript.toolchain_version}",
52
+ "#{extension_point.sdks.assemblyscript.package}": "^#{extension_point_version}",
88
53
  "@as-pect/cli": "4.0.0",
89
- "as-wasi": "^0.2.0",
90
- "assemblyscript": "^0.12.0"
54
+ "as-wasi": "^0.2.1",
55
+ "assemblyscript": "^0.16.1"
91
56
  },
92
57
  "scripts": {
93
- "test": "asp --config test/as-pect.config.js --summary --verbose"
58
+ "test": "asp --summary --verbose",
59
+ "build": "shopify-scripts-toolchain-as build --src src/script.ts --binary build/#{script_name}.wasm --metadata build/metadata.json -- --lib node_modules --optimize --use Date="
94
60
  },
95
61
  "engines": {
96
- "node": ">=14.5"
62
+ "node": ">=#{MIN_NODE_VERSION}"
97
63
  }
98
64
  }
99
65
  HERE
100
-
101
66
  ctx.write("package.json", package_json)
102
67
  end
103
68
  end
@@ -4,16 +4,15 @@ module Script
4
4
  module Layers
5
5
  module Infrastructure
6
6
  class AssemblyScriptTaskRunner
7
- BYTECODE_FILE = "%{name}.wasm"
8
- SCRIPT_SDK_BUILD = "npx --no-install shopify-scripts-build --src=../%{source} --binary=#{BYTECODE_FILE} "\
9
- "-- --lib=../node_modules --optimize --use Date="
7
+ BYTECODE_FILE = "build/%{name}.wasm"
8
+ METADATA_FILE = "build/metadata.json"
9
+ SCRIPT_SDK_BUILD = "npm run build"
10
10
 
11
- attr_reader :ctx, :script_name, :script_source_file
11
+ attr_reader :ctx, :script_name
12
12
 
13
- def initialize(ctx, script_name, script_source_file)
13
+ def initialize(ctx, script_name)
14
14
  @ctx = ctx
15
15
  @script_name = script_name
16
- @script_source_file = script_source_file
17
16
  end
18
17
 
19
18
  def build
@@ -28,7 +27,7 @@ module Script
28
27
  def install_dependencies
29
28
  check_node_version!
30
29
 
31
- output, status = ctx.capture2e("npm", "install", "--no-audit", "--no-optional", "--loglevel error")
30
+ output, status = ctx.capture2e("npm install --no-audit --no-optional --legacy-peer-deps --loglevel error")
32
31
  raise Errors::DependencyInstallError, output unless status.success?
33
32
  end
34
33
 
@@ -39,6 +38,16 @@ module Script
39
38
  true
40
39
  end
41
40
 
41
+ def metadata
42
+ unless @ctx.file_exist?(METADATA_FILE)
43
+ msg = @ctx.message('script.error.metadata_not_found_cause', METADATA_FILE)
44
+ raise Domain::Errors::MetadataNotFoundError, msg
45
+ end
46
+
47
+ raw_contents = File.read(METADATA_FILE)
48
+ Domain::Metadata.create_from_json(@ctx, raw_contents)
49
+ end
50
+
42
51
  private
43
52
 
44
53
  def check_node_version!
@@ -47,18 +56,40 @@ module Script
47
56
 
48
57
  require 'semantic/semantic'
49
58
  version = ::Semantic::Version.new(output[1..-1])
50
- unless version >= ::Semantic::Version.new("12.16.0")
51
- raise Errors::DependencyInstallError, "Node version must be >= v12.16.0. Current version: #{output.strip}."
59
+ unless version >= ::Semantic::Version.new(AssemblyScriptProjectCreator::MIN_NODE_VERSION)
60
+ raise Errors::DependencyInstallError,
61
+ "Node version must be >= v#{AssemblyScriptProjectCreator::MIN_NODE_VERSION}. "\
62
+ "Current version: #{output.strip}."
52
63
  end
53
64
  end
54
65
 
55
66
  def compile
56
- out, status = ctx.capture2e(format(SCRIPT_SDK_BUILD, source: script_source_file, name: script_name))
67
+ check_compilation_dependencies!
68
+
69
+ out, status = ctx.capture2e(SCRIPT_SDK_BUILD)
57
70
  raise Domain::Errors::ServiceFailureError, out unless status.success?
58
71
  end
59
72
 
73
+ def check_compilation_dependencies!
74
+ pkg = JSON.parse(File.read('package.json'))
75
+ build_script = pkg.dig('scripts', 'build')
76
+
77
+ raise Errors::BuildScriptNotFoundError,
78
+ "Build script not found" if build_script.nil?
79
+
80
+ unless build_script.start_with?("shopify-scripts")
81
+ raise Errors::InvalidBuildScriptError, "Invalid build script"
82
+ end
83
+ end
84
+
60
85
  def bytecode
61
- File.read(format(BYTECODE_FILE, name: script_name))
86
+ blob = format(BYTECODE_FILE, name: script_name)
87
+ raise Errors::WebAssemblyBinaryNotFoundError unless @ctx.file_exist?(blob)
88
+
89
+ contents = File.read(blob)
90
+ @ctx.rm(blob)
91
+
92
+ contents
62
93
  end
63
94
 
64
95
  def check_if_ep_dependencies_up_to_date!
@@ -9,7 +9,9 @@ module Script
9
9
  class AppScriptUndefinedError < ScriptProjectError; end
10
10
  class BuildError < ScriptProjectError; end
11
11
  class DependencyInstallError < ScriptProjectError; end
12
+ class EmptyResponseError < ScriptProjectError; end
12
13
  class ForbiddenError < ScriptProjectError; end
14
+
13
15
  class GraphqlError < ScriptProjectError
14
16
  attr_reader :errors
15
17
  def initialize(errors)
@@ -17,7 +19,9 @@ module Script
17
19
  super("GraphQL failed with errors: #{errors}")
18
20
  end
19
21
  end
22
+
20
23
  class ProjectCreatorNotFoundError < ScriptProjectError; end
24
+
21
25
  class ScriptRepushError < ScriptProjectError
22
26
  attr_reader :api_key
23
27
  def initialize(api_key)
@@ -25,15 +29,18 @@ module Script
25
29
  @api_key = api_key
26
30
  end
27
31
  end
32
+
28
33
  class ScriptServiceUserError < ScriptProjectError
29
34
  def initialize(query_name, errors)
30
35
  super("Failed performing #{query_name}. Errors: #{errors}.")
31
36
  end
32
37
  end
38
+
33
39
  class ShopAuthenticationError < ScriptProjectError; end
34
40
  class ShopScriptConflictError < ScriptProjectError; end
35
41
  class ShopScriptUndefinedError < ScriptProjectError; end
36
42
  class TaskRunnerNotFoundError < ScriptProjectError; end
43
+
37
44
  class PackagesOutdatedError < ScriptProjectError
38
45
  attr_reader :outdated_packages
39
46
  def initialize(outdated_packages)
@@ -41,6 +48,15 @@ module Script
41
48
  @outdated_packages = outdated_packages
42
49
  end
43
50
  end
51
+
52
+ class BuildScriptNotFoundError < ScriptProjectError; end
53
+ class InvalidBuildScriptError < ScriptProjectError; end
54
+
55
+ class WebAssemblyBinaryNotFoundError < ScriptProjectError
56
+ def initialize
57
+ super("WebAssembly binary not found")
58
+ end
59
+ end
44
60
  end
45
61
  end
46
62
  end
@@ -8,18 +8,24 @@ module Script
8
8
  Domain::ExtensionPoint.new(type, fetch_extension_point(type))
9
9
  end
10
10
 
11
+ def extension_points
12
+ extension_point_configs.map do |type, extension_point_config|
13
+ Domain::ExtensionPoint.new(type, extension_point_config)
14
+ end
15
+ end
16
+
11
17
  def extension_point_types
12
- extension_points.keys
18
+ extension_point_configs.keys
13
19
  end
14
20
 
15
21
  private
16
22
 
17
23
  def fetch_extension_point(type)
18
- raise Domain::Errors::InvalidExtensionPointError, type unless extension_points[type]
19
- extension_points[type]
24
+ raise Domain::Errors::InvalidExtensionPointError, type unless extension_point_configs[type]
25
+ extension_point_configs[type]
20
26
  end
21
27
 
22
- def extension_points
28
+ def extension_point_configs
23
29
  @extension_points ||= begin
24
30
  require 'yaml'
25
31
  YAML.load_file(Project.project_filepath('config/extension_points.yml'))
@@ -5,7 +5,8 @@ module Script
5
5
  module Infrastructure
6
6
  class ProjectCreator
7
7
  PROJECT_CREATORS = {
8
- "ts" => Infrastructure::AssemblyScriptProjectCreator,
8
+ "assemblyscript" => Infrastructure::AssemblyScriptProjectCreator,
9
+ "rust" => Infrastructure::RustProjectCreator,
9
10
  }
10
11
 
11
12
  def self.for(ctx, language, extension_point, script_name, path_to_project)
@@ -7,30 +7,42 @@ module Script
7
7
  include SmartProperties
8
8
  property! :ctx, accepts: ShopifyCli::Context
9
9
 
10
- def create_push_package(script, script_content, compiled_type)
11
- build_file_path = file_path(script.name, compiled_type)
10
+ def create_push_package(
11
+ extension_point_type:,
12
+ script_name:,
13
+ description:,
14
+ script_content:,
15
+ compiled_type:,
16
+ metadata:
17
+ )
18
+ build_file_path = file_path(script_name, compiled_type)
12
19
  write_to_path(build_file_path, script_content)
13
20
 
14
21
  Domain::PushPackage.new(
15
- build_file_path,
16
- script,
17
- script_content,
18
- compiled_type,
22
+ id: build_file_path,
23
+ extension_point_type: extension_point_type,
24
+ script_name: script_name,
25
+ description: description,
26
+ script_content: script_content,
27
+ compiled_type: compiled_type,
28
+ metadata: metadata,
19
29
  )
20
30
  end
21
31
 
22
- def get_push_package(script, compiled_type)
23
- build_file_path = file_path(script.name, compiled_type)
24
-
32
+ def get_push_package(extension_point_type:, script_name:, description:, compiled_type:, metadata:)
33
+ build_file_path = file_path(script_name, compiled_type)
25
34
  raise Domain::PushPackageNotFoundError unless ctx.file_exist?(build_file_path)
26
35
 
27
36
  script_content = File.read(build_file_path)
28
37
 
29
38
  Domain::PushPackage.new(
30
- build_file_path,
31
- script,
32
- script_content,
33
- compiled_type,
39
+ id: build_file_path,
40
+ extension_point_type: extension_point_type,
41
+ script_name: script_name,
42
+ description: description,
43
+ script_content: script_content,
44
+ compiled_type: compiled_type,
45
+ metadata: metadata,
34
46
  )
35
47
  end
36
48