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,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ class RustProjectCreator
7
+ include SmartProperties
8
+ property! :ctx, accepts: ShopifyCli::Context
9
+ property! :extension_point, accepts: Domain::ExtensionPoint
10
+ property! :script_name, accepts: String
11
+ property! :path_to_project, accepts: String
12
+
13
+ ORIGIN_BRANCH = 'main'
14
+ SAMPLE_PATH = 'default'
15
+
16
+ def setup_dependencies
17
+ git_init
18
+ setup_remote
19
+ setup_sparse_checkout
20
+ pull
21
+ clean
22
+ set_script_name
23
+ end
24
+
25
+ def bootstrap
26
+ end
27
+
28
+ private
29
+
30
+ def git_init
31
+ out, status = ctx.capture2e("git init")
32
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
33
+ end
34
+
35
+ def setup_remote
36
+ repo = extension_point.sdks.rust.package
37
+ out, status = ctx.capture2e("git remote add -f origin #{repo}")
38
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
39
+ end
40
+
41
+ def setup_sparse_checkout
42
+ type = extension_point.type
43
+ out, status = ctx.capture2e("git config core.sparsecheckout true")
44
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
45
+ out, status = ctx.capture2e("echo #{type}/#{SAMPLE_PATH} >> .git/info/sparse-checkout")
46
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
47
+ end
48
+
49
+ def pull
50
+ out, status = ctx.capture2e("git pull origin #{ORIGIN_BRANCH}")
51
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
52
+ end
53
+
54
+ def clean
55
+ type = extension_point.type
56
+ ctx.rm_rf(".git")
57
+ source = File.join(path_to_project, File.join(type, SAMPLE_PATH))
58
+ FileUtils.copy_entry(source, path_to_project)
59
+ ctx.rm_rf(type)
60
+ end
61
+
62
+ def set_script_name
63
+ config_file = 'Cargo.toml'
64
+ upstream_name = "#{extension_point.type.gsub('_', '-')}-default"
65
+ contents = File.read(config_file)
66
+ new_contents = contents.sub(upstream_name, script_name)
67
+ File.write(config_file, new_contents)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ module Script
3
+ module Layers
4
+ module Infrastructure
5
+ class RustTaskRunner
6
+ attr_reader :ctx, :script_name
7
+
8
+ BUILD_TARGET = "wasm32-unknown-unknown"
9
+ METADATA_FILE = "build/metadata.json"
10
+
11
+ def initialize(ctx, script_name)
12
+ @ctx = ctx
13
+ @script_name = script_name
14
+ end
15
+
16
+ def dependencies_installed?
17
+ true
18
+ end
19
+
20
+ def install_dependencies
21
+ end
22
+
23
+ def build
24
+ compile
25
+ bytecode
26
+ end
27
+
28
+ def compiled_type
29
+ "wasm"
30
+ end
31
+
32
+ def metadata
33
+ unless @ctx.file_exist?(METADATA_FILE)
34
+ msg = @ctx.message('script.error.metadata_not_found_cause', METADATA_FILE)
35
+ raise Domain::Errors::MetadataNotFoundError, msg
36
+ end
37
+
38
+ raw_contents = File.read(METADATA_FILE)
39
+ Domain::Metadata.create_from_json(@ctx, raw_contents)
40
+ end
41
+
42
+ private
43
+
44
+ def compile
45
+ out, status = ctx.capture2e("cargo build --target=#{BUILD_TARGET} --release")
46
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
47
+ end
48
+
49
+ def bytecode
50
+ binary_name = "#{script_name}.wasm"
51
+ binary_path = "target/#{BUILD_TARGET}/release/#{binary_name}"
52
+ raise Errors::WebAssemblyBinaryNotFoundError unless ctx.file_exist?(binary_path)
53
+
54
+ File.read(binary_path)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -15,16 +15,22 @@ module Script
15
15
  script_name:,
16
16
  script_content:,
17
17
  compiled_type:,
18
+ description: nil,
18
19
  api_key: nil,
19
- force: false
20
+ force: false,
21
+ metadata:
20
22
  )
21
23
  query_name = "app_script_update_or_create"
