shopify-cli 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +1 -0
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +9 -0
  5. data/README.md +39 -7
  6. data/Rakefile +2 -0
  7. data/dev.yml +2 -2
  8. data/docs/_config.yml +1 -18
  9. data/docs/app/node/commands/index.md +2 -80
  10. data/docs/app/node/index.md +2 -33
  11. data/docs/app/rails/commands/index.md +2 -78
  12. data/docs/app/rails/index.md +2 -34
  13. data/docs/core/index.md +2 -84
  14. data/docs/getting-started/index.md +2 -25
  15. data/docs/getting-started/install/index.md +1 -118
  16. data/docs/getting-started/migrate/index.md +2 -94
  17. data/docs/getting-started/uninstall/index.md +2 -35
  18. data/docs/getting-started/upgrade/index.md +2 -39
  19. data/docs/help/start-app/index.md +2 -4
  20. data/docs/index.md +2 -24
  21. data/install.sh +1 -1
  22. data/lib/project_types/extension/cli.rb +19 -10
  23. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  24. data/lib/project_types/extension/features/argo.rb +117 -0
  25. data/lib/project_types/extension/forms/create.rb +2 -2
  26. data/lib/project_types/extension/models/specification.rb +35 -0
  27. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
  28. data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
  29. data/lib/project_types/extension/models/specifications.rb +77 -0
  30. data/lib/project_types/extension/tasks/configure_features.rb +52 -0
  31. data/lib/project_types/extension/tasks/fetch_specifications.rb +38 -0
  32. data/lib/project_types/node/commands/create.rb +3 -1
  33. data/lib/project_types/node/commands/generate.rb +2 -11
  34. data/lib/project_types/node/messages/messages.rb +9 -44
  35. data/lib/project_types/rails/commands/create.rb +8 -9
  36. data/lib/project_types/rails/forms/create.rb +1 -1
  37. data/lib/project_types/rails/gem.rb +1 -1
  38. data/lib/project_types/rails/messages/messages.rb +1 -1
  39. data/lib/project_types/script/cli.rb +7 -4
  40. data/lib/project_types/script/commands/create.rb +6 -4
  41. data/lib/project_types/script/commands/push.rb +5 -13
  42. data/lib/project_types/script/config/extension_points.yml +9 -5
  43. data/lib/project_types/script/errors.rb +17 -0
  44. data/lib/project_types/script/forms/create.rb +26 -2
  45. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +10 -1
  46. data/lib/project_types/script/layers/application/build_script.rb +9 -4
  47. data/lib/project_types/script/layers/application/create_script.rb +12 -10
  48. data/lib/project_types/script/layers/application/extension_points.rb +24 -0
  49. data/lib/project_types/script/layers/application/push_script.rb +18 -16
  50. data/lib/project_types/script/layers/domain/errors.rb +4 -0
  51. data/lib/project_types/script/layers/domain/extension_point.rb +62 -6
  52. data/lib/project_types/script/layers/domain/metadata.rb +55 -0
  53. data/lib/project_types/script/layers/domain/push_package.rb +25 -6
  54. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +6 -6
  55. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +16 -6
  56. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +10 -4
  57. data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
  58. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +25 -13
  59. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
  60. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
  61. data/lib/project_types/script/layers/infrastructure/script_service.rb +7 -1
  62. data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
  63. data/lib/project_types/script/messages/messages.rb +39 -8
  64. data/lib/project_types/script/script_project.rb +25 -16
  65. data/lib/project_types/script/ui/error_handler.rb +34 -1
  66. data/lib/project_types/theme/cli.rb +40 -0
  67. data/lib/project_types/theme/commands/connect.rb +54 -0
  68. data/lib/project_types/theme/commands/create.rb +48 -0
  69. data/lib/project_types/theme/commands/deploy.rb +38 -0
  70. data/lib/project_types/theme/commands/generate.rb +20 -0
  71. data/lib/project_types/theme/commands/generate/env.rb +79 -0
  72. data/lib/project_types/theme/commands/push.rb +55 -0
  73. data/lib/project_types/theme/commands/serve.rb +31 -0
  74. data/lib/project_types/theme/forms/connect.rb +34 -0
  75. data/lib/project_types/theme/forms/create.rb +22 -0
  76. data/lib/project_types/theme/messages/messages.rb +147 -0
  77. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
  78. data/lib/project_types/theme/themekit.rb +113 -0
  79. data/lib/shopify-cli/admin_api.rb +42 -2
  80. data/lib/shopify-cli/api.rb +27 -24
  81. data/lib/shopify-cli/commands/system.rb +1 -1
  82. data/lib/shopify-cli/context.rb +23 -2
  83. data/lib/shopify-cli/feature.rb +0 -2
  84. data/lib/shopify-cli/http_request.rb +20 -8
  85. data/lib/shopify-cli/messages/messages.rb +6 -3
  86. data/lib/shopify-cli/method_object.rb +104 -0
  87. data/lib/shopify-cli/partners_api.rb +8 -2
  88. data/lib/shopify-cli/project_type.rb +1 -1
  89. data/lib/shopify-cli/resolve_constant.rb +25 -0
  90. data/lib/shopify-cli/result.rb +432 -0
  91. data/lib/shopify-cli/shopifolk.rb +3 -2
  92. data/lib/shopify-cli/tasks/select_org_and_shop.rb +6 -5
  93. data/lib/shopify-cli/tunnel.rb +7 -1
  94. data/lib/shopify-cli/version.rb +1 -1
  95. data/lib/shopify_cli.rb +4 -1
  96. data/shopify.fish +1 -1
  97. data/shopify.sh +1 -1
  98. data/vendor/deps/cli-kit/REVISION +1 -1
  99. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
  100. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
  101. data/vendor/deps/cli-ui/REVISION +1 -1
  102. data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
  103. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
  104. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
  105. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
  106. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
  107. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
  108. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
  109. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
  110. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
  111. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
  112. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
  113. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
  114. data/vendor/deps/webrick/.gitignore +9 -0
  115. data/vendor/deps/webrick/Gemfile +3 -0
  116. data/vendor/deps/webrick/LICENSE.txt +22 -0
  117. data/vendor/deps/webrick/README.md +61 -0
  118. data/vendor/deps/webrick/Rakefile +10 -0
  119. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  120. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  121. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  122. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  123. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  124. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  125. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  126. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  127. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  128. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  129. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  130. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  131. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  132. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  133. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  134. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  135. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  136. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  137. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  138. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  139. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  140. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  141. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  142. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  143. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  144. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  145. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  146. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  147. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  148. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  149. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  150. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  151. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  152. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  153. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  154. data/vendor/deps/webrick/webrick.gemspec +74 -0
  155. metadata +70 -26
  156. data/docs/Gemfile +0 -5
  157. data/docs/Gemfile.lock +0 -258
  158. data/docs/_data/nav.yml +0 -35
  159. data/docs/_includes/footer.html +0 -15
  160. data/docs/_includes/head.html +0 -19
  161. data/docs/_includes/sidebar_nav.html +0 -22
  162. data/docs/_includes/toc.html +0 -112
  163. data/docs/_layouts/default.html +0 -79
  164. data/docs/css/docs.css +0 -157
  165. data/docs/images/header.png +0 -0
  166. data/docs/installing-ruby.md +0 -28
  167. data/lib/project_types/extension/features/argo/admin.rb +0 -20
  168. data/lib/project_types/extension/features/argo/base.rb +0 -129
  169. data/lib/project_types/extension/features/argo/checkout.rb +0 -20
  170. data/lib/project_types/extension/models/type.rb +0 -81
  171. data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
  172. data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
  173. data/lib/project_types/node/commands/generate/billing.rb +0 -39
  174. data/lib/project_types/node/commands/generate/page.rb +0 -59
  175. data/lib/project_types/node/commands/generate/webhook.rb +0 -37
  176. data/lib/project_types/script/layers/domain/script.rb +0 -18
  177. data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -47
  178. data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
  179. 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"]
