shopify-cli 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,17 @@
1
+ module Rails
2
+ class Ruby
3
+ include SmartProperties
4
+
5
+ VERSION_STRING = /ruby ([\d\.]+)/
6
+
7
+ property :ctx, accepts: ShopifyCli::Context, required: true
8
+
9
+ class << self
10
+ def version(ctx)
11
+ require 'semantic/semantic'
12
+ out, _ = ctx.capture2('ruby', '-v')
13
+ Semantic::Version.new(VERSION_STRING.match(out)[1])
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ class Project < ShopifyCli::ProjectType
5
+ hidden_project_type
6
+ creator 'Script', 'Script::Commands::Create'
7
+
8
+ register_command('Script::Commands::Push', 'push')
9
+ register_command('Script::Commands::Disable', 'disable')
10
+ register_command('Script::Commands::Enable', 'enable')
11
+
12
+ require Project.project_filepath('messages/messages')
13
+ register_messages(Script::Messages::MESSAGES)
14
+ end
15
+
16
+ # define/autoload project specific Commands
17
+ module Commands
18
+ autoload :Create, Project.project_filepath('commands/create')
19
+ autoload :Push, Project.project_filepath('commands/push')
20
+ autoload :Disable, Project.project_filepath('commands/disable')
21
+ autoload :Enable, Project.project_filepath('commands/enable')
22
+ end
23
+
24
+ # define/autoload project specific Forms
25
+ module Forms
26
+ autoload :Create, Project.project_filepath('forms/create')
27
+ autoload :Push, Project.project_filepath('forms/push')
28
+ autoload :Enable, Project.project_filepath('forms/enable')
29
+ autoload :ScriptForm, Project.project_filepath('forms/script_form')
30
+ end
31
+
32
+ module Layers
33
+ module Application
34
+ autoload :BuildScript, Project.project_filepath('layers/application/build_script')
35
+ autoload :CreateScript, Project.project_filepath('layers/application/create_script')
36
+ autoload :PushScript, Project.project_filepath('layers/application/push_script')
37
+ autoload :DisableScript, Project.project_filepath('layers/application/disable_script')
38
+ autoload :EnableScript, Project.project_filepath('layers/application/enable_script')
39
+ autoload :ExtensionPoints, Project.project_filepath('layers/application/extension_points')
40
+ autoload :ProjectDependencies, Project.project_filepath('layers/application/project_dependencies')
41
+ end
42
+
43
+ module Domain
44
+ autoload :Errors, Project.project_filepath('layers/domain/errors')
45
+ autoload :PushPackage, Project.project_filepath('layers/domain/push_package')
46
+ autoload :ExtensionPoint, Project.project_filepath('layers/domain/extension_point')
47
+ autoload :Script, Project.project_filepath('layers/domain/script')
48
+ end
49
+
50
+ module Infrastructure
51
+ autoload :Errors, Project.project_filepath('layers/infrastructure/errors')
52
+ autoload :AssemblyScriptDependencyManager,
53
+ Project.project_filepath('layers/infrastructure/assemblyscript_dependency_manager')
54
+ autoload :AssemblyScriptTsConfig, Project.project_filepath('layers/infrastructure/assemblyscript_tsconfig')
55
+ autoload :AssemblyScriptWasmBuilder,
56
+ Project.project_filepath('layers/infrastructure/assemblyscript_wasm_builder')
57
+ autoload :DependencyManager, Project.project_filepath('layers/infrastructure/dependency_manager')
58
+ autoload :PushPackageRepository, Project.project_filepath('layers/infrastructure/push_package_repository')
59
+ autoload :ExtensionPointRepository, Project.project_filepath('layers/infrastructure/extension_point_repository')
60
+ autoload :ScriptBuilder, Project.project_filepath('layers/infrastructure/script_builder')
61
+ autoload :ScriptRepository, Project.project_filepath('layers/infrastructure/script_repository')
62
+ autoload :ScriptService, Project.project_filepath('layers/infrastructure/script_service')
63
+ autoload :TestSuiteRepository, Project.project_filepath('layers/infrastructure/test_suite_repository')
64
+ end
65
+ end
66
+
67
+ module UI
68
+ autoload :ErrorHandler, Project.project_filepath('ui/error_handler')
69
+ autoload :StrictSpinner, Project.project_filepath('ui/strict_spinner')
70
+ end
71
+
72
+ autoload :ScriptProject, Project.project_filepath('script_project')
73
+ autoload :Errors, Project.project_filepath('errors')
74
+
75
+ class ScriptProjectError < StandardError; end
76
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Commands
5
+ class Create < ShopifyCli::SubCommand
6
+ options do |parser, flags|
7
+ parser.on('--name=NAME') { |name| flags[:name] = name }
8
+ parser.on('--extension_point=EP_NAME') { |ep_name| flags[:extension_point] = ep_name }
9
+ end
10
+
11
+ def call(args, _name)
12
+ language = 'ts'
13
+ cur_dir = @ctx.root
14
+
15
+ form = Forms::Create.ask(@ctx, args, options.flags)
16
+ return @ctx.puts(self.class.help) if form.nil?
17
+
18
+ unless !form.name.empty? && form.extension_point && ScriptProject::SUPPORTED_LANGUAGES.include?(language)
19
+ return @ctx.puts(self.class.help)
20
+ end
21
+
22
+ script = Layers::Application::CreateScript.call(
23
+ ctx: @ctx,
24
+ language: language,
25
+ script_name: form.name,
26
+ extension_point_type: form.extension_point
27
+ )
28
+ @ctx.puts(@ctx.message('script.create.script_path', folder: script.name))
29
+ @ctx.puts(@ctx.message('script.create.script_created', script_id: File.join(script.name, script.id)))
30
+ rescue StandardError => e
31
+ ScriptProject.cleanup(ctx: @ctx, script_name: form.name, root_dir: cur_dir)
32
+ UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.create.error.operation_failed'))
33
+ end
34
+
35
+ def self.help
36
+ ShopifyCli::Context.message('script.create.help', ShopifyCli::TOOL_NAME)
37
+ end
38
+
39
+ def self.extended_help
40
+ allowed_values = Script::Layers::Application::ExtensionPoints.types.map { |type| "{{cyan:#{type}}}" }
41
+ ShopifyCli::Context.message('script.create.extended_help', ShopifyCli::TOOL_NAME, allowed_values.join(', '))
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Commands
5
+ class Disable < ShopifyCli::Command
6
+ options do |parser, flags|
7
+ parser.on('--api_key=APIKEY') { |t| flags[:api_key] = t }
8
+ parser.on('--shop_domain=MYSHOPIFYDOMAIN') { |t| flags[:shop_domain] = t }
9
+ end
10
+
11
+ def call(args, _name)
12
+ form = Forms::Enable.ask(@ctx, args, options.flags)
13
+ return @ctx.puts(self.class.help) unless form
14
+
15
+ project = ScriptProject.current
16
+ Layers::Application::DisableScript.call(
17
+ ctx: @ctx,
18
+ api_key: form.api_key,
19
+ shop_domain: form.shop_domain,
20
+ extension_point_type: project.extension_point_type
21
+ )
22
+ @ctx.puts(@ctx.message('script.disable.script_disabled'))
23
+ rescue StandardError => e
24
+ UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.disable.error.operation_failed'))
25
+ end
26
+
27
+ def self.help
28
+ ShopifyCli::Context.message('script.disable.help', ShopifyCli::TOOL_NAME)
29
+ end
30
+
31
+ def self.extended_help
32
+ ShopifyCli::Context.message('script.disable.extended_help', ShopifyCli::TOOL_NAME)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Commands
5
+ class Enable < ShopifyCli::Command
6
+ options do |parser, flags|
7
+ parser.on('--api_key=APIKEY') { |t| flags[:api_key] = t }
8
+ parser.on('--shop_domain=MYSHOPIFYDOMAIN') { |t| flags[:shop_domain] = t }
9
+ end
10
+
11
+ def call(args, _name)
12
+ form = Forms::Enable.ask(@ctx, args, options.flags)
13
+ return @ctx.puts(self.class.help) unless form
14
+
15
+ project = ScriptProject.current
16
+
17
+ Layers::Application::EnableScript.call(
18
+ ctx: @ctx,
19
+ api_key: form.api_key,
20
+ shop_domain: form.shop_domain,
21
+ configuration: { entries: [] },
22
+ extension_point_type: project.extension_point_type,
23
+ title: project.script_name
24
+ )
25
+ @ctx.puts(@ctx.message(
26
+ 'script.enable.script_enabled',
27
+ api_key: form.api_key,
28
+ shop_domain: form.shop_domain,
29
+ type: project.extension_point_type.capitalize,
30
+ title: project.script_name
31
+ ))
32
+ @ctx.puts(@ctx.message('script.enable.info'))
33
+ rescue StandardError => e
34
+ UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.enable.error.operation_failed'))
35
+ end
36
+
37
+ def self.help
38
+ ShopifyCli::Context.message('script.enable.help', ShopifyCli::TOOL_NAME)
39
+ end
40
+
41
+ def self.extended_help
42
+ ShopifyCli::Context.message('script.enable.extended_help', ShopifyCli::TOOL_NAME)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Commands
5
+ class Push < ShopifyCli::Command
6
+ options do |parser, flags|
7
+ parser.on('--api_key=APIKEY') { |t| flags[:api_key] = t }
8
+ parser.on('--force') { |t| flags[:force] = t }
9
+ end
10
+
11
+ def call(args, _name)
12
+ form = Forms::Push.ask(@ctx, args, options.flags)
13
+ project = ScriptProject.current
14
+
15
+ return @ctx.puts(self.class.help) unless form && ScriptProject::SUPPORTED_LANGUAGES.include?(project.language)
16
+
17
+ Layers::Application::PushScript.call(
18
+ ctx: @ctx,
19
+ language: project.language,
20
+ extension_point_type: project.extension_point_type,
21
+ script_name: project.script_name,
22
+ api_key: form.api_key,
23
+ force: form.force
24
+ )
25
+ @ctx.puts(@ctx.message('script.push.script_pushed', api_key: form.api_key))
26
+ rescue StandardError => e
27
+ UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.push.error.operation_failed'))
28
+ end
29
+
30
+ def self.help
31
+ ShopifyCli::Context.message('script.push.help', ShopifyCli::TOOL_NAME)
32
+ end
33
+
34
+ def self.extended_help
35
+ ShopifyCli::Context.message('script.push.extended_help', ShopifyCli::TOOL_NAME)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ discount:
2
+ assemblyscript:
3
+ package: "@shopify/extension-point-as-discount"
4
+ version: "^0.2.2"
5
+ sdk-version: "^6.0.0"
6
+ toolchain-version: "^1.1.0"
7
+ unit_limit_per_order:
8
+ assemblyscript:
9
+ package: "@shopify/extension-point-as-unit-limit-per-order"
10
+ version: "^0.1.2"
11
+ sdk-version: "^6.0.0"
12
+ toolchain-version: "^1.1.0"
13
+ payment_filter:
14
+ assemblyscript:
15
+ package: "@shopify/extension-point-as-payment-filter"
16
+ version: "^0.1.2"
17
+ sdk-version: "^6.0.0"
18
+ toolchain-version: "^1.1.0"
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Errors
5
+ class InvalidContextError < ScriptProjectError; end
6
+ class NoExistingAppsError < ScriptProjectError; end
7
+ class NoExistingOrganizationsError < ScriptProjectError; end
8
+ class NoExistingStoresError < ScriptProjectError
9
+ attr_reader :organization_id
10
+ def initialize(organization_id)
11
+ @organization_id = organization_id
12
+ end
13
+ end
14
+ class ScriptProjectAlreadyExistsError < ScriptProjectError; end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Forms
5
+ class Create < ScriptForm
6
+ flag_arguments :extension_point, :name
7
+
8
+ def ask
9
+ self.name = (name || ask_name).downcase.gsub(' ', '_')
10
+ self.extension_point ||= ask_extension_point
11
+ end
12
+
13
+ private
14
+
15
+ def ask_extension_point
16
+ CLI::UI::Prompt.ask(
17
+ @ctx.message('script.forms.create.select_extension_point'),
18
+ options: Script::Layers::Application::ExtensionPoints.types
19
+ )
20
+ end
21
+
22
+ def ask_name
23
+ name = CLI::UI::Prompt.ask(@ctx.message('script.forms.create.script_name'))
24
+ return name if name.match?(/^[0-9A-Za-z _-]*$/)
25
+ @ctx.abort(@ctx.message('script.forms.create.error.invalid_name'))
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Forms
5
+ class Enable < ScriptForm
6
+ flag_arguments :api_key, :shop_domain
7
+
8
+ def ask
9
+ self.api_key ||= ask_api_key
10
+ self.shop_domain ||= ask_shop_domain
11
+ end
12
+
13
+ private
14
+
15
+ def ask_api_key
16
+ ask_app_api_key(organization['apps'], message: ctx.message('script.forms.enable.ask_app_api_key'))
17
+ end
18
+
19
+ def ask_shop_domain
20
+ super(organization, message: ctx.message('script.forms.enable.ask_shop_domain'))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Forms
5
+ class Push < ScriptForm
6
+ flag_arguments :api_key, :force
7
+
8
+ def ask
9
+ self.api_key ||= ask_api_key
10
+ end
11
+
12
+ private
13
+
14
+ def ask_api_key
15
+ ask_app_api_key(organization['apps'])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Forms
5
+ class ScriptForm < ShopifyCli::Form
6
+ protected
7
+
8
+ def organization
9
+ @organization ||= ask_organization
10
+ end
11
+
12
+ def organizations
13
+ return @organizations if defined?(@organizations)
14
+ ctx.puts(ctx.message('script.forms.script_form.fetching_organizations'))
15
+ @organizations = ShopifyCli::PartnersAPI::Organizations.fetch_with_app(ctx)
16
+ end
17
+
18
+ def ask_app_api_key(apps, message: ctx.message('script.forms.script_form.ask_app_api_key_default'))
19
+ if apps.count == 0
20
+ raise Errors::NoExistingAppsError
21
+ elsif apps.count == 1
22
+ ctx.puts(ctx.message(
23
+ 'script.forms.script_form.using_app',
24
+ title: apps.first['title'],
25
+ api_key: apps.first['apiKey']
26
+ ))
27
+ apps.first["apiKey"]
28
+ else
29
+ CLI::UI::Prompt.ask(message) do |handler|
30
+ apps.each { |app| handler.option(app["title"]) { app["apiKey"] } }
31
+ end
32
+ end
33
+ end
34
+
35
+ def ask_organization
36
+ if organizations.count == 0
37
+ raise Errors::NoExistingOrganizationsError
38
+ elsif organizations.count == 1
39
+ org = organizations.first
40
+ ctx.puts(ctx.message('script.forms.script_form.using_organization',
41
+ ctx.message('core.partners_api.org_name_and_id', org['businessName'], org['id'])))
42
+ org
43
+ else
44
+ org_id = CLI::UI::Prompt.ask(ctx.message('script.forms.script_form.select_organization')) do |handler|
45
+ organizations.each do |o|
46
+ handler.option(ctx.message('core.partners_api.org_name_and_id', o['businessName'], o['id'])) { o['id'] }
47
+ end
48
+ end
49
+ organizations.find { |o| o['id'] == org_id }
50
+ end
51
+ end
52
+
53
+ def ask_shop_domain(organization, message: ctx.message('script.forms.script_form.ask_shop_domain_default'))
54
+ if organization['stores'].count == 0
55
+ raise Errors::NoExistingStoresError, organization['id']
56
+ elsif organization['stores'].count == 1
57
+ domain = organization['stores'].first['shopDomain']
58
+ ctx.puts(ctx.message('script.forms.script_form.using_development_store', domain: domain))
59
+ domain
60
+ else
61
+ CLI::UI::Prompt.ask(message, options: organization["stores"].map { |s| s["shopDomain"] })
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end