22
24
  variables = {
23
25
  extensionPointName: extension_point_type.upcase,
24
26
  title: script_name,
27
+ description: description,
25
28
  sourceCode: Base64.encode64(script_content),
26
29
  language: compiled_type,
27
30
  force: force,
31
+ schemaMajorVersion: metadata.schema_major_version.to_s, # API expects string value
32
+ schemaMinorVersion: metadata.schema_minor_version.to_s, # API expects string value
33
+ useMsgpack: metadata.use_msgpack,
28
34
  }
29
35
  resp_hash = script_service_request(query_name: query_name, api_key: api_key, variables: variables)
30
36
  user_errors = resp_hash["data"]["appScriptUpdateOrCreate"]["userErrors"]
@@ -146,6 +152,8 @@ module Script
146
152
  end
147
153
 
148
154
  def raise_if_graphql_failed(response)
155
+ raise Errors::EmptyResponseError if response.nil?
156
+
149
157
  return unless response.key?('errors')
150
158
  case error_code(response['errors'])
151
159
  when 'forbidden'
@@ -5,12 +5,13 @@ module Script
5
5
  module Infrastructure
6
6
  class TaskRunner
7
7
  TASK_RUNNERS = {
8
- "ts" => Infrastructure::AssemblyScriptTaskRunner,
8
+ "assemblyscript" => Infrastructure::AssemblyScriptTaskRunner,
9
+ "rust" => Infrastructure::RustTaskRunner,
9
10
  }
10
11
 
11
- def self.for(ctx, language, script_name, script_source_file)
12
+ def self.for(ctx, language, script_name)
12
13
  raise Errors::TaskRunnerNotFoundError unless TASK_RUNNERS[language]
13
- TASK_RUNNERS[language].new(ctx, script_name, script_source_file)
14
+ TASK_RUNNERS[language].new(ctx, script_name)
14
15
  end
15
16
  end
16
17
  end