@@ -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.",
@@ -39,14 +42,39 @@ module Script
39
42
  project_exists_cause: "Directory with the same name as the script already exists.",
40
43
  project_exists_help: "Use different script name and try again.",
41
44
 
42
- invalid_extension_cause: "Invalid extension point %s",
45
+ invalid_extension_cause: "Invalid extension point %s.",
43
46
  invalid_extension_help: "Allowed values: %s.",
44
47
 
48
+ invalid_language_cause: "Invalid language %s.",
49
+ invalid_language_help: "Allowed values: %s.",
50
+
45
51
  invalid_config: "Can't change the configuration values because %1$s is missing or "\
46
52
  "it is not formatted properly.",
47
53
 
48
54
  script_not_found_cause: "Couldn't find script %s for extension point %s",
49
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",
50
78
  app_not_installed_cause: "App not installed on store.",
51
79
 
52
80
  app_script_not_pushed_help: "Script isn't on the app. Run {{command:shopify push}}, and then try again.",
@@ -80,13 +108,13 @@ module Script
80
108
  packages_outdated_cause: "These npm packages are out of date: %s.",
81
109
  packages_outdated_help: "To update them, run {{cyan:npm install --save-dev %s}}.",
82
110
 
83
- invalid_build_script: "Invalid build script.",
84
- build_script_not_found: "Build script not found.",
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.",
85
115
  # rubocop:disable Layout/LineLength
86
- build_script_suggestion: "Root package.json needs a script named build, which" \
87
- "uses @shopify/scripts-toolchain-as to compile to WebAssembly.\n" \
88
- "Example:\n" \
89
- "build: npx shopify-scripts-toolchain-as build --src src/script.ts --binary <script_name>.wasm -- --lib node_modules --optimize --use Date=",
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=",
90
118
 
