shopify-cli 0.9.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 (273) hide show
  1. checksums.yaml +7 -0
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/CODE_OF_CONDUCT.md +73 -0
  4. data/.github/CONTRIBUTING.md +51 -0
  5. data/.github/DESIGN.md +153 -0
  6. data/.github/ISSUE_TEMPLATE.md +38 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
  8. data/.github/probots.yml +3 -0
  9. data/.gitignore +19 -0
  10. data/.rubocop.yml +47 -0
  11. data/.ruby-version +1 -0
  12. data/.travis.yml +12 -0
  13. data/Gemfile +22 -0
  14. data/Gemfile.lock +77 -0
  15. data/LICENSE.md +7 -0
  16. data/README.md +13 -0
  17. data/Rakefile +101 -0
  18. data/SECURITY.md +59 -0
  19. data/Vagrantfile +17 -0
  20. data/bin/load_shopify.rb +20 -0
  21. data/bin/shopify +32 -0
  22. data/dev.yml +17 -0
  23. data/docs/Gemfile +5 -0
  24. data/docs/Gemfile.lock +248 -0
  25. data/docs/_config.yml +16 -0
  26. data/docs/_data/nav.yml +26 -0
  27. data/docs/_includes/footer.html +15 -0
  28. data/docs/_includes/head.html +19 -0
  29. data/docs/_includes/sidebar_nav.html +22 -0
  30. data/docs/_includes/toc.html +112 -0
  31. data/docs/_layouts/default.html +79 -0
  32. data/docs/app/node/commands/index.md +82 -0
  33. data/docs/app/node/index.md +35 -0
  34. data/docs/app/rails/commands/index.md +80 -0
  35. data/docs/app/rails/index.md +36 -0
  36. data/docs/core/index.md +70 -0
  37. data/docs/css/docs.css +157 -0
  38. data/docs/getting-started/index.md +61 -0
  39. data/docs/help/start-app/index.md +6 -0
  40. data/docs/images/header.png +0 -0
  41. data/docs/index.md +27 -0
  42. data/docs/installing-ruby.md +28 -0
  43. data/ext/shopify-cli/extconf.rb +27 -0
  44. data/install.sh +7 -0
  45. data/lib/docgen/class_template.md.erb +81 -0
  46. data/lib/docgen/index_template.md.erb +5 -0
  47. data/lib/docgen/markdown.rb +101 -0
  48. data/lib/graphql/admin_introspection.graphql +87 -0
  49. data/lib/graphql/all_organizations.graphql +19 -0
  50. data/lib/graphql/all_orgs_with_apps.graphql +30 -0
  51. data/lib/graphql/api_versions.graphql +6 -0
  52. data/lib/graphql/convert_dev_to_test_store.graphql +10 -0
  53. data/lib/graphql/create_app.graphql +20 -0
  54. data/lib/graphql/create_customer.graphql +9 -0
  55. data/lib/graphql/create_draft_order.graphql +8 -0
  56. data/lib/graphql/create_product.graphql +9 -0
  57. data/lib/graphql/extension_create.graphql +21 -0
  58. data/lib/graphql/extension_update_draft.graphql +18 -0
  59. data/lib/graphql/find_organization.graphql +17 -0
  60. data/lib/graphql/get_app_urls.graphql +6 -0
  61. data/lib/graphql/update_dashboard_urls.graphql +8 -0
  62. data/lib/project_types/extension/cli.rb +71 -0
  63. data/lib/project_types/extension/commands/build.rb +29 -0
  64. data/lib/project_types/extension/commands/create.rb +49 -0
  65. data/lib/project_types/extension/commands/extension_command.rb +22 -0
  66. data/lib/project_types/extension/commands/push.rb +69 -0
  67. data/lib/project_types/extension/commands/register.rb +78 -0
  68. data/lib/project_types/extension/commands/serve.rb +24 -0
  69. data/lib/project_types/extension/commands/tunnel.rb +69 -0
  70. data/lib/project_types/extension/extension_project.rb +85 -0
  71. data/lib/project_types/extension/extension_project_keys.rb +10 -0
  72. data/lib/project_types/extension/features/argo.rb +48 -0
  73. data/lib/project_types/extension/features/argo_dependencies.rb +28 -0
  74. data/lib/project_types/extension/features/argo_setup.rb +54 -0
  75. data/lib/project_types/extension/features/argo_setup_step.rb +31 -0
  76. data/lib/project_types/extension/features/argo_setup_steps.rb +53 -0
  77. data/lib/project_types/extension/features/tunnel_url.rb +20 -0
  78. data/lib/project_types/extension/forms/create.rb +52 -0
  79. data/lib/project_types/extension/forms/register.rb +48 -0
  80. data/lib/project_types/extension/messages/message_loading.rb +37 -0
  81. data/lib/project_types/extension/messages/messages.rb +126 -0
  82. data/lib/project_types/extension/models/app.rb +14 -0
  83. data/lib/project_types/extension/models/registration.rb +19 -0
  84. data/lib/project_types/extension/models/type.rb +76 -0
  85. data/lib/project_types/extension/models/types/checkout_post_purchase.rb +20 -0
  86. data/lib/project_types/extension/models/types/subscription_management.rb +20 -0
  87. data/lib/project_types/extension/models/validation_error.rb +17 -0
  88. data/lib/project_types/extension/models/version.rb +15 -0
  89. data/lib/project_types/extension/tasks/converters/registration_converter.rb +26 -0
  90. data/lib/project_types/extension/tasks/converters/validation_error_converter.rb +25 -0
  91. data/lib/project_types/extension/tasks/converters/version_converter.rb +28 -0
  92. data/lib/project_types/extension/tasks/create_extension.rb +31 -0
  93. data/lib/project_types/extension/tasks/get_apps.rb +34 -0
  94. data/lib/project_types/extension/tasks/update_draft.rb +29 -0
  95. data/lib/project_types/extension/tasks/user_errors.rb +45 -0
  96. data/lib/project_types/node/cli.rb +37 -0
  97. data/lib/project_types/node/commands/create.rb +117 -0
  98. data/lib/project_types/node/commands/deploy.rb +22 -0
  99. data/lib/project_types/node/commands/deploy/heroku.rb +91 -0
  100. data/lib/project_types/node/commands/generate.rb +51 -0
  101. data/lib/project_types/node/commands/generate/billing.rb +37 -0
  102. data/lib/project_types/node/commands/generate/page.rb +55 -0
  103. data/lib/project_types/node/commands/generate/webhook.rb +33 -0
  104. data/lib/project_types/node/commands/open.rb +16 -0
  105. data/lib/project_types/node/commands/populate.rb +23 -0
  106. data/lib/project_types/node/commands/populate/customer.rb +31 -0
  107. data/lib/project_types/node/commands/populate/draft_order.rb +28 -0
  108. data/lib/project_types/node/commands/populate/product.rb +30 -0
  109. data/lib/project_types/node/commands/serve.rb +45 -0
  110. data/lib/project_types/node/commands/tunnel.rb +39 -0
  111. data/lib/project_types/node/forms/create.rb +87 -0
  112. data/lib/project_types/node/messages/messages.rb +260 -0
  113. data/lib/project_types/rails/cli.rb +41 -0
  114. data/lib/project_types/rails/commands/create.rb +126 -0
  115. data/lib/project_types/rails/commands/deploy.rb +22 -0
  116. data/lib/project_types/rails/commands/deploy/heroku.rb +113 -0
  117. data/lib/project_types/rails/commands/generate.rb +49 -0
  118. data/lib/project_types/rails/commands/generate/webhook.rb +39 -0
  119. data/lib/project_types/rails/commands/open.rb +16 -0
  120. data/lib/project_types/rails/commands/populate.rb +23 -0
  121. data/lib/project_types/rails/commands/populate/customer.rb +31 -0
  122. data/lib/project_types/rails/commands/populate/draft_order.rb +28 -0
  123. data/lib/project_types/rails/commands/populate/product.rb +30 -0
  124. data/lib/project_types/rails/commands/serve.rb +47 -0
  125. data/lib/project_types/rails/commands/tunnel.rb +39 -0
  126. data/lib/project_types/rails/forms/create.rb +116 -0
  127. data/lib/project_types/rails/gem.rb +56 -0
  128. data/lib/project_types/rails/messages/messages.rb +283 -0
  129. data/lib/project_types/rails/ruby.rb +17 -0
  130. data/lib/project_types/script/cli.rb +76 -0
  131. data/lib/project_types/script/commands/create.rb +45 -0
  132. data/lib/project_types/script/commands/disable.rb +36 -0
  133. data/lib/project_types/script/commands/enable.rb +46 -0
  134. data/lib/project_types/script/commands/push.rb +39 -0
  135. data/lib/project_types/script/config/extension_points.yml +18 -0
  136. data/lib/project_types/script/errors.rb +16 -0
  137. data/lib/project_types/script/forms/create.rb +29 -0
  138. data/lib/project_types/script/forms/enable.rb +24 -0
  139. data/lib/project_types/script/forms/push.rb +19 -0
  140. data/lib/project_types/script/forms/script_form.rb +66 -0
  141. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +27 -0
  142. data/lib/project_types/script/graphql/script_service_proxy.graphql +8 -0
  143. data/lib/project_types/script/graphql/shop_script_delete.graphql +14 -0
  144. data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +28 -0
  145. data/lib/project_types/script/layers/application/build_script.rb +43 -0
  146. data/lib/project_types/script/layers/application/create_script.rb +47 -0
  147. data/lib/project_types/script/layers/application/disable_script.rb +19 -0
  148. data/lib/project_types/script/layers/application/enable_script.rb +21 -0
  149. data/lib/project_types/script/layers/application/extension_points.rb +17 -0
  150. data/lib/project_types/script/layers/application/project_dependencies.rb +34 -0
  151. data/lib/project_types/script/layers/application/push_script.rb +30 -0
  152. data/lib/project_types/script/layers/domain/errors.rb +25 -0
  153. data/lib/project_types/script/layers/domain/extension_point.rb +29 -0
  154. data/lib/project_types/script/layers/domain/push_package.rb +29 -0
  155. data/lib/project_types/script/layers/domain/script.rb +18 -0
  156. data/lib/project_types/script/layers/infrastructure/assemblyscript_dependency_manager.rb +73 -0
  157. data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +38 -0
  158. data/lib/project_types/script/layers/infrastructure/assemblyscript_wasm_builder.rb +39 -0
  159. data/lib/project_types/script/layers/infrastructure/dependency_manager.rb +36 -0
  160. data/lib/project_types/script/layers/infrastructure/errors.rb +38 -0
  161. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +31 -0
  162. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +47 -0
  163. data/lib/project_types/script/layers/infrastructure/script_builder.rb +34 -0
  164. data/lib/project_types/script/layers/infrastructure/script_repository.rb +89 -0
  165. data/lib/project_types/script/layers/infrastructure/script_service.rb +165 -0
  166. data/lib/project_types/script/layers/infrastructure/test_suite_repository.rb +59 -0
  167. data/lib/project_types/script/messages/messages.rb +204 -0
  168. data/lib/project_types/script/script_project.rb +37 -0
  169. data/lib/project_types/script/templates/ts/as-pect.config.js +21 -0
  170. data/lib/project_types/script/ui/error_handler.rb +136 -0
  171. data/lib/project_types/script/ui/strict_spinner.rb +22 -0
  172. data/lib/rubygems_plugin.rb +18 -0
  173. data/lib/shopify-cli/admin_api.rb +99 -0
  174. data/lib/shopify-cli/admin_api/populate_resource_command.rb +165 -0
  175. data/lib/shopify-cli/admin_api/schema.rb +32 -0
  176. data/lib/shopify-cli/api.rb +104 -0
  177. data/lib/shopify-cli/command.rb +67 -0
  178. data/lib/shopify-cli/commands.rb +28 -0
  179. data/lib/shopify-cli/commands/connect.rb +108 -0
  180. data/lib/shopify-cli/commands/create.rb +50 -0
  181. data/lib/shopify-cli/commands/help.rb +79 -0
  182. data/lib/shopify-cli/commands/logout.rb +23 -0
  183. data/lib/shopify-cli/commands/system.rb +135 -0
  184. data/lib/shopify-cli/commands/version.rb +15 -0
  185. data/lib/shopify-cli/context.rb +372 -0
  186. data/lib/shopify-cli/core.rb +9 -0
  187. data/lib/shopify-cli/core/entry_point.rb +40 -0
  188. data/lib/shopify-cli/core/executor.rb +21 -0
  189. data/lib/shopify-cli/core/help_resolver.rb +20 -0
  190. data/lib/shopify-cli/core/monorail.rb +118 -0
  191. data/lib/shopify-cli/db.rb +114 -0
  192. data/lib/shopify-cli/form.rb +40 -0
  193. data/lib/shopify-cli/git.rb +141 -0
  194. data/lib/shopify-cli/helpers.rb +5 -0
  195. data/lib/shopify-cli/helpers/haikunator.rb +92 -0
  196. data/lib/shopify-cli/heroku.rb +97 -0
  197. data/lib/shopify-cli/js_deps.rb +110 -0
  198. data/lib/shopify-cli/js_system.rb +98 -0
  199. data/lib/shopify-cli/messages/messages.rb +287 -0
  200. data/lib/shopify-cli/oauth.rb +192 -0
  201. data/lib/shopify-cli/oauth/servlet.rb +61 -0
  202. data/lib/shopify-cli/options.rb +40 -0
  203. data/lib/shopify-cli/packager.rb +116 -0
  204. data/lib/shopify-cli/partners_api.rb +114 -0
  205. data/lib/shopify-cli/partners_api/organizations.rb +32 -0
  206. data/lib/shopify-cli/process_supervision.rb +187 -0
  207. data/lib/shopify-cli/project.rb +191 -0
  208. data/lib/shopify-cli/project_type.rb +83 -0
  209. data/lib/shopify-cli/resources.rb +5 -0
  210. data/lib/shopify-cli/resources/env_file.rb +96 -0
  211. data/lib/shopify-cli/sub_command.rb +15 -0
  212. data/lib/shopify-cli/task.rb +10 -0
  213. data/lib/shopify-cli/tasks.rb +32 -0
  214. data/lib/shopify-cli/tasks/create_api_client.rb +29 -0
  215. data/lib/shopify-cli/tasks/ensure_dev_store.rb +41 -0
  216. data/lib/shopify-cli/tasks/ensure_env.rb +31 -0
  217. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +20 -0
  218. data/lib/shopify-cli/tasks/update_dashboard_urls.rb +44 -0
  219. data/lib/shopify-cli/tunnel.rb +154 -0
  220. data/lib/shopify-cli/version.rb +3 -0
  221. data/lib/shopify_cli.rb +132 -0
  222. data/shopify-cli.gemspec +40 -0
  223. data/shopify.fish +12 -0
  224. data/shopify.sh +11 -0
  225. data/vendor/deps/cli-kit/REVISION +1 -0
  226. data/vendor/deps/cli-kit/lib/cli/kit.rb +60 -0
  227. data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +21 -0
  228. data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +49 -0
  229. data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +94 -0
  230. data/vendor/deps/cli-kit/lib/cli/kit/config.rb +133 -0
  231. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +115 -0
  232. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +81 -0
  233. data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +102 -0
  234. data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +82 -0
  235. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +76 -0
  236. data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +60 -0
  237. data/vendor/deps/cli-kit/lib/cli/kit/ruby_backports/enumerable.rb +6 -0
  238. data/vendor/deps/cli-kit/lib/cli/kit/support.rb +9 -0
  239. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +244 -0
  240. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +207 -0
  241. data/vendor/deps/cli-kit/lib/cli/kit/util.rb +189 -0
  242. data/vendor/deps/cli-kit/lib/cli/kit/version.rb +5 -0
  243. data/vendor/deps/cli-ui/REVISION +1 -0
  244. data/vendor/deps/cli-ui/lib/cli/ui.rb +187 -0
  245. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +153 -0
  246. data/vendor/deps/cli-ui/lib/cli/ui/box.rb +15 -0
  247. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +79 -0
  248. data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +179 -0
  249. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +310 -0
  250. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +78 -0
  251. data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +88 -0
  252. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +248 -0
  253. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +472 -0
  254. data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +24 -0
  255. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +48 -0
  256. data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +40 -0
  257. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +241 -0
  258. data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +227 -0
  259. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +36 -0
  260. data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +102 -0
  261. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +5 -0
  262. data/vendor/deps/smart_properties/REVISION +1 -0
  263. data/vendor/deps/smart_properties/lib/smart_properties.rb +174 -0
  264. data/vendor/deps/smart_properties/lib/smart_properties/errors.rb +114 -0
  265. data/vendor/deps/smart_properties/lib/smart_properties/property.rb +162 -0
  266. data/vendor/deps/smart_properties/lib/smart_properties/property_collection.rb +83 -0
  267. data/vendor/deps/smart_properties/lib/smart_properties/validations.rb +8 -0
  268. data/vendor/deps/smart_properties/lib/smart_properties/validations/ancestor.rb +27 -0
  269. data/vendor/deps/smart_properties/lib/smart_properties/version.rb +3 -0
  270. data/vendor/lib/semantic/LICENSE +20 -0
  271. data/vendor/lib/semantic/semantic.rb +4 -0
  272. data/vendor/lib/semantic/version.rb +180 -0
  273. metadata +374 -0
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Script
6
+ module Layers
7
+ module Infrastructure
8
+ class TestSuiteRepository
9
+ ASPECT_DTS_FILENAME = "as-pect.d.ts"
10
+ ASPECT_DTS_FILE_CONTENTS = "/// <reference types=\"@as-pect/assembly/types/as-pect\" />"
11
+ BOOTSTRAP_TEST = "npx --no-install shopify-scripts-bootstrap test %{test_base}"
12
+
13
+ def create_test_suite(script)
14
+ # Remove this once we have a test suite for js
15
+ return unless script.language == "ts"
16
+
17
+ FileUtils.mkdir_p(test_base)
18
+ FileUtils.copy(aspect_config_template(script.language), "#{test_base}/as-pect.config.js")
19
+ out, status = CLI::Kit::System.capture2e(format(BOOTSTRAP_TEST, test_base: test_base))
20
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
21
+
22
+ write_tsconfig_file
23
+ write_aspect_type_definitions_file
24
+ end
25
+
26
+ private
27
+
28
+ def test_dir
29
+ "test"
30
+ end
31
+
32
+ def test_base
33
+ "#{ScriptProject.current.directory}/#{test_dir}"
34
+ end
35
+
36
+ def aspect_config_template(language)
37
+ Project.project_filepath("templates/#{language}/as-pect.config.js")
38
+ end
39
+
40
+ def write_tsconfig_file
41
+ AssemblyScriptTsConfig
42
+ .new(dir_to_write_in: test_dir)
43
+ .with_extends_assemblyscript_config(relative_path_to_node_modules: ".")
44
+ .with_module_resolution_paths(paths: { "*": ["#{relative_path_to_source_dir}/*.ts"] })
45
+ .write
46
+ end
47
+
48
+ def relative_path_to_source_dir
49
+ src_path_from_root = ScriptRepository.new.relative_path_to_src
50
+ Pathname.new(src_path_from_root).relative_path_from(test_dir)
51
+ end
52
+
53
+ def write_aspect_type_definitions_file
54
+ File.write("#{test_base}/#{ASPECT_DTS_FILENAME}", ASPECT_DTS_FILE_CONTENTS)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,204 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Messages
5
+ MESSAGES = {
6
+ script: {
7
+ error: {
8
+ generic: "{{red:{{x}} Error}}",
9
+ eacces_cause: "You don't have permission to write to this directory.",
10
+ eacces_help: "Change your directory permissions and try again.",
11
+
12
+ enospc_cause: "You don't have enough disk space to perform this action.",
13
+ enospc_help: "Free up some space and try again.",
14
+
15
+ oauth_cause: "Something went wrong while authenticating your account with the Partner Dashboard.",
16
+ oauth_help: "Try again.",
17
+
18
+ invalid_context_cause: "Your .shopify-cli.yml file is not correct.",
19
+ invalid_context_help: "See https://help.shopify.com",
20
+
21
+ no_existing_apps_cause: "You don't have any apps.",
22
+ no_existing_apps_help: "Please create an app with {{command:shopify create}} or"\
23
+ "visit https://partners.shopify.com/.",
24
+
25
+ no_existing_orgs_cause: "You don't have any partner organizations.",
26
+ no_existing_orgs_help: "Please visit https://partners.shopify.com/ to create a partners account.",
27
+
28
+ no_existing_stores_cause: "You don't have any development stores.",
29
+ no_existing_stores_help: "Visit https://partners.shopify.com/%{organization_id}/stores/ to create one.",
30
+
31
+ project_exists_cause: "Directory with the same name as the script already exists.",
32
+ project_exists_help: "Use different script name and try again.",
33
+
34
+ invalid_extension_cause: "Invalid extension point %s",
35
+ invalid_extension_help: "Allowed values: %s.",
36
+
37
+ script_not_found_cause: "Couldn't find script %s for extension point %s",
38
+
39
+ app_not_installed_cause: "App not installed on development store.",
40
+
41
+ app_script_undefined_help: "Push script to app.",
42
+
43
+ build_error_cause: "Something went wrong while building the script.",
44
+ build_error_help: "Correct the errors and try again.",
45
+
46
+ dependency_install_cause: "Something went wrong while installing the dependencies that are needed.",
47
+ dependency_install_help: "Correct the errors and try again.",
48
+
49
+ forbidden_error_cause: "You do not have permission to do this action.",
50
+
51
+ graphql_error_cause: "An error was returned: %s.",
52
+ graphql_error_help: "\nReview the error and try again.",
53
+
54
+ script_repush_cause: "A script with the same extension point already exists on app (API key: %s).",
55
+ script_repush_help: "Use {{cyan:--force}} to replace the existing script.",
56
+
57
+ shop_auth_cause: "Unable to authenticate with the store.",
58
+ shop_auth_help: "Try again.",
59
+
60
+ shop_script_conflict_cause: "Another app in this store has already enabled a script "\
61
+ "on this extension point.",
62
+ shop_script_conflict_help: "Disable that script or uninstall that app and try again.",
63
+
64
+ shop_script_undefined_cause: "Script is already turned off in development store.",
65
+ },
66
+
67
+ create: {
68
+ help: <<~HELP,
69
+ {{command:%1$s create script}}: Creates a script project.
70
+ Usage: {{command:%1$s create script}}
71
+ HELP
72
+ extended_help: <<~HELP,
73
+ \s\sOptions:
74
+ \s\s{{command:--name=NAME}} Script project name. Use any string.
75
+ \s\s{{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
76
+ HELP
77
+
78
+ error: {
79
+ operation_failed: "Script not created.",
80
+ },
81
+
82
+ script_path: "{{v}} Project directory: {{green:%{folder}}}",
83
+ script_created: "{{v}} Script created: {{green:%{script_id}}}",
84
+ creating: "Creating script",
85
+ created: "Created script",
86
+ },
87
+
88
+ push: {
89
+ help: <<~HELP,
90
+ Build the script and put it into production. If you've already pushed a script with the same extension point, use --force to replace the current script with the newest one.
91
+ Usage: {{command:%s push}}
92
+ HELP
93
+ extended_help: <<~HELP,
94
+ \s\sOptions:
95
+ \s\s{{command:--API_key=<API_key>}} API key. Must be a valid API key, otherwise store access fails.
96
+ \s\s{{command:[--force]}} Forces the script to be overwritten if an instance of it already exists.
97
+ HELP
98
+
99
+ error: {
100
+ operation_failed: "Script not pushed.",
101
+ },
102
+
103
+ script_pushed: "{{v}} Script pushed to app (API key: %{api_key}).",
104
+ },
105
+
106
+ disable: {
107
+ help: <<~HELP,
108
+ Turn off script in development store.
109
+ Usage: {{command:%s disable}}
110
+ HELP
111
+ extended_help: <<~HELP,
112
+ \s\sOptions:
113
+ \s\s{{command:--API_key=<API_key>}} API key. Must be a valid API key, otherwise store access fails.
114
+ \s\s{{command:--shop_domain=<my_store.myshopify.com>}} Test store URL. Must be an existing test store.
115
+ HELP
116
+
117
+ error: {
118
+ operation_failed: "Can't disable script.",
119
+ },
120
+
121
+ script_disabled: "{{v}} Script disabled. Script is turned off in development store.",
122
+ },
123
+
124
+ enable: {
125
+ help: <<~HELP,
126
+ Turn on script in development store.
127
+ Usage: {{command:%s enable}}
128
+ HELP
129
+ extended_help: <<~HELP,
130
+ \s\sOptions:
131
+ \s\s{{command:--API_key=<API_key>}} API key. Must be a valid API key, otherwise store access fails.
132
+ \s\s{{command:--shop_domain=<my_store.myshopify.com>}} Test store URL. Must be an existing test store.
133
+ HELP
134
+
135
+ info: "{{*}} A script always remains enabled until you disable it - even after pushing "\
136
+ "script changes with the same extension point to an app. To disable a script, use "\
137
+ "the 'disable' command.",
138
+
139
+ error: {
140
+ operation_failed: "Can't enable script.",
141
+ },
142
+
143
+ script_enabled: "{{v}} Script enabled. %{type} script %{title} in app (API key: %{api_key}) "\
144
+ "is turned on in development store {{green:%{shop_domain}}}",
145
+ },
146
+
147
+ project_deps: {
148
+ none_required: "{{v}} None required",
149
+ checking_with_npm: "Checking dependencies with npm",
150
+ installing: "Dependencies installing",
151
+ installed: "Missing dependencies installed",
152
+ },
153
+
154
+ test: {
155
+ help: <<~HELP,
156
+ Runs unit tests on your script.
157
+ Usage: {{command:%s test}}
158
+ HELP
159
+
160
+ error: {
161
+ operation_failed: "Tests didn't run or they ran with failures.",
162
+ },
163
+
164
+ running: "Running tests",
165
+ success: "{{v}} Tests finished.",
166
+ },
167
+
168
+ forms: {
169
+ create: {
170
+ select_extension_point: "Which extension point do you want to use?",
171
+ script_name: "Script Name",
172
+
173
+ error: {
174
+ invalid_name: "Invalid script name: replace or remove unsupported characters. Valid "\
175
+ "characters are numbers, letters, spaces, hyphens, or underscores.",
176
+ },
177
+ },
178
+ script_form: {
179
+ ask_app_api_key_default: "Which app do you want this script to belong to?",
180
+ ask_shop_domain_default: "Select a development store",
181
+ fetching_organizations: "{{i}} Fetching partner organizations",
182
+ select_organization: "Select partner organization.",
183
+ using_app: "Using app {{green:%{title} (%{api_key})}}.",
184
+ using_development_store: "Using development store {{green:%{domain}}}",
185
+ using_organization: "Partner organization {{green:%s}}.",
186
+ },
187
+ enable: {
188
+ ask_app_api_key: "Which app is the script pushed to?",
189
+ ask_shop_domain: "Which development store is the app installed on?",
190
+ },
191
+ },
192
+
193
+ application: {
194
+ building: "Building",
195
+ building_script: "Building script",
196
+ built: "Built",
197
+ pushed: "{{v}} Pushed",
198
+ disabled: "{{v}} Disabled",
199
+ enabled: "{{v}} Enabled",
200
+ },
201
+ },
202
+ }.freeze
203
+ end
204
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ class ScriptProject < ShopifyCli::Project
5
+ SUPPORTED_LANGUAGES = %w(ts)
6
+
7
+ attr_reader :extension_point_type, :script_name, :language
8
+
9
+ def initialize(dir)
10
+ super(dir)
11
+ @extension_point_type = lookup_config('extension_point_type')
12
+ @script_name = lookup_config('script_name')
13
+ @language = 'ts'
14
+ end
15
+
16
+ private
17
+
18
+ def lookup_config(key)
19
+ raise Errors::InvalidContextError, key unless config.key?(key)
20
+ config[key]
21
+ end
22
+
23
+ class << self
24
+ def create(dir)
25
+ raise Errors::ScriptProjectAlreadyExistsError, dir if Dir.exist?(dir)
26
+
27
+ FileUtils.mkdir_p(dir)
28
+ Dir.chdir(dir)
29
+ end
30
+
31
+ def cleanup(ctx:, script_name:, root_dir:)
32
+ Dir.chdir(root_dir)
33
+ ctx.rm_r("#{root_dir}/#{script_name}") if Dir.exist?("#{root_dir}/#{script_name}")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module.exports = {
2
+ include: ["**/*.spec.ts"],
3
+ add: ["**/*.include.ts"],
4
+ flags: {
5
+ "--runtime": ["stub"],
6
+ "--lib": ["node_modules","src"]
7
+ },
8
+ disclude: [/node_modules/],
9
+ imports: {},
10
+ performance: {
11
+ enabled: false,
12
+ maxSamples: 10000,
13
+ maxTestRunTime: 5000,
14
+ reportMedian: true,
15
+ reportAverage: true,
16
+ reportStandardDeviation: false,
17
+ reportMax: false,
18
+ reportMin: false,
19
+ },
20
+ outputBinary: false,
21
+ };
@@ -0,0 +1,136 @@
1
+ require 'cli/ui'
2
+
3
+ module Script
4
+ module UI
5
+ module ErrorHandler
6
+ def self.display(failed_op:, cause_of_error:, help_suggestion:)
7
+ $stderr.puts(CLI::UI.fmt(ShopifyCli::Context.message('script.error.generic')))
8
+ full_msg = failed_op ? failed_op.dup : ""
9
+ full_msg << " #{cause_of_error}" if cause_of_error
10
+ full_msg << " #{help_suggestion}" if help_suggestion
11
+ $stderr.puts(CLI::UI.fmt(full_msg.strip))
12
+ end
13
+
14
+ def self.display_and_raise(failed_op: nil, cause_of_error: nil, help_suggestion: nil)
15
+ display(failed_op: failed_op, cause_of_error: cause_of_error, help_suggestion: help_suggestion)
16
+ raise(ShopifyCli::AbortSilent)
17
+ end
18
+
19
+ def self.pretty_print_and_raise(e, failed_op: nil)
20
+ messages = error_messages(e)
21
+ raise e if messages.nil?
22
+ display_and_raise(failed_op: failed_op, **messages)
23
+ end
24
+
25
+ def self.error_messages(e)
26
+ case e
27
+ when Errno::EACCES
28
+ {
29
+ cause_of_error: ShopifyCli::Context.message('script.error.eacces_cause'),
30
+ help_suggestion: ShopifyCli::Context.message('script.error.eacces_help'),
31
+ }
32
+ when Errno::ENOSPC
33
+ {
34
+ cause_of_error: ShopifyCli::Context.message('script.error.enospc_cause'),
35
+ help_suggestion: ShopifyCli::Context.message('script.error.enospc_help'),
36
+ }
37
+ when ShopifyCli::OAuth::Error
38
+ {
39
+ cause_of_error: ShopifyCli::Context.message('script.error.oauth_cause'),
40
+ help_suggestion: ShopifyCli::Context.message('script.error.oauth_help'),
41
+ }
42
+ when Errors::InvalidContextError
43
+ {
44
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_context_cause'),
45
+ help_suggestion: ShopifyCli::Context.message('script.error.invalid_context_help'),
46
+ }
47
+ when Errors::NoExistingAppsError
48
+ {
49
+ cause_of_error: ShopifyCli::Context.message('script.error.no_existing_apps_cause'),
50
+ help_suggestion: ShopifyCli::Context.message('script.error.no_existing_apps_help'),
51
+ }
52
+ when Errors::NoExistingOrganizationsError
53
+ {
54
+ cause_of_error: ShopifyCli::Context.message('script.error.no_existing_orgs_cause'),
55
+ help_suggestion: ShopifyCli::Context.message('script.error.no_existing_orgs_help'),
56
+ }
57
+ when Errors::NoExistingStoresError
58
+ {
59
+ cause_of_error: ShopifyCli::Context.message('script.error.no_existing_stores_cause'),
60
+ help_suggestion: ShopifyCli::Context.message(
61
+ 'script.error.no_existing_stores_help',
62
+ organization_id: e.organization_id
63
+ ),
64
+ }
65
+ when Errors::ScriptProjectAlreadyExistsError
66
+ {
67
+ cause_of_error: ShopifyCli::Context.message('script.error.project_exists_cause'),
68
+ help_suggestion: ShopifyCli::Context.message('script.error.project_exists_help'),
69
+ }
70
+ when Layers::Domain::Errors::InvalidExtensionPointError
71
+ {
72
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_extension_cause', e.type),
73
+ help_suggestion: ShopifyCli::Context.message(
74
+ 'script.error.invalid_extension_help',
75
+ Script::Layers::Application::ExtensionPoints.types.join(', ')
76
+ ),
77
+ }
78
+ when Layers::Domain::Errors::ScriptNotFoundError
79
+ {
80
+ cause_of_error: ShopifyCli::Context.message(
81
+ 'script.error.script_not_found_cause',
82
+ e.script_name,
83
+ e.extension_point_type
84
+ ),
85
+ }
86
+ when Layers::Infrastructure::Errors::AppNotInstalledError
87
+ {
88
+ cause_of_error: ShopifyCli::Context.message('script.error.app_not_installed_cause'),
89
+ }
90
+ when Layers::Infrastructure::Errors::AppScriptUndefinedError
91
+ {
92
+ help_suggestion: ShopifyCli::Context.message('script.error.app_script_undefined_help'),
93
+ }
94
+ when Layers::Infrastructure::Errors::BuildError
95
+ {
96
+ cause_of_error: ShopifyCli::Context.message('script.error.build_error_cause'),
97
+ help_suggestion: ShopifyCli::Context.message('script.error.build_error_help'),
98
+ }
99
+ when Layers::Infrastructure::Errors::DependencyInstallError
100
+ {
101
+ cause_of_error: ShopifyCli::Context.message('script.error.dependency_install_cause'),
102
+ help_suggestion: ShopifyCli::Context.message('script.error.dependency_install_help'),
103
+ }
104
+ when Layers::Infrastructure::Errors::ForbiddenError
105
+ {
106
+ cause_of_error: ShopifyCli::Context.message('script.error.forbidden_error_cause'),
107
+ }
108
+ when Layers::Infrastructure::Errors::GraphqlError
109
+ {
110
+ cause_of_error: ShopifyCli::Context.message('script.error.graphql_error_cause', e.errors.join(', ')),
111
+ help_suggestion: ShopifyCli::Context.message('script.error.graphql_error_help'),
112
+ }
113
+ when Layers::Infrastructure::Errors::ScriptRepushError
114
+ {
115
+ cause_of_error: ShopifyCli::Context.message('script.error.script_repush_cause', e.api_key),
116
+ help_suggestion: ShopifyCli::Context.message('script.error.script_repush_help'),
117
+ }
118
+ when Layers::Infrastructure::Errors::ShopAuthenticationError
119
+ {
120
+ cause_of_error: ShopifyCli::Context.message('script.error.shop_auth_cause'),
121
+ help_suggestion: ShopifyCli::Context.message('script.error.shop_auth_help'),
122
+ }
123
+ when Layers::Infrastructure::Errors::ShopScriptConflictError
124
+ {
125
+ cause_of_error: ShopifyCli::Context.message('script.error.shop_script_conflict_cause'),
126
+ help_suggestion: ShopifyCli::Context.message('script.error.shop_script_conflict_help'),
127
+ }
128
+ when Layers::Infrastructure::Errors::ShopScriptUndefinedError
129
+ {
130
+ cause_of_error: ShopifyCli::Context.message('script.error.shop_script_undefined_cause'),
131
+ }
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end