@@ -5,6 +5,9 @@ module Script
5
5
  MESSAGES = {
6
6
  script: {
7
7
  error: {
8
+ deprecated_ep: "This project uses an extension point %s which has been deprecated. "\
9
+ "This Script will no longer function in production.",
10
+ deprecated_ep_cause: "Try using a different extension point.",
8
11
  generic: "{{red:{{x}} Error}}",
9
12
  eacces_cause: "You don't have permission to write to this directory.",
10
13
  eacces_help: "Change your directory permissions and try again.",
@@ -18,6 +21,10 @@ module Script
18
21
  invalid_context_cause: "Your .shopify-cli.yml file is not correct.",
19
22
  invalid_context_help: "See https://help.shopify.com",
20
23
 
24
+ invalid_config_props_cause: "{{command:--config_props}} is formatted incorrectly.",
25
+ invalid_config_props_help: "Try again using this format: "\
26
+ "{{cyan:--config_props='name1:value1, name2:value2'}}",
27
+
21
28
  invalid_script_name_cause: "Invalid script name.",
22
29
  invalid_script_name_help: "Replace or remove unsupported characters. Valid characters "\
23
30
  "are numbers, letters, hyphens, or underscores.",
@@ -35,14 +42,39 @@ module Script
35
42
  project_exists_cause: "Directory with the same name as the script already exists.",
36
43
  project_exists_help: "Use different script name and try again.",
37
44
 
38
- invalid_extension_cause: "Invalid extension point %s",
45
+ invalid_extension_cause: "Invalid extension point %s.",
39
46
  invalid_extension_help: "Allowed values: %s.",
40
47
 
48
+ invalid_language_cause: "Invalid language %s.",
49
+ invalid_language_help: "Allowed values: %s.",
50
+
41
51
  invalid_config: "Can't change the configuration values because %1$s is missing or "\
42
52
  "it is not formatted properly.",
43
53
 
44
54
  script_not_found_cause: "Couldn't find script %s for extension point %s",
45
55
 
56
+ service_failure_cause: "Internal service error.",
57
+ service_failure_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
58
+
59
+ user_error_cause: "Invalid script extension metadata.",
60
+ user_error_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
61
+
62
+ metadata_validation_cause: "Invalid script extension metadata.",
63
+ metadata_validation_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
64
+
65
+ metadata_schema_versions_missing: "Invalid script metadata:" \
66
+ " 'schemaVersions' field is missing",
67
+ metadata_schema_versions_single_key: "Invalid script extension metadata:" \
68
+ " 'schemaVersions' can have only one extension point name.",
69
+ metadata_schema_versions_missing_major: "Invalid script extension metadata:" \
70
+ " 'schemaVersions' is missing the 'major' field",
71
+ metadata_schema_versions_missing_minor: "Invalid script extension metadata:" \
72
+ " 'schemaVersions' is missing the 'minor' field",
73
+
74
+ metadata_not_found_cause: "Script version file (%s) cannot be found.",
75
+ metadata_not_found_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date and " \
76
+ "'package.json' contains a 'scripts/build' entry with a " \
77
+ "'--metadata build/metadata.json' argument",
46
78
  app_not_installed_cause: "App not installed on store.",
47
79
 
48
80
  app_script_not_pushed_help: "Script isn't on the app. Run {{command:shopify push}}, and then try again.",
@@ -53,6 +85,9 @@ module Script
53
85
  dependency_install_cause: "Something went wrong while installing the dependencies that are needed.",
54
86
  dependency_install_help: "Correct the errors and try again.",
55
87
 
88
+ failed_api_request_cause: "Something went wrong while communicating with Shopify.",
89
+ failed_api_request_help: "Try again.",
90
+
56
91
  forbidden_error_cause: "You do not have permission to do this action.",
57
92
 
58
93
  graphql_error_cause: "An error was returned: %s.",
@@ -70,8 +105,21 @@ module Script
70
105
 
71
106
  shop_script_undefined_cause: "Script is already turned off in store.",
72
107
 
73
- packages_outdated_cause: "The following npm packages are out of date: %s.",
74
- packages_outdated_help: "Update them by running {{cyan:npm install --save-dev %s}}.",
108
+ packages_outdated_cause: "These npm packages are out of date: %s.",
109
+ packages_outdated_help: "To update them, run {{cyan:npm install --save-dev %s}}.",
110
+
111
+ invalid_build_script: "The root package.json contains an invalid build command that " \
112
+ "is needed to compile your script to WebAssembly.",
113
+ build_script_not_found: "The root package.json is missing the build command that " \
114
+ "is needed to compile your script to WebAssembly.",
115
+ # rubocop:disable Layout/LineLength
116
+ build_script_suggestion: "\n\nFor example, your package.json needs the following command:" \
117
+ "\nbuild: npx shopify-scripts-toolchain-as build --src src/script.ts --binary build/<script_name>.wasm --metadata build/metadata.json -- --lib node_modules --optimize --use Date=",
118
+
119
+ web_assembly_binary_not_found: "WebAssembly binary not found.",
120
+ web_assembly_binary_not_found_suggestion: "No WebAssembly binary found." \
121
+ "Check that your build npm script outputs the generated binary to the root of the directory." \
122
+ "Generated binary should match the script name: <script_name>.wasm",
75
123
  },
76
124
 
77
125
  create: {
@@ -80,6 +128,7 @@ module Script
80
128
  Usage: {{command:%1$s create script}}
81
129
  Options:
82
130
  {{command:--name=NAME}} Script project name. Use any string.
131
+ {{command:--description=DESCRIPTION}} Description of the project. Use any string.
83
132
  {{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
84
133
  HELP
85
134
 
@@ -89,7 +138,7 @@ module Script
89
138
 
90
139
  change_directory_notice: "{{*}} Change directories to {{green:%s}} to run script commands",
91
140
  creating: "Creating script",
92
- created: "Created script: {{green:%s}}",
141
+ created: "Created script",
93
142
  },
94
143
 
95
144
  push: {
@@ -151,7 +200,9 @@ module Script
151
200
  forms: {
152
201
  create: {
153
202
  select_extension_point: "Which extension point do you want to use?",
203
+ select_language: "Which language do you want to use?",
154
204
  script_name: "Script Name",
205
+ description: "Description",
155
206
  },
156
207
  },
157
208
 
@@ -2,16 +2,15 @@
2
2
 
3
3
  module Script
4
4
  class ScriptProject < ShopifyCli::Project
5
- SUPPORTED_LANGUAGES = %w(ts)
6
- SOURCE_DIR = "src"
7
-
8
- attr_reader :extension_point_type, :script_name, :language
5
+ attr_reader :extension_point_type, :script_name, :language, :description
9
6
 
10
7
  def initialize(*args)
11
8
  super
12
- @extension_point_type = lookup_config('extension_point_type')
13
- @script_name = lookup_config('script_name')
14
- @language = 'ts'
9
+ @extension_point_type = lookup_config!('extension_point_type')
10
+ raise Errors::DeprecatedEPError, @extension_point_type if deprecated?(@extension_point_type)
11
+ @script_name = lookup_config!('script_name')
12
+ @description = lookup_config('description')
13
+ @language = lookup_language
15
14
  ShopifyCli::Core::Monorail.metadata = {
16
15
  "script_name" => @script_name,
17
16
  "extension_point_type" => @extension_point_type,
@@ -19,25 +18,35 @@ module Script
19
18
  }
20
19
  end
21
20
 
22
- def file_name
23
- "script.#{language}"
21
+ def api_key
22
+ env[:api_key]
24
23
  end
25
24
 
26
- def source_file
27
- "#{SOURCE_DIR}/#{file_name}"
28
- end
25
+ private
29
26
 
30
- def source_path
31
- "#{script_name}/#{source_file}"
27
+ def deprecated?(ep)
28
+ Script::Layers::Application::ExtensionPoints.deprecated_types.include?(ep)
32
29
  end
33
30
 
34
- private
35
-
36
31
  def lookup_config(key)
32
+ return nil unless config.key?(key)
33
+ config[key]
34
+ end
35
+
36
+ def lookup_config!(key)
37
37
  raise Errors::InvalidContextError, key unless config.key?(key)
38
38
  config[key]
39
39
  end
40
40
 
41
+ def lookup_language
42
+ lang = lookup_config('language')&.downcase || Layers::Domain::ExtensionPointAssemblyScriptSDK.language
43
+ if Layers::Application::ExtensionPoints.supported_language?(type: extension_point_type, language: lang)
44
+ lang
45
+ else
46
+ raise Errors::InvalidLanguageError.new(lang, extension_point_type)
47
+ end
48
+ end
49
+
41
50
  class << self
42
51
  def create(ctx, dir)
43
52
  raise Errors::ScriptProjectAlreadyExistsError, dir if ctx.dir_exist?(dir)
@@ -44,10 +44,23 @@ module Script
44
44
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_context_cause'),
45
45
  help_suggestion: ShopifyCli::Context.message('script.error.invalid_context_help'),
46
46
  }
47
+ when Errors::InvalidConfigProps
48
+ {
49
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_config_props_cause'),
50
+ help_suggestion: ShopifyCli::Context.message('script.error.invalid_config_props_help'),
51
+ }
47
52
  when Errors::InvalidConfigYAMLError
48
53
  {
49
54
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_config', e.config_file),
50
55
  }
56
+ when Errors::InvalidLanguageError
57
+ {
58
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_language_cause', e.language),
59
+ help_suggestion: ShopifyCli::Context.message(
60
+ 'script.error.invalid_language_help',
61
+ Script::Layers::Application::ExtensionPoints.languages(type: e.extension_point_type).join(', ')
62
+ ),
63
+ }
51
64
  when Errors::InvalidScriptNameError
52
65
  {
53
66
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_script_name_cause'),
@@ -76,12 +89,17 @@ module Script
76
89
  cause_of_error: ShopifyCli::Context.message('script.error.project_exists_cause'),
77
90
  help_suggestion: ShopifyCli::Context.message('script.error.project_exists_help'),
78
91
  }
92
+ when Errors::DeprecatedEPError
93
+ {
94
+ cause_of_error: ShopifyCli::Context.message('script.error.deprecated_ep', e.ep),
95
+ help_suggestion: ShopifyCli::Context.message('script.error.deprecated_ep_cause'),
96
+ }
79
97
  when Layers::Domain::Errors::InvalidExtensionPointError
80
98
  {
81
99
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_extension_cause', e.type),
82
100
  help_suggestion: ShopifyCli::Context.message(
83
101
  'script.error.invalid_extension_help',
84
- Script::Layers::Application::ExtensionPoints.types.join(', ')
102
+ Script::Layers::Application::ExtensionPoints.types.join(', ')
85
103
  ),
86
104
  }
87
105
  when Layers::Domain::Errors::ScriptNotFoundError
@@ -92,6 +110,21 @@ module Script
92
110
  e.extension_point_type
93
111
  ),
94
112
  }
113
+ when Layers::Domain::Errors::ServiceFailureError
114
+ {
115
+ cause_of_error: ShopifyCli::Context.message('script.error.service_failure_cause'),
116
+ help_suggestion: ShopifyCli::Context.message('script.error.service_failure_help'),
117
+ }
118
+ when Layers::Domain::Errors::MetadataValidationError
119
+ {
120
+ cause_of_error: ShopifyCli::Context.message('script.error.metadata_validation_cause'),
121
+ help_suggestion: ShopifyCli::Context.message('script.error.metadata_validation_help'),
122
+ }
123
+ when Layers::Domain::Errors::MetadataNotFoundError
124
+ {
125
+ cause_of_error: ShopifyCli::Context.message('script.error.metadata_not_found_cause'),
126
+ help_suggestion: ShopifyCli::Context.message('script.error.metadata_not_found_help'),
127
+ }
95
128
  when Layers::Infrastructure::Errors::AppNotInstalledError
96
129
  {
97
130
  cause_of_error: ShopifyCli::Context.message('script.error.app_not_installed_cause'),
@@ -111,6 +144,11 @@ module Script
111
144
  cause_of_error: ShopifyCli::Context.message('script.error.dependency_install_cause'),
112
145
  help_suggestion: ShopifyCli::Context.message('script.error.dependency_install_help'),
113
146
  }
147
+ when Layers::Infrastructure::Errors::EmptyResponseError
148
+ {
149
+ cause_of_error: ShopifyCli::Context.message('script.error.failed_api_request_cause'),
150
+ help_suggestion: ShopifyCli::Context.message('script.error.failed_api_request_help'),
151
+ }
114
152
  when Layers::Infrastructure::Errors::ForbiddenError
115
153
  {
116
154
  cause_of_error: ShopifyCli::Context.message('script.error.forbidden_error_cause'),
@@ -125,6 +163,11 @@ module Script
125
163
  cause_of_error: ShopifyCli::Context.message('script.error.script_repush_cause', e.api_key),
126
164
  help_suggestion: ShopifyCli::Context.message('script.error.script_repush_help'),
127
165
  }
166
+ when Layers::Infrastructure::Errors::ScriptServiceUserError
167
+ {
168
+ cause_of_error: ShopifyCli::Context.message('script.error.user_error_cause'),
169
+ help_suggestion: ShopifyCli::Context.message('script.error.user_error_help'),
170
+ }
128
171
  when Layers::Infrastructure::Errors::ShopAuthenticationError
129
172
  {
130
173
  cause_of_error: ShopifyCli::Context.message('script.error.shop_auth_cause'),
@@ -150,6 +193,21 @@ module Script
150
193
  e.outdated_packages.collect { |package| "#{package}@latest" }.join(' ')
151
194
  ),
152
195
  }
196
+ when Layers::Infrastructure::Errors::BuildScriptNotFoundError
197
+ {
198
+ cause_of_error: ShopifyCli::Context.message('script.error.build_script_not_found'),
199
+ help_suggestion: ShopifyCli::Context.message('script.error.build_script_suggestion'),
200
+ }
201
+ when Layers::Infrastructure::Errors::InvalidBuildScriptError
202
+ {
203
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_build_script'),
204
+ help_suggestion: ShopifyCli::Context.message('script.error.build_script_suggestion'),
205
+ }
206
+ when Layers::Infrastructure::Errors::WebAssemblyBinaryNotFoundError
207
+ {
208
+ cause_of_error: ShopifyCli::Context.message('script.error.web_assembly_binary_not_found'),
209
+ help_suggestion: ShopifyCli::Context.message('script.error.web_assembly_binary_not_found_suggestion'),
210
+ }
153
211
  end
154
212
  end
155
213
  end