shopify-cli 2.6.5 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer.json +5 -0
  3. data/.github/DESIGN.md +1 -1
  4. data/.github/ISSUE_TEMPLATE.md +7 -0
  5. data/.gitignore +1 -0
  6. data/.vscode/extensions.json +5 -0
  7. data/.vscode/settings.json +9 -0
  8. data/CHANGELOG.md +42 -4
  9. data/CONTRIBUTING.md +1 -21
  10. data/{Dockerfile → Codespace.dockerfile} +11 -3
  11. data/Gemfile +1 -0
  12. data/Gemfile.lock +6 -4
  13. data/README.md +20 -99
  14. data/Rakefile +27 -0
  15. data/Tests.dockerfile +35 -0
  16. data/assets/logo.png +0 -0
  17. data/dev.yml +0 -3
  18. data/docs/README.md +13 -0
  19. data/docs/contributors/testing.md +27 -0
  20. data/docs/users/installation.md +46 -0
  21. data/{THEMEKIT_MIGRATION.md → docs/users/migrate-from-themekit.md} +1 -1
  22. data/ext/javy/javy.rb +186 -0
  23. data/ext/javy/version +1 -0
  24. data/lib/project_types/extension/cli.rb +7 -3
  25. data/lib/project_types/extension/commands/build.rb +4 -8
  26. data/lib/project_types/extension/commands/create.rb +3 -5
  27. data/lib/project_types/extension/commands/extension_command.rb +1 -1
  28. data/lib/project_types/extension/features/argo.rb +1 -8
  29. data/lib/project_types/extension/features/argo_serve.rb +9 -23
  30. data/lib/project_types/extension/forms/create.rb +1 -1
  31. data/lib/project_types/extension/forms/questions/ask_template.rb +3 -6
  32. data/lib/project_types/extension/messages/messages.rb +1 -2
  33. data/lib/project_types/extension/models/development_server.rb +2 -2
  34. data/lib/project_types/extension/models/development_server_requirements.rb +2 -3
  35. data/lib/project_types/extension/models/server_config/app.rb +13 -0
  36. data/lib/project_types/extension/models/server_config/development.rb +5 -4
  37. data/lib/project_types/extension/models/server_config/development_renderer.rb +1 -1
  38. data/lib/project_types/extension/models/server_config/development_resource.rb +13 -0
  39. data/lib/project_types/extension/models/server_config/extension.rb +4 -0
  40. data/lib/project_types/extension/models/server_config/root.rb +4 -1
  41. data/lib/project_types/extension/tasks/convert_server_config.rb +65 -0
  42. data/lib/project_types/extension/tasks/ensure_resource_url.rb +39 -0
  43. data/lib/project_types/extension/tasks/find_package_from_json.rb +37 -0
  44. data/lib/project_types/extension/tasks/merge_server_config.rb +32 -0
  45. data/lib/project_types/extension/tasks/run_extension_command.rb +11 -10
  46. data/lib/project_types/node/cli.rb +0 -16
  47. data/lib/project_types/node/forms/create.rb +5 -5
  48. data/lib/project_types/node/messages/messages.rb +2 -144
  49. data/lib/project_types/php/cli.rb +0 -11
  50. data/lib/project_types/php/forms/create.rb +5 -6
  51. data/lib/project_types/php/messages/messages.rb +2 -161
  52. data/lib/project_types/rails/cli.rb +0 -16
  53. data/lib/project_types/rails/commands/create.rb +43 -16
  54. data/lib/project_types/rails/forms/create.rb +5 -7
  55. data/lib/project_types/rails/messages/messages.rb +6 -151
  56. data/lib/project_types/script/cli.rb +7 -1
  57. data/lib/project_types/script/commands/create.rb +3 -8
  58. data/lib/project_types/script/commands/javy.rb +29 -0
  59. data/lib/project_types/script/commands/push.rb +3 -2
  60. data/lib/project_types/script/config/extension_points.yml +3 -26
  61. data/lib/project_types/script/errors.rb +0 -18
  62. data/lib/project_types/script/forms/ask_app.rb +32 -0
  63. data/lib/project_types/script/forms/ask_org.rb +30 -0
  64. data/lib/project_types/script/forms/ask_script_uuid.rb +22 -0
  65. data/lib/project_types/script/forms/run_against_shopify_org.rb +14 -0
  66. data/lib/project_types/script/layers/application/build_script.rb +0 -1
  67. data/lib/project_types/script/layers/application/connect_app.rb +73 -0
  68. data/lib/project_types/script/layers/application/create_script.rb +2 -2
  69. data/lib/project_types/script/layers/domain/script_json.rb +1 -1
  70. data/lib/project_types/script/layers/domain/script_project.rb +4 -0
  71. data/lib/project_types/script/layers/infrastructure/api_clients/partners_proxy_api_client.rb +0 -4
  72. data/lib/project_types/script/layers/infrastructure/errors.rb +8 -4
  73. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb +1 -5
  74. data/lib/project_types/script/layers/infrastructure/languages/typescript_task_runner.rb +25 -4
  75. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +3 -4
  76. data/lib/project_types/script/layers/infrastructure/script_service.rb +1 -1
  77. data/lib/project_types/script/messages/messages.rb +16 -20
  78. data/lib/project_types/script/ui/error_handler.rb +1 -32
  79. data/lib/project_types/theme/cli.rb +1 -1
  80. data/lib/project_types/theme/commands/check.rb +1 -1
  81. data/lib/project_types/theme/commands/delete.rb +1 -1
  82. data/lib/project_types/theme/commands/init.rb +1 -1
  83. data/lib/project_types/theme/commands/language_server.rb +1 -1
  84. data/lib/project_types/theme/commands/package.rb +1 -1
  85. data/lib/project_types/theme/commands/publish.rb +1 -1
  86. data/lib/project_types/theme/commands/pull.rb +4 -1
  87. data/lib/project_types/theme/commands/push.rb +7 -2
  88. data/lib/project_types/theme/commands/serve.rb +9 -2
  89. data/lib/project_types/theme/messages/messages.rb +39 -1
  90. data/lib/project_types/theme/ui/sync_progress_bar.rb +2 -2
  91. data/lib/shopify_cli/admin_api/populate_resource_command.rb +1 -1
  92. data/lib/shopify_cli/api.rb +7 -2
  93. data/lib/shopify_cli/app_type_detector.rb +24 -20
  94. data/lib/shopify_cli/command/app_sub_command.rb +10 -0
  95. data/lib/shopify_cli/command/project_command.rb +31 -0
  96. data/lib/shopify_cli/command/sub_command.rb +19 -0
  97. data/lib/shopify_cli/command.rb +7 -2
  98. data/lib/shopify_cli/commands/app/connect.rb +22 -0
  99. data/lib/shopify_cli/commands/app/create/node.rb +36 -0
  100. data/lib/shopify_cli/commands/app/create/php.rb +36 -0
  101. data/lib/shopify_cli/commands/app/create/rails.rb +38 -0
  102. data/lib/shopify_cli/commands/app/create.rb +28 -0
  103. data/lib/shopify_cli/commands/app/deploy.rb +49 -0
  104. data/lib/shopify_cli/commands/app/open.rb +19 -0
  105. data/lib/shopify_cli/commands/app/serve.rb +49 -0
  106. data/lib/shopify_cli/commands/app/tunnel.rb +43 -0
  107. data/lib/shopify_cli/commands/app.rb +29 -0
  108. data/lib/shopify_cli/commands/config.rb +2 -2
  109. data/lib/shopify_cli/commands.rb +1 -0
  110. data/lib/shopify_cli/constants.rb +7 -0
  111. data/lib/shopify_cli/context.rb +9 -0
  112. data/lib/shopify_cli/environment.rb +4 -0
  113. data/lib/shopify_cli/exception_reporter.rb +8 -6
  114. data/lib/shopify_cli/git.rb +12 -1
  115. data/lib/shopify_cli/github/issue_url_generator.rb +19 -0
  116. data/lib/shopify_cli/github.rb +5 -0
  117. data/lib/shopify_cli/identity_auth.rb +18 -0
  118. data/lib/shopify_cli/messages/messages.rb +254 -9
  119. data/lib/shopify_cli/migrator.rb +9 -11
  120. data/lib/shopify_cli/partners_api.rb +1 -8
  121. data/lib/shopify_cli/project.rb +5 -1
  122. data/lib/shopify_cli/project_commands.rb +1 -1
  123. data/lib/shopify_cli/services/app/connect_service.rb +25 -0
  124. data/lib/shopify_cli/services/app/create/node_service.rb +155 -0
  125. data/lib/shopify_cli/services/app/create/php_service.rb +152 -0
  126. data/lib/shopify_cli/services/app/create/rails_service.rb +215 -0
  127. data/lib/shopify_cli/services/app/deploy/heroku/node_service.rb +101 -0
  128. data/lib/shopify_cli/services/app/deploy/heroku/php_service.rb +135 -0
  129. data/lib/shopify_cli/services/app/deploy/heroku/rails_service.rb +120 -0
  130. data/lib/shopify_cli/services/app/open_service.rb +19 -0
  131. data/lib/shopify_cli/services/app/serve/node_service.rb +42 -0
  132. data/lib/shopify_cli/services/app/serve/php_service.rb +46 -0
  133. data/lib/shopify_cli/services/app/serve/rails_service.rb +48 -0
  134. data/lib/shopify_cli/services/app/tunnel/auth_service.rb +21 -0
  135. data/lib/shopify_cli/services/app/tunnel/start_service.rb +20 -0
  136. data/lib/shopify_cli/services/app/tunnel/stop_service.rb +20 -0
  137. data/lib/shopify_cli/services.rb +31 -0
  138. data/lib/shopify_cli/tasks/ensure_authenticated.rb +9 -3
  139. data/lib/shopify_cli/theme/dev_server/local_assets.rb +1 -1
  140. data/lib/shopify_cli/theme/dev_server.rb +35 -17
  141. data/lib/shopify_cli/theme/syncer/error_reporter.rb +45 -0
  142. data/lib/shopify_cli/theme/syncer/operation.rb +56 -0
  143. data/lib/shopify_cli/theme/syncer/standard_reporter.rb +32 -0
  144. data/lib/shopify_cli/theme/syncer.rb +40 -39
  145. data/lib/shopify_cli/theme/theme.rb +31 -19
  146. data/lib/shopify_cli/tunnel.rb +25 -22
  147. data/lib/shopify_cli/version.rb +1 -1
  148. data/lib/shopify_cli.rb +1 -2
  149. data/shopify-cli.gemspec +2 -6
  150. data/shopify-dev +18 -0
  151. data/utilities/constants.rb +7 -0
  152. data/utilities/docker/container.rb +30 -2
  153. data/utilities/docker.rb +3 -2
  154. data/utilities/utilities.rb +1 -0
  155. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +1 -1
  156. metadata +64 -54
  157. data/docs/_config.yml +0 -2
  158. data/docs/app/node/commands/index.md +0 -4
  159. data/docs/app/node/index.md +0 -4
  160. data/docs/app/rails/commands/index.md +0 -4
  161. data/docs/app/rails/index.md +0 -4
  162. data/docs/core/index.md +0 -4
  163. data/docs/getting-started/index.md +0 -4
  164. data/docs/getting-started/install/index.md +0 -4
  165. data/docs/getting-started/migrate/index.md +0 -4
  166. data/docs/getting-started/uninstall/index.md +0 -4
  167. data/docs/getting-started/upgrade/index.md +0 -4
  168. data/docs/help/start-app/index.md +0 -4
  169. data/docs/index.md +0 -4
  170. data/ext/shopify-cli/extconf.rb +0 -60
  171. data/install.sh +0 -7
  172. data/lib/project_types/extension/tasks/converters/server_config_converter.rb +0 -31
  173. data/lib/project_types/extension/tasks/load_server_config.rb +0 -23
  174. data/lib/project_types/node/commands/connect.rb +0 -21
  175. data/lib/project_types/node/commands/create.rb +0 -125
  176. data/lib/project_types/node/commands/deploy/heroku.rb +0 -96
  177. data/lib/project_types/node/commands/deploy.rb +0 -32
  178. data/lib/project_types/node/commands/generate.rb +0 -22
  179. data/lib/project_types/node/commands/open.rb +0 -18
  180. data/lib/project_types/node/commands/serve.rb +0 -45
  181. data/lib/project_types/node/commands/tunnel.rb +0 -41
  182. data/lib/project_types/php/commands/connect.rb +0 -19
  183. data/lib/project_types/php/commands/create.rb +0 -143
  184. data/lib/project_types/php/commands/deploy/heroku.rb +0 -129
  185. data/lib/project_types/php/commands/deploy.rb +0 -32
  186. data/lib/project_types/php/commands/open.rb +0 -16
  187. data/lib/project_types/php/commands/serve.rb +0 -48
  188. data/lib/project_types/php/commands/tunnel.rb +0 -37
  189. data/lib/project_types/rails/commands/connect.rb +0 -21
  190. data/lib/project_types/rails/commands/deploy/heroku.rb +0 -115
  191. data/lib/project_types/rails/commands/deploy.rb +0 -32
  192. data/lib/project_types/rails/commands/generate/webhook.rb +0 -42
  193. data/lib/project_types/rails/commands/generate.rb +0 -60
  194. data/lib/project_types/rails/commands/open.rb +0 -18
  195. data/lib/project_types/rails/commands/serve.rb +0 -51
  196. data/lib/project_types/rails/commands/tunnel.rb +0 -41
  197. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +0 -0
  198. data/lib/project_types/script/tasks/ensure_env.rb +0 -106
  199. data/lib/shopify_cli/sub_command.rb +0 -17
  200. data/shopify.fish +0 -12
  201. data/shopify.sh +0 -11