91
119
  web_assembly_binary_not_found: "WebAssembly binary not found.",
92
120
  web_assembly_binary_not_found_suggestion: "No WebAssembly binary found." \
@@ -100,6 +128,7 @@ module Script
100
128
  Usage: {{command:%1$s create script}}
101
129
  Options:
102
130
  {{command:--name=NAME}} Script project name. Use any string.
131
+ {{command:--description=DESCRIPTION}} Description of the project. Use any string.
103
132
  {{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
104
133
  HELP
105
134
 
@@ -109,7 +138,7 @@ module Script
109
138
 
110
139
  change_directory_notice: "{{*}} Change directories to {{green:%s}} to run script commands",
111
140
  creating: "Creating script",
112
- created: "Created script: {{green:%s}}",
141
+ created: "Created script",
113
142
  },
114
143
 
115
144
  push: {
@@ -171,7 +200,9 @@ module Script
171
200
  forms: {
172
201
  create: {
173
202
  select_extension_point: "Which extension point do you want to use?",
203
+ select_language: "Which language do you want to use?",
174
204
  script_name: "Script Name",
205
+ description: "Description",
175
206
  },
176
207
  },
177
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)
@@ -53,6 +53,14 @@ module Script
53
53
  {
54
54
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_config', e.config_file),
55
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
+ }
56
64
  when Errors::InvalidScriptNameError
57
65
  {
58
66
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_script_name_cause'),
@@ -81,12 +89,17 @@ module Script
81
89
  cause_of_error: ShopifyCli::Context.message('script.error.project_exists_cause'),
82
90
  help_suggestion: ShopifyCli::Context.message('script.error.project_exists_help'),
83
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
+ }
84
97
  when Layers::Domain::Errors::InvalidExtensionPointError
85
98
  {
86
99
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_extension_cause', e.type),
87
100
  help_suggestion: ShopifyCli::Context.message(
88
101
  'script.error.invalid_extension_help',
89
- Script::Layers::Application::ExtensionPoints.types.join(', ')
102
+ Script::Layers::Application::ExtensionPoints.types.join(', ')
90
103
  ),
91
104
  }
92
105
  when Layers::Domain::Errors::ScriptNotFoundError
@@ -97,6 +110,21 @@ module Script
97
110
  e.extension_point_type
98
111
  ),
99
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
+ }
100
128
  when Layers::Infrastructure::Errors::AppNotInstalledError
101
129
  {
102
130
  cause_of_error: ShopifyCli::Context.message('script.error.app_not_installed_cause'),
@@ -135,6 +163,11 @@ module Script
135
163
  cause_of_error: ShopifyCli::Context.message('script.error.script_repush_cause', e.api_key),
136
164
  help_suggestion: ShopifyCli::Context.message('script.error.script_repush_help'),
137
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
+ }
138
171
  when Layers::Infrastructure::Errors::ShopAuthenticationError
139
172
  {
140
173
  cause_of_error: ShopifyCli::Context.message('script.error.shop_auth_cause'),
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ module Theme
3
+ class Project < ShopifyCli::ProjectType
4
+ hidden_feature
5
+
6
+ title('Theme')
7
+ creator('Theme::Commands::Create')
8
+ connector('Theme::Commands::Connect')
9
+
10
+ register_command('Theme::Commands::Deploy', 'deploy')
11
+ register_command('Theme::Commands::Generate', 'generate')
12
+ register_command('Theme::Commands::Push', 'push')
13
+ register_command('Theme::Commands::Serve', 'serve')
14
+
15
+ register_task('Theme::Tasks::EnsureThemekitInstalled', :ensure_themekit_installed)
16
+
17
+ require Project.project_filepath('messages/messages')
18
+ register_messages(Theme::Messages::MESSAGES)
19
+ end
20
+
21
+ module Commands
22
+ autoload :Connect, Project.project_filepath('commands/connect')
23
+ autoload :Create, Project.project_filepath('commands/create')
24
+ autoload :Deploy, Project.project_filepath('commands/deploy')
25
+ autoload :Generate, Project.project_filepath('commands/generate')
26
+ autoload :Push, Project.project_filepath('commands/push')
27
+ autoload :Serve, Project.project_filepath('commands/serve')
28
+ end
29
+
30
+ module Tasks
31
+ autoload :EnsureThemekitInstalled, Project.project_filepath('tasks/ensure_themekit_installed')
32
+ end
33
+
34
+ module Forms
35
+ autoload :Create, Project.project_filepath('forms/create')
36
+ autoload :Connect, Project.project_filepath('forms/connect')
37
+ end
38
+
39
+ autoload :Themekit, Project.project_filepath('themekit')
40
+ end