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,5 @@
1
+ module ShopifyCli
2
+ module Helpers
3
+ autoload :Haikunator, 'shopify-cli/helpers/haikunator'
4
+ end
5
+ end
@@ -0,0 +1,92 @@
1
+ # Copyright (c) 2015 Usman Bashir
2
+ #
3
+ # MIT License
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require "securerandom"
25
+
26
+ module ShopifyCli
27
+ module Helpers
28
+ module Haikunator
29
+ class << self
30
+ def title
31
+ build(0, ' ')
32
+ end
33
+
34
+ def haikunate(token_range = 9999, delimiter = "-")
35
+ build(token_range, delimiter)
36
+ end
37
+
38
+ def name
39
+ first = nouns[random_seed % nouns.length]
40
+ last = adjectives[random_seed % adjectives.length]
41
+ [first, last]
42
+ end
43
+
44
+ private
45
+
46
+ def build(token_range, delimiter)
47
+ sections = [
48
+ adjectives[random_seed % adjectives.length],
49
+ nouns[random_seed % nouns.length],
50
+ token(token_range),
51
+ ]
52
+
53
+ sections.compact.join(delimiter)
54
+ end
55
+
56
+ def random_seed
57
+ SecureRandom.random_number(4096)
58
+ end
59
+
60
+ def token(range)
61
+ SecureRandom.random_number(range) if range > 0
62
+ end
63
+
64
+ def adjectives
65
+ %w(
66
+ autumn hidden bitter misty silent empty dry dark summer
67
+ icy delicate quiet white cool spring winter patient
68
+ twilight dawn crimson wispy weathered blue billowing
69
+ broken cold damp falling frosty green long late lingering
70
+ bold little morning muddy old red rough still small
71
+ sparkling throbbing shy wandering withered wild black
72
+ young holy solitary fragrant aged snowy proud floral
73
+ restless divine polished ancient purple lively nameless
74
+ )
75
+ end
76
+
77
+ def nouns
78
+ %w(
79
+ waterfall river breeze moon rain wind sea morning
80
+ snow lake sunset pine shadow leaf dawn glitter forest
81
+ hill cloud meadow sun glade bird brook butterfly
82
+ bush dew dust field fire flower firefly feather grass
83
+ haze mountain night pond darkness snowflake silence
84
+ sound sky shape surf thunder violet water wildflower
85
+ wave water resonance sun wood dream cherry tree fog
86
+ frost voice paper frog smoke star
87
+ )
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,97 @@
1
+ module ShopifyCli
2
+ class Heroku
3
+ DOWNLOAD_URLS = {
4
+ linux: 'https://cli-assets.heroku.com/heroku-linux-x64.tar.gz',
5
+ mac: 'https://cli-assets.heroku.com/heroku-darwin-x64.tar.gz',
6
+ windows: 'https://cli-assets.heroku.com/heroku-win32-x64.tar.gz',
7
+ }
8
+
9
+ def initialize(ctx)
10
+ @ctx = ctx
11
+ end
12
+
13
+ def app
14
+ return nil unless (app = git_remote)
15
+ app = app.split('/').last
16
+ app = app.split('.').first
17
+ app
18
+ end
19
+
20
+ def authenticate
21
+ result = @ctx.system(heroku_command, 'login')
22
+ @ctx.abort(@ctx.message('core.heroku.error.authentication')) unless result.success?
23
+ end
24
+
25
+ def create_new_app
26
+ output, status = @ctx.capture2e(heroku_command, 'create')
27
+ @ctx.abort(@ctx.message('core.heroku.error.creation')) unless status.success?
28
+ @ctx.puts(output)
29
+ end
30
+
31
+ def deploy(branch_to_deploy)
32
+ result = @ctx.system('git', 'push', '-u', 'heroku', "#{branch_to_deploy}:master")
33
+ @ctx.abort(@ctx.message('core.heroku.error.deploy')) unless result.success?
34
+ end
35
+
36
+ def download
37
+ return if installed?
38
+
39
+ result = @ctx.system('curl', '-o', download_path, DOWNLOAD_URLS[@ctx.os], chdir: ShopifyCli::CACHE_DIR)
40
+ @ctx.abort(@ctx.message('core.heroku.error.download')) unless result.success?
41
+ @ctx.abort(@ctx.message('core.heroku.error.download')) unless File.exist?(download_path)
42
+ end
43
+
44
+ def install
45
+ return if installed?
46
+
47
+ result = @ctx.system('tar', '-xf', download_path, chdir: ShopifyCli::CACHE_DIR)
48
+ @ctx.abort(@ctx.message('core.heroku.error.install')) unless result.success?
49
+
50
+ @ctx.rm(download_path)
51
+ end
52
+
53
+ def select_existing_app(app_name)
54
+ result = @ctx.system(heroku_command, 'git:remote', '-a', app_name)
55
+
56
+ msg = @ctx.message('core.heroku.error.could_not_select_app', app_name)
57
+ @ctx.abort(msg) unless result.success?
58
+ end
59
+
60
+ def whoami
61
+ output, status = @ctx.capture2e(heroku_command, 'whoami')
62
+ return output.strip if status.success?
63
+ nil
64
+ end
65
+
66
+ private
67
+
68
+ def download_filename
69
+ URI.parse(DOWNLOAD_URLS[@ctx.os]).path.split('/').last
70
+ end
71
+
72
+ def download_path
73
+ File.join(ShopifyCli::CACHE_DIR, download_filename)
74
+ end
75
+
76
+ def git_remote
77
+ output, status = @ctx.capture2e('git', 'remote', 'get-url', 'heroku')
78
+ status.success? ? output : nil
79
+ end
80
+
81
+ def heroku_command
82
+ local_path = File.join(ShopifyCli::CACHE_DIR, 'heroku', 'bin', 'heroku').to_s
83
+ if File.exist?(local_path)
84
+ local_path
85
+ else
86
+ 'heroku'
87
+ end
88
+ end
89
+
90
+ def installed?
91
+ _output, status = @ctx.capture2e(heroku_command, '--version')
92
+ status.success?
93
+ rescue
94
+ false
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,110 @@
1
+ require 'shopify_cli'
2
+
3
+ module ShopifyCli
4
+ ##
5
+ # ShopifyCli::JsDeps ensures that all JavaScript dependencies are installed for projects.
6
+ #
7
+ class JsDeps
8
+ include SmartProperties
9
+
10
+ property! :ctx, accepts: ShopifyCli::Context
11
+ property! :system, accepts: JsSystem, default: -> { JsSystem.new(ctx: ctx) }
12
+
13
+ ##
14
+ # Proxy to instance method ShopifyCli::JsDeps.new.install.
15
+ #
16
+ # #### Parameters
17
+ # - `ctx`: running context from your command
18
+ # - `verbose`: whether to run the installation tools in silent mode
19
+ #
20
+ # #### Example
21
+ #
22
+ # ShopifyCli::JsDeps.install(ctx)
23
+ #
24
+ def self.install(ctx, verbose = false)
25
+ new(ctx: ctx).install(verbose)
26
+ end
27
+
28
+ ##
29
+ # Installs all of a project's JavaScript dependencies using Yarn or NPM, based on the project's settings.
30
+ #
31
+ # #### Parameters
32
+ # - `verbose`: whether to run the installation tools in silent mode
33
+ #
34
+ # #### Example
35
+ #
36
+ # # context is the running context for the command
37
+ # ShopifyCli::JsDeps.new(context).install(true)
38
+ #
39
+ def install(verbose = false)
40
+ title = ctx.message('core.js_deps.installing', @system.package_manager)
41
+ success = ctx.message('core.js_deps.installed')
42
+ failure = ctx.message('core.js_deps.error.install_error', @system.package_manager)
43
+
44
+ CLI::UI::Frame.open(title, success_text: success, failure_text: failure) do
45
+ @system.call(
46
+ yarn: -> { yarn(verbose) },
47
+ npm: -> { npm(verbose) }
48
+ )
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def yarn(verbose = false)
55
+ cmd = %w(yarn install)
56
+ cmd << '--silent' unless verbose
57
+
58
+ run_install_command(cmd)
59
+ end
60
+
61
+ def npm(verbose = false)
62
+ cmd = %w(npm install --no-audit --no-optional)
63
+ cmd << '--quiet' unless verbose
64
+
65
+ run_install_command(cmd)
66
+ end
67
+
68
+ def run_install_command(cmd)
69
+ deps = parse_dependencies
70
+ errors = nil
71
+
72
+ spinner_title = ctx.message('core.js_deps.installing_deps', deps.size)
73
+ success = CLI::UI::Spinner.spin(spinner_title, auto_debrief: false) do |spinner|
74
+ _, errors, status = CLI::Kit::System.capture3(*cmd, env: @ctx.env, chdir: ctx.root)
75
+ update_spinner_title_and_status(spinner, status, deps)
76
+ end
77
+
78
+ errors.lines.each { |e| ctx.puts e } unless success || errors.nil?
79
+ success
80
+ end
81
+
82
+ def update_spinner_title_and_status(spinner, status, deps)
83
+ if status.success?
84
+ spinner.update_title(ctx.message('core.js_deps.installed_deps', deps.size))
85
+ else
86
+ spinner.update_title(ctx.message('core.js_deps.error.install_spinner_error', deps.size))
87
+ CLI::UI::Spinner::TASK_FAILED
88
+ end
89
+ end
90
+
91
+ def parse_dependencies
92
+ package_json = File.join(ctx.root, 'package.json')
93
+ pkg = begin
94
+ JSON.parse(File.read(package_json))
95
+ rescue Errno::ENOENT, Errno::ENOTDIR
96
+ ctx.abort(ctx.message('core.js_deps.error.missing_package', package_json))
97
+ end
98
+
99
+ %w(dependencies devDependencies).map do |key|
100
+ pkg.fetch(key, []).keys
101
+ end.flatten
102
+ rescue JSON::ParserError
103
+ ctx.puts(
104
+ ctx.message('core.js_deps.error.invalid_package', File.read(File.join(path, 'package.json'))),
105
+ error: true
106
+ )
107
+ raise ShopifyCli::AbortSilent
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,98 @@
1
+ require 'shopify_cli'
2
+
3
+ module ShopifyCli
4
+ ##
5
+ # ShopifyCli::JsSystem allows conditional system calls of npm or yarn commands.
6
+ #
7
+ class JsSystem
8
+ include SmartProperties
9
+
10
+ YARN_CORE_COMMAND = 'yarn'
11
+ NPM_CORE_COMMAND = 'npm'
12
+
13
+ class << self
14
+ ##
15
+ # Proxy to instance method `ShopifyCli::JsSystem.new.yarn?`
16
+ #
17
+ # #### Parameters
18
+ # - `ctx`: running context from your command
19
+ #
20
+ # #### Example
21
+ #
22
+ # ShopifyCli::JsSystem.yarn?(ctx)
23
+ #
24
+ def yarn?(ctx)
25
+ JsSystem.new(ctx: ctx).yarn?
26
+ end
27
+
28
+ ##
29
+ # Proxy to instance method `ShopifyCli::JsSystem.new.call`
30
+ #
31
+ # #### Parameters
32
+ # - `ctx`: running context from your command
33
+ # - `yarn`: The proc, array, or string command to run if yarn is available
34
+ # - `npm`: The proc, array, or string command to run if npm is available
35
+ #
36
+ # #### Example
37
+ #
38
+ # ShopifyCli::JsSystem.call(ctx, yarn: ['install', '--silent'], npm: ['install', '--no-audit'])
39
+ #
40
+ def call(ctx, yarn:, npm:)
41
+ JsSystem.new(ctx: ctx).call(yarn: yarn, npm: npm)
42
+ end
43
+ end
44
+
45
+ property :ctx, accepts: ShopifyCli::Context
46
+
47
+ ##
48
+ # Returns the name of the JS package manager being used
49
+ #
50
+ # #### Example
51
+ #
52
+ # ShopifyCli::JsSystem.new(ctx: ctx).package_manager
53
+ #
54
+ def package_manager
55
+ yarn? ? YARN_CORE_COMMAND : NPM_CORE_COMMAND
56
+ end
57
+
58
+ ##
59
+ # Returns true if yarn is available and false otherwise
60
+ #
61
+ # #### Example
62
+ #
63
+ # ShopifyCli::JsSystem.new(ctx: ctx).yarn?
64
+ #
65
+ def yarn?
66
+ @has_yarn ||= begin
67
+ _, status = CLI::Kit::System.capture2('which', 'yarn')
68
+ File.exist?(File.join(ctx.root, 'yarn.lock')) && status.success?
69
+ end
70
+ end
71
+
72
+ ##
73
+ # Runs a command with the proper JS package manager depending on the result of `yarn?`
74
+ #
75
+ # #### Parameters
76
+ # - `ctx`: running context from your command
77
+ # - `yarn`: The proc, array, or string command to run if yarn is available
78
+ # - `npm`: The proc, array, or string command to run if npm is available
79
+ #
80
+ # #### Example
81
+ #
82
+ # ShopifyCli::JsSystem.new(ctx: ctx).call(yarn: ['install', '--silent'], npm: ['install', '--no-audit'])
83
+ #
84
+ def call(yarn:, npm:)
85
+ yarn? ? call_command(yarn, YARN_CORE_COMMAND) : call_command(npm, NPM_CORE_COMMAND)
86
+ end
87
+
88
+ private
89
+
90
+ def call_command(command, core_command)
91
+ if command.is_a?(String) || command.is_a?(Array)
92
+ CLI::Kit::System.system(core_command, *command, chdir: ctx.root).success?
93
+ else
94
+ command.call
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,287 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyCli
4
+ module Messages
5
+ MESSAGES = {
6
+ core: {
7
+ connect: {
8
+ help: <<~HELP,
9
+ Connect (or re-connect) an existing project to a Shopify partner organization and/or a store. Creates or updates the {{green:.env}} file, and creates the {{green:.shopify-cli.yml}} file.
10
+ Usage: {{command:%s connect}}
11
+ HELP
12
+
13
+ production_warning: <<~MESSAGE,
14
+ {{yellow:! Warning: if you have connected to an {{bold:app in production}}, running {{command:serve}} may update the app URL and cause an outage.
15
+ MESSAGE
16
+ already_connected_warning: "{{yellow:! This app appears to be already connected}}",
17
+ connected: "{{v}} Project now connected to {{green:%s}}",
18
+ project_type_select: "What type of project would you like to connect?",
19
+ organization_select: "To which partner organization does this project belong?",
20
+ app_select: "To which app does this project belong?",
21
+ no_development_stores: <<~MESSAGE,
22
+ No development stores available.
23
+ Visit {{underline:https://partners.shopify.com/%d/stores}} to create one
24
+ MESSAGE
25
+ development_store_select: "Which development store would you like to use?",
26
+ cli_yml_saved: ".shopify-cli.yml saved to project root",
27
+ },
28
+
29
+ context: {
30
+ open_url: <<~OPEN,
31
+ Please open this URL in your browser:
32
+ {{green:%s}}
33
+ OPEN
34
+ },
35
+
36
+ create: {
37
+ help: <<~HELP,
38
+ Create a new project.
39
+ Usage: {{command:%s create [ %s ]}}
40
+ HELP
41
+
42
+ error: {
43
+ invalid_app_type: "{{red:Error}}: invalid app type {{bold:%s}}",
44
+ },
45
+
46
+ project_type_select: "What type of project would you like to create?",
47
+ },
48
+
49
+ env_file: {
50
+ saving_header: "writing %s file...",
51
+ saving: "writing %s file",
52
+ saved: "%s saved to project root",
53
+ },
54
+
55
+ git: {
56
+ error: {
57
+ directory_exists: "Project directory already exists. Please create a project with a new name.",
58
+ no_branches_found: "Could not find any git branches",
59
+ repo_not_initiated: "Git repo is not initiated. Please run `git init` and make at least one commit.",
60
+ no_commits_made: "No git commits have been made. Please make at least one commit.",
61
+ },
62
+
63
+ cloning: "Cloning into %s...",
64
+ cloned: "Cloned into %s",
65
+ },
66
+
67
+ help: {
68
+ error: {
69
+ command_not_found: "Command %s not found.",
70
+ },
71
+
72
+ preamble: <<~MESSAGE,
73
+ Use {{command:%s help <command>}} to display detailed information about a specific command.
74
+
75
+ {{bold:Available core commands:}}
76
+
77
+ MESSAGE
78
+ },
79
+
80
+ heroku: {
81
+ error: {
82
+ authentication: "Could not authenticate with Heroku",
83
+ creation: "Heroku app could not be created",
84
+ deploy: "Could not deploy to Heroku",
85
+ download: "Heroku CLI could not be downloaded",
86
+ install: "Could not install Heroku CLI",
87
+ could_not_select_app: "Heroku app `%s` could not be selected",
88
+ },
89
+ },
90
+
91
+ js_deps: {
92
+ error: {
93
+ missing_package: "expected to have a file at: %s",
94
+ invalid_package: "{{info:%s}} was not valid JSON. Fix this then try again",
95
+ install_spinner_error: "Unable to install all %d dependencies",
96
+ install_error: 'An error occurred while installing dependencies',
97
+ },
98
+
99
+ installing: "Installing dependencies with %s...",
100
+ installed: "Dependencies installed",
101
+ npm_installing_deps: "Installing %d dependencies...",
102
+ npm_installed_deps: "%d npm dependencies installed",
103
+ },
104
+
105
+ logout: {
106
+ help: <<~HELP,
107
+ Log out of a currently authenticated partner organization and store, or clear invalid credentials
108
+ Usage: {{command:%s logout}}
109
+ HELP
110
+
111
+ success: "Logged out of partner organization and store",
112
+ },
113
+
114
+ monorail: {
115
+ consent_prompt: <<~MSG,
116
+ Would you like to enable anonymous usage reporting?
117
+ If you select “Yes”, we’ll collect data about which commands you use and which errors you encounter.
118
+ Sharing this anonymous data helps Shopify improve this tool.
119
+ MSG
120
+ },
121
+
122
+ oauth: {
123
+ error: {
124
+ timeout: "Timed out while waiting for response from Shopify",
125
+ },
126
+
127
+ location: {
128
+ admin: "development store",
129
+ partner: "Shopify Partners account",
130
+ },
131
+ authentication_required:
132
+ "{{i}} Authentication required. Login to the URL below with your %s credentials to continue.",
133
+
134
+ servlet: {
135
+ success_response: "Authenticated successfully. You may now close this page.",
136
+ invalid_request_response: "Invalid request: %s",
137
+ invalid_state_response: "Anti-forgery state token does not match the initial request.",
138
+ authenticated: "Authenticated successfully",
139
+ not_authenticated: "Failed to authenticate",
140
+ },
141
+ },
142
+
143
+ options: {
144
+ help_text: "Print help for command",
145
+ },
146
+
147
+ partners_api: {
148
+ org_name_and_id: "%s (%s)",
149
+ error: {
150
+ account_not_found: <<~MESSAGE,
151
+ {{x}} error: Your account was not found. Please sign up at https://partners.shopify.com/signup
152
+ For authentication issues, run {{command:%s logout}} to clear invalid credentials
153
+ MESSAGE
154
+ },
155
+ },
156
+
157
+ populate: {
158
+ options: {
159
+ header: "{{bold:{{cyan:%s}} options:}}",
160
+ count_help: "Number of resources to generate",
161
+ },
162
+ populating: "Populating %d %ss...",
163
+ completion_message: <<~COMPLETION_MESSAGE,
164
+ Successfully added %d %s to {{green:%s}}
165
+ {{*}} View all %ss at {{underline:%s%ss}}
166
+ COMPLETION_MESSAGE
167
+ },
168
+
169
+ project: {
170
+ error: {
171
+ not_in_project: <<~MESSAGE,
172
+ {{x}} You are not in a Shopify app project
173
+ {{yellow:{{*}}}}{{reset: Run}}{{cyan: shopify create}}{{reset: to create your app}}
174
+ MESSAGE
175
+ cli_yaml: {
176
+ not_hash: "{{x}} .shopify-cli.yml was not a proper YAML file. Expecting a hash.",
177
+ invalid: "{{x}} %s contains invalid YAML: %s",
178
+ not_found: "{{x}} %s not found",
179
+ },
180
+ },
181
+ },
182
+
183
+ project_type: {
184
+ error: {
185
+ cannot_override_core: "Can't register duplicate core command '%s' from %s",
186
+ },
187
+ },
188
+
189
+ system: {
190
+ help: <<~HELP,
191
+ Print details about the development system.
192
+ Usage: {{command:%s system [all]}}
193
+
194
+ {{cyan:all}}: displays more details about development system and environment
195
+
196
+ HELP
197
+
198
+ error: {
199
+ unknown_option: "{{x}} {{red:unknown option '%s'}}",
200
+ },
201
+
202
+ header: "{{bold:Shopify App CLI}}",
203
+ const: "%17s = %s",
204
+ ruby_header: <<~RUBY_MESSAGE,
205
+ {{bold:Ruby (via RbConfig)}}
206
+ %s
207
+ RUBY_MESSAGE
208
+ rb_config: "%-25s - RbConfig[\"%s\"]",
209
+ command_header: "{{bold:Commands}}",
210
+ command_with_path: "{{v}} %s, %s",
211
+ command_not_found: "{{x}} %s",
212
+ ngrok_available: "{{v}} ngrok, %s",
213
+ ngrok_not_available: "{{x}} ngrok NOT available",
214
+ project: {
215
+ header: "{{bold:In a {{cyan:%s}} project directory}}",
216
+ command_with_path: "{{v}} %s, %s, version %s",
217
+ command_not_found: "{{x}} %s",
218
+ env_header: "{{bold:Project environment}}",
219
+ env_not_set: "not set",
220
+ env: "%-18s = %s",
221
+ no_env: "{{x}} .env file not present",
222
+ },
223
+ environment_header: "{{bold:Environment}}",
224
+ env: "%-17s = %s",
225
+ },
226
+
227
+ tasks: {
228
+ ensure_env: {
229
+ api_key_question: "What is your Shopify API key?",
230
+ api_secret_key_question: "What is your Shopify API secret key?",
231
+ development_store_question: "What is your development store URL? (Example: my-dev-store.myshopify.com)",
232
+ },
233
+ ensure_dev_store: {
234
+ could_not_verify_store: "Couldn't verify your store %s",
235
+ convert_to_dev_store: <<~MESSAGE,
236
+ Do you want to convert %s to a development store?
237
+ Doing this will allow you to install your app, but the store will become {{bold:transfer-disabled}}.
238
+ Learn more: https://shopify.dev/tutorials/transfer-a-development-store-to-a-merchant#transfer-disabled-stores
239
+ MESSAGE
240
+ transfer_disabled: "{{v}} Transfer has been disabled on %s.",
241
+ },
242
+ update_dashboard_urls: {
243
+ updated: "{{v}} Whitelist URLS updated in Partners Dashboard}}",
244
+ update_error:
245
+ "{{x}} error: For authentication issues, run {{command:%s logout}} to clear invalid credentials",
246
+ update_prompt: "Do you want to update your application url?",
247
+ },
248
+ },
249
+
250
+ tunnel: {
251
+ error: {
252
+ stop: "ngrok tunnel could not be stopped. Try running {{command:killall -9 ngrok}}",
253
+ url_fetch_failure: "Unable to fetch external url",
254
+ },
255
+
256
+ stopped: "{{green:x}} ngrok tunnel stopped",
257
+ not_running: "{{green:x}} ngrok tunnel not running",
258
+ start_with_account: "{{v}} ngrok tunnel running at {{underline:%s}}, with account %s",
259
+ start: "{{v}} ngrok tunnel running at {{underline:%s}}",
260
+ },
261
+
262
+ version: {
263
+ help: <<~HELP,
264
+ Prints version number.
265
+ Usage: {{command:%s version}}
266
+ HELP
267
+ },
268
+
269
+ warning: {
270
+ development_version: <<~DEVELOPMENT,
271
+ {{*}} {{yellow:You are running a development version of the CLI at:}}
272
+ {{yellow:%s}}
273
+
274
+ DEVELOPMENT
275
+
276
+ shell_shim: <<~MESSAGE,
277
+ {{x}} This version of Shopify App CLI is no longer supported. You’ll need to migrate to the new CLI version to continue.
278
+
279
+ Please visit this page for complete instructions:
280
+ {{underline:https://shopify.github.io/shopify-app-cli/migrate/}}
281
+
282
+ MESSAGE
283
+ },
284
+ },
285
+ }.freeze
286
+ end
287
+ end