@@ -0,0 +1,120 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Deploy
5
+ module Heroku
6
+ class RailsService < BaseService
7
+ DB_CHECK_CMD = 'bundle exec rails runner "puts ActiveRecord::Base.connection.adapter_name.downcase"'
8
+
9
+ attr_reader :context
10
+
11
+ def initialize(context:)
12
+ @context = context
13
+ super()
14
+ end
15
+
16
+ def call
17
+ CLI::UI::Frame.open(context.message("core.app.deploy.heroku.rails.db_check.validating")) do
18
+ CLI::UI::Spinner.spin(context.message("core.app.deploy.heroku.rails.db_check.checking")) do |spinner|
19
+ db_type, err = check_db(context)
20
+ context.abort(context.message(err)) unless err.nil?
21
+ spinner.update_title(context.message("core.app.deploy.heroku.rails.db_check.validated", db_type))
22
+ end
23
+ true
24
+ end
25
+
26
+ spin_group = CLI::UI::SpinGroup.new
27
+ heroku_service = ShopifyCLI::Heroku.new(context)
28
+
29
+ spin_group.add(context.message("core.app.deploy.heroku.downloading")) do |spinner|
30
+ heroku_service.download
31
+ spinner.update_title(context.message("core.app.deploy.heroku.downloaded"))
32
+ end
33
+ spin_group.wait
34
+
35
+ spin_group.add(context.message("core.app.deploy.heroku.installing")) do |spinner|
36
+ heroku_service.install
37
+ spinner.update_title(context.message("core.app.deploy.heroku.installed"))
38
+ end
39
+ spin_group.add(context.message("core.app.deploy.heroku.git.checking")) do |spinner|
40
+ ShopifyCLI::Git.init(context)
41
+ spinner.update_title(context.message("core.app.deploy.heroku.git.initialized"))
42
+ end
43
+ spin_group.wait
44
+
45
+ if (account = heroku_service.whoami)
46
+ context.puts(context.message("core.app.deploy.heroku.authenticated_with_account", account))
47
+ else
48
+ CLI::UI::Frame.open(
49
+ context.message("core.app.deploy.heroku.authenticating"),
50
+ success_text: context.message("core.app.deploy.heroku.authenticated")
51
+ ) do
52
+ heroku_service.authenticate
53
+ end
54
+ end
55
+
56
+ if (app_name = heroku_service.app)
57
+ context.puts(context.message("core.app.deploy.heroku.app.selected", app_name))
58
+ else
59
+ app_type = CLI::UI::Prompt.ask(context.message("core.app.deploy.heroku.app.no_apps_found")) do |handler|
60
+ handler.option(context.message("core.app.deploy.heroku.app.create")) { :new }
61
+ handler.option(context.message("core.app.deploy.heroku.app.select")) { :existing }
62
+ end
63
+
64
+ if app_type == :existing
65
+ app_name = CLI::UI::Prompt.ask(context.message("core.app.deploy.heroku.app.name"))
66
+ CLI::UI::Frame.open(
67
+ context.message("core.app.deploy.heroku.app.selecting", app_name),
68
+ success_text: context.message("core.app.deploy.heroku.app.selected", app_name)
69
+ ) do
70
+ heroku_service.select_existing_app(app_name)
71
+ end
72
+ elsif app_type == :new
73
+ CLI::UI::Frame.open(
74
+ context.message("core.app.deploy.heroku.app.creating"),
75
+ success_text: context.message("core.app.deploy.heroku.app.created")
76
+ ) do
77
+ heroku_service.create_new_app
78
+ end
79
+ end
80
+ end
81
+
82
+ branches = ShopifyCLI::Git.branches(context)
83
+ if branches.length == 1
84
+ branch_to_deploy = branches[0]
85
+ context.puts(context.message("core.app.deploy.heroku.git.branch_selected", branch_to_deploy))
86
+ else
87
+ prompt_question = context.message("core.app.deploy.heroku.git.what_branch")
88
+ branch_to_deploy = CLI::UI::Prompt.ask(prompt_question) do |handler|
89
+ branches.each do |branch|
90
+ handler.option(branch) { branch }
91
+ end
92
+ end
93
+ end
94
+
95
+ CLI::UI::Frame.open(
96
+ context.message("core.app.deploy.heroku.deploying"),
97
+ success_text: context.message("core.app.deploy.heroku.deployed")
98
+ ) do
99
+ heroku_service.deploy(branch_to_deploy)
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def check_db(context)
106
+ out, stat = context.capture2e(DB_CHECK_CMD)
107
+ if stat.success? && out.strip == "sqlite"
108
+ ["sqlite", "core.app.deploy.heroku.rails.db_check.sqlite"]
109
+ elsif !stat.success?
110
+ [nil, "core.app.deploy.heroku.rails.db_check.problem"]
111
+ else
112
+ [out.strip, nil]
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,19 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ class OpenService < BaseService
5
+ attr_reader :project, :context
6
+
7
+ def initialize(project:, context:)
8
+ @project = project
9
+ @context = context
10
+ super()
11
+ end
12
+
13
+ def call
14
+ context.open_url!("#{project.env.host}/login?shop=#{project.env.shop}")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Serve
5
+ class NodeService < BaseService
6
+ attr_accessor :host, :port, :context
7
+
8
+ def initialize(host:, port:, context:)
9
+ @host = host
10
+ @port = port
11
+ @context = context
12
+ super()
13
+ end
14
+
15
+ def call
16
+ project = ShopifyCLI::Project.current
17
+ url = host || ShopifyCLI::Tunnel.start(context, port: port)
18
+ raise ShopifyCLI::Abort,
19
+ context.message("core.app.serve.error.host_must_be_https") if url.match(/^https/i).nil?
20
+ project.env.update(context, :host, url)
21
+ ShopifyCLI::Tasks::UpdateDashboardURLS.call(
22
+ context,
23
+ url: url,
24
+ callback_url: "/auth/callback",
25
+ )
26
+
27
+ if project.env.shop
28
+ project_url = "#{project.env.host}/auth?shop=#{project.env.shop}"
29
+ context.puts("\n" + context.message("core.app.serve.open_info", project_url) + "\n")
30
+ end
31
+
32
+ CLI::UI::Frame.open(context.message("core.app.serve.running_server")) do
33
+ env = project.env.to_h
34
+ env["PORT"] = port.to_s
35
+ context.system("npm run dev", env: env)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Serve
5
+ class PHPService < BaseService
6
+ attr_accessor :host, :port, :context
7
+
8
+ def initialize(host:, port:, context:)
9
+ @host = host
10
+ @port = port
11
+ @context = context
12
+ super()
13
+ end
14
+
15
+ def call
16
+ project = ShopifyCLI::Project.current
17
+ url = host || ShopifyCLI::Tunnel.start(context, port: port)
18
+ raise ShopifyCLI::Abort,
19
+ context.message("core.app.serve.error.host_must_be_https") if url.match(/^https/i).nil?
20
+ project.env.update(context, :host, url)
21
+ ShopifyCLI::Tasks::UpdateDashboardURLS.call(
22
+ context,
23
+ url: url,
24
+ callback_url: "/auth/callback",
25
+ )
26
+
27
+ if project.env.shop
28
+ project_url = "#{project.env.host}/login?shop=#{project.env.shop}"
29
+ context.puts("\n" + context.message("core.app.serve.open_info", project_url) + "\n")
30
+ end
31
+
32
+ CLI::UI::Frame.open(context.message("core.app.serve.running_server")) do
33
+ if ShopifyCLI::ProcessSupervision.running?(:npm_watch)
34
+ ShopifyCLI::ProcessSupervision.stop(:npm_watch)
35
+ end
36
+ ShopifyCLI::ProcessSupervision.start(:npm_watch, "npm run watch", force_spawn: true)
37
+
38
+ env = project.env.to_h
39
+ context.system("php", "artisan", "serve", "--port", port.to_s, env: env)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Serve
5
+ class RailsService < BaseService
6
+ attr_accessor :host, :port, :context
7
+
8
+ def initialize(host:, port:, context:)
9
+ @host = host
10
+ @port = port
11
+ @context = context
12
+ super()
13
+ end
14
+
15
+ def call
16
+ project = ShopifyCLI::Project.current
17
+ url = host || ShopifyCLI::Tunnel.start(context, port: port)
18
+ raise ShopifyCLI::Abort,
19
+ context.message("core.app.serve.error.host_must_be_https") if url.match(/^https/i).nil?
20
+ project.env.update(context, :host, url)
21
+ ShopifyCLI::Tasks::UpdateDashboardURLS.call(
22
+ context,
23
+ url: url,
24
+ callback_url: "/auth/shopify/callback",
25
+ )
26
+
27
+ if project.env.shop
28
+ project_url = "#{project.env.host}/login?shop=#{project.env.shop}"
29
+ context.puts("\n" + context.message("core.app.serve.open_info", project_url) + "\n")
30
+ end
31
+
32
+ CLI::UI::Frame.open(context.message("core.app.serve.running_server")) do
33
+ env = ShopifyCLI::Project.current.env.to_h
34
+ env.delete("HOST")
35
+ env["PORT"] = port.to_s
36
+ env["GEM_PATH"] = Rails::Gem.gem_path(context)
37
+ if context.windows?
38
+ context.system("ruby bin\\rails server", env: env)
39
+ else
40
+ context.system("bin/rails server", env: env)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Tunnel
5
+ class AuthService < BaseService
6
+ attr_accessor :context, :token
7
+
8
+ def initialize(token:, context:)
9
+ @context = context
10
+ @token = token
11
+ super()
12
+ end
13
+
14
+ def call
15
+ ShopifyCLI::Tunnel.auth(context, token)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Tunnel
5
+ class StartService < BaseService
6
+ attr_accessor :context
7
+
8
+ def initialize(context:)
9
+ @context = context
10
+ super()
11
+ end
12
+
13
+ def call
14
+ ShopifyCLI::Tunnel.start(context)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ module App
4
+ module Tunnel
5
+ class StopService < BaseService
6
+ attr_accessor :context
7
+
8
+ def initialize(context:)
9
+ @context = context
10
+ super()
11
+ end
12
+
13
+ def call
14
+ ShopifyCLI::Tunnel.stop(context)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,5 +2,36 @@ module ShopifyCLI
2
2
  module Services
3
3
  autoload :BaseService, "shopify_cli/services/base_service"
4
4
  autoload :ReportingService, "shopify_cli/services/reporting_service"
5
+
6
+ module App
7
+ module Serve
8
+ autoload :NodeService, "shopify_cli/services/app/serve/node_service"
9
+ autoload :RailsService, "shopify_cli/services/app/serve/rails_service"
10
+ autoload :PHPService, "shopify_cli/services/app/serve/php_service"
11
+ end
12
+
13
+ module Create
14
+ autoload :NodeService, "shopify_cli/services/app/create/node_service"
15
+ autoload :RailsService, "shopify_cli/services/app/create/rails_service"
16
+ autoload :PHPService, "shopify_cli/services/app/create/php_service"
17
+ end
18
+
19
+ module Deploy
20
+ module Heroku
21
+ autoload :NodeService, "shopify_cli/services/app/deploy/heroku/node_service"
22
+ autoload :RailsService, "shopify_cli/services/app/deploy/heroku/rails_service"
23
+ autoload :PHPService, "shopify_cli/services/app/deploy/heroku/php_service"
24
+ end
25
+ end
26
+
27
+ module Tunnel
28
+ autoload :StartService, "shopify_cli/services/app/tunnel/start_service"
29
+ autoload :StopService, "shopify_cli/services/app/tunnel/stop_service"
30
+ autoload :AuthService, "shopify_cli/services/app/tunnel/auth_service"
31
+ end
32
+
33
+ autoload :ConnectService, "shopify_cli/services/app/connect_service"
34
+ autoload :OpenService, "shopify_cli/services/app/open_service"
35
+ end
5
36
  end
6
37
  end
@@ -4,9 +4,15 @@ module ShopifyCLI
4
4
  module Tasks
5
5
  class EnsureAuthenticated < ShopifyCLI::Task
6
6
  def call(ctx)
7
- ctx.abort(
8
- ctx.message("core.identity_auth.login_prompt", ShopifyCLI::TOOL_NAME)
9
- ) unless ShopifyCLI::IdentityAuth::IDENTITY_ACCESS_TOKENS.all? { |key| ShopifyCLI::DB.exists?(key) }
7
+ return if ShopifyCLI::Environment.acceptance_test?
8
+ unless ShopifyCLI::IdentityAuth.authenticated?
9
+ raise ShopifyCLI::Abort,
10
+ ctx.message("core.identity_auth.login_prompt", ShopifyCLI::TOOL_NAME)
11
+ end
12
+ if ShopifyCLI::IdentityAuth.environment_auth_token?
13
+ ctx.puts(ctx.message("core.identity_auth.token_authentication",
14
+ ShopifyCLI::Constants::EnvironmentVariables::AUTH_TOKEN))
15
+ end
10
16
  end
11
17
  end
12
18
  end
@@ -4,7 +4,7 @@ module ShopifyCLI
4
4
  module Theme
5
5
  module DevServer
6
6
  class LocalAssets
7
- ASSET_REGEX = %r{//cdn.shopify.com/s/.*?/(assets/.+\.(?:css|js))}
7
+ ASSET_REGEX = %r{//cdn\.shopify\.com/s/.+?/(assets/.+?\.(?:css|js))}
8
8
 
9
9
  class FileBody
10
10
  def initialize(path)
@@ -17,10 +17,14 @@ require "pathname"
17
17
  module ShopifyCLI
18
18
  module Theme
19
19
  module DevServer
20
+ # Errors
21
+ Error = Class.new(StandardError)
22
+ AddressBindingError = Class.new(Error)
23
+
20
24
  class << self
21
25
  attr_accessor :ctx
22
26
 
23
- def start(ctx, root, port: 9292, poll: false)
27
+ def start(ctx, root, host: "127.0.0.1", port: 9292, poll: false)
24
28
  @ctx = ctx
25
29
  theme = DevelopmentTheme.new(ctx, root: root)
26
30
  ignore_filter = IgnoreFilter.from_path(root)
@@ -32,6 +36,7 @@ module ShopifyCLI
32
36
  @app = LocalAssets.new(ctx, @app, theme: theme)
33
37
  @app = HotReload.new(ctx, @app, theme: theme, watcher: watcher, ignore_filter: ignore_filter)
34
38
  stopped = false
39
+ address = "http://#{host}:#{port}"
35
40
 
36
41
  theme.ensure_exists!
37
42
 
@@ -40,8 +45,8 @@ module ShopifyCLI
40
45
  stop
41
46
  end
42
47
 
43
- CLI::UI::Frame.open(@ctx.message("theme.serve.serve")) do
44
- ctx.print_task("Syncing theme ##{theme.id} on #{theme.shop}")
48
+ CLI::UI::Frame.open(@ctx.message("theme.serve.viewing_theme")) do
49
+ ctx.print_task(ctx.message("theme.serve.syncing_theme", theme.id, theme.shop))
45
50
  @syncer.start_threads
46
51
  if block_given?
47
52
  yield @syncer
@@ -51,18 +56,9 @@ module ShopifyCLI
51
56
 
52
57
  return if stopped
53
58
 
54
- ctx.puts("")
55
- ctx.puts("Serving #{theme.root}")
56
- ctx.puts("")
57
- ctx.open_url!("http://127.0.0.1:#{port}")
58
- ctx.puts("")
59
- ctx.puts("Customize this theme in the Online Store Editor:")
60
- ctx.puts("{{green:#{theme.editor_url}}}")
61
- ctx.puts("")
62
- ctx.puts("Share this theme preview:")
63
- ctx.puts("{{green:#{theme.preview_url}}}")
64
- ctx.puts("")
65
- ctx.puts("(Use Ctrl-C to stop)")
59
+ ctx.puts(ctx.message("theme.serve.serving", theme.root))
60
+ ctx.open_url!(address)
61
+ ctx.puts(ctx.message("theme.serve.customize_or_preview", theme.editor_url, theme.preview_url))
66
62
  end
67
63
 
68
64
  logger = if ctx.debug?
@@ -74,6 +70,7 @@ module ShopifyCLI
74
70
  watcher.start
75
71
  WebServer.run(
76
72
  @app,
73
+ BindAddress: host,
77
74
  Port: port,
78
75
  Logger: logger,
79
76
  AccessLog: [],
@@ -82,8 +79,11 @@ module ShopifyCLI
82
79
 
83
80
  rescue ShopifyCLI::API::APIRequestForbiddenError,
84
81
  ShopifyCLI::API::APIRequestUnauthorizedError
85
- @ctx.abort("You are not authorized to edit themes on #{theme.shop}.\n" \
86
- "Make sure you are a user of that store, and allowed to edit themes.")
82
+ raise ShopifyCLI::Abort, @ctx.message("theme.serve.ensure_user", theme.shop)
83
+ rescue Errno::EADDRINUSE
84
+ abort_address_already_in_use(address)
85
+ rescue Errno::EADDRNOTAVAIL
86
+ raise AddressBindingError, "Error binding to the address #{host}."
87
87
  end
88
88
 
89
89
  def stop
@@ -92,6 +92,24 @@ module ShopifyCLI
92
92
  @syncer.shutdown
93
93
  WebServer.shutdown
94
94
  end
95
+
96
+ private
97
+
98
+ def abort_address_already_in_use(address)
99
+ open_frame(@ctx.message("theme.serve.already_in_use_error"), color: :red) do
100
+ @ctx.puts(@ctx.message("theme.serve.address_already_in_use", address))
101
+ end
102
+
103
+ open_frame(@ctx.message("theme.serve.try_this"), color: :green) do
104
+ @ctx.puts(@ctx.message("theme.serve.try_port_option"))
105
+ end
106
+
107
+ raise ShopifyCLI::AbortSilent
108
+ end
109
+
110
+ def open_frame(title, color:, &block)
111
+ CLI::UI::Frame.open(title, color: CLI::UI.resolve_color(color), timing: false, &block)
112
+ end
95
113
  end
96
114
  end
97
115
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyCLI
4
+ module Theme
5
+ class Syncer
6
+ ##
7
+ # ShopifyCLI::Theme::Syncer::ErrorReporter allows delaying log of errors,
8
+ # mainly to not break the progress bar.
9
+ #
10
+ class ErrorReporter
11
+ attr_reader :ctx, :delayed_errors
12
+
13
+ def initialize(ctx)
14
+ @ctx = ctx
15
+ @has_any_error = false
16
+ @delay_errors = false
17
+ @delayed_errors = []
18
+ end
19
+
20
+ def disable!
21
+ @delay_errors = true
22
+ end
23
+
24
+ def enable!
25
+ @delay_errors = false
26
+ @delayed_errors.each { |error| report(error) }
27
+ @delayed_errors.clear
28
+ end
29
+
30
+ def report(error_message)
31
+ if @delay_errors
32
+ @delayed_errors << error_message
33
+ else
34
+ @has_any_error = true
35
+ @ctx.error(error_message)
36
+ end
37
+ end
38
+
39
+ def has_any_error?
40
+ @has_any_error
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyCLI
4
+ module Theme
5
+ class Syncer
6
+ class Operation
7
+ attr_accessor :method, :file
8
+
9
+ COLOR_BY_STATUS = {
10
+ error: :red,
11
+ synced: :green,
12
+ fixed: :cyan,
13
+ }
14
+
15
+ def initialize(ctx, method, file)
16
+ @ctx = ctx
17
+ @method = method
18
+ @file = file
19
+ end
20
+
21
+ def to_s
22
+ "#{method} #{file_path}"
23
+ end
24
+
25
+ def as_error_message
26
+ as_message_with(status: :error)
27
+ end
28
+
29
+ def as_synced_message
30
+ as_message_with(status: :synced)
31
+ end
32
+
33
+ def as_fix_message
34
+ as_message_with(status: :fixed)
35
+ end
36
+
37
+ def file_path
38
+ file&.relative_path.to_s
39
+ end
40
+
41
+ private
42
+
43
+ def as_message_with(status:)
44
+ status_color = COLOR_BY_STATUS[status]
45
+ status_text = @ctx.message("theme.serve.operation.status.#{status}").ljust(6)
46
+
47
+ "#{timestamp} {{#{status_color}:#{status_text}}} {{>}} {{blue:#{self}}}"
48
+ end
49
+
50
+ def timestamp
51
+ Time.now.strftime("%T")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyCLI
4
+ module Theme
5
+ class Syncer
6
+ ##
7
+ # ShopifyCLI::Theme::Syncer::StdReporter allows disabling/enabling
8
+ # messages reported in the standard output (ShopifyCLI::Context#puts).
9
+ #
10
+ class StandardReporter
11
+ attr_reader :ctx
12
+
13
+ def initialize(ctx)
14
+ @enabled = true
15
+ @ctx = ctx
16
+ end
17
+
18
+ def disable!
19
+ @enabled = false
20
+ end
21
+
22
+ def enable!
23
+ @enabled = true
24
+ end
25
+
26
+ def report(message)
27
+ ctx.puts(message) if @enabled
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end