shopify-cli 1.11.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/CONTRIBUTING.md +7 -7
  4. data/.github/DESIGN.md +3 -3
  5. data/.github/PULL_REQUEST_TEMPLATE.md +1 -1
  6. data/.github/workflows/build.yml +1 -1
  7. data/.gitignore +3 -0
  8. data/.rubocop.yml +3 -1
  9. data/.ruby-version +1 -1
  10. data/CHANGELOG.md +48 -20
  11. data/Gemfile +4 -0
  12. data/Gemfile.lock +32 -0
  13. data/LICENSE +4 -1
  14. data/README.md +92 -26
  15. data/RELEASING.md +29 -7
  16. data/Rakefile +2 -2
  17. data/SECURITY.md +1 -1
  18. data/bin/load_shopify.rb +1 -1
  19. data/bin/shopify +3 -3
  20. data/dev.yml +1 -1
  21. data/docs/app/node/index.md +1 -1
  22. data/docs/app/rails/index.md +1 -1
  23. data/docs/core/index.md +1 -1
  24. data/docs/getting-started/index.md +1 -1
  25. data/docs/getting-started/install/index.md +1 -1
  26. data/docs/getting-started/migrate/index.md +1 -1
  27. data/docs/getting-started/uninstall/index.md +1 -1
  28. data/docs/getting-started/upgrade/index.md +1 -1
  29. data/docs/help/start-app/index.md +1 -1
  30. data/docs/index.md +1 -1
  31. data/ext/shopify-cli/extconf.rb +17 -5
  32. data/install.sh +1 -1
  33. data/lib/docgen/index_template.md.erb +2 -2
  34. data/lib/graphql/all_orgs_with_extensions.graphql +37 -0
  35. data/lib/graphql/find_organization.graphql +2 -1
  36. data/lib/project_types/extension/cli.rb +18 -15
  37. data/lib/project_types/extension/commands/build.rb +4 -5
  38. data/lib/project_types/extension/commands/connect.rb +35 -0
  39. data/lib/project_types/extension/commands/create.rb +12 -16
  40. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  41. data/lib/project_types/extension/commands/info.rb +86 -0
  42. data/lib/project_types/extension/commands/push.rb +8 -7
  43. data/lib/project_types/extension/commands/register.rb +4 -5
  44. data/lib/project_types/extension/commands/serve.rb +5 -8
  45. data/lib/project_types/extension/commands/tunnel.rb +3 -1
  46. data/lib/project_types/extension/errors.rb +9 -0
  47. data/lib/project_types/extension/extension_project.rb +5 -0
  48. data/lib/project_types/extension/features/argo.rb +6 -6
  49. data/lib/project_types/extension/features/argo_runtime.rb +22 -38
  50. data/lib/project_types/extension/features/argo_serve.rb +25 -20
  51. data/lib/project_types/extension/forms/connect.rb +42 -0
  52. data/lib/project_types/extension/forms/questions/ask_name.rb +14 -6
  53. data/lib/project_types/extension/forms/questions/ask_registration.rb +51 -0
  54. data/lib/project_types/extension/messages/messages.rb +75 -11
  55. data/lib/project_types/extension/models/specification.rb +1 -0
  56. data/lib/project_types/extension/models/specification_handlers/{checkout_argo_extension.rb → checkout_ui_extension.rb} +3 -1
  57. data/lib/project_types/extension/models/specification_handlers/default.rb +21 -6
  58. data/lib/project_types/extension/models/specification_handlers/theme_app_extension.rb +86 -0
  59. data/lib/project_types/extension/models/specifications.rb +1 -0
  60. data/lib/project_types/extension/tasks/configure_features.rb +6 -7
  61. data/lib/project_types/extension/tasks/configure_options.rb +20 -0
  62. data/lib/project_types/extension/tasks/get_extensions.rb +32 -0
  63. data/lib/project_types/node/cli.rb +9 -21
  64. data/lib/project_types/node/commands/connect.rb +8 -2
  65. data/lib/project_types/node/commands/create.rb +9 -5
  66. data/lib/project_types/node/commands/deploy.rb +15 -5
  67. data/lib/project_types/node/commands/deploy/heroku.rb +29 -29
  68. data/lib/project_types/node/commands/generate.rb +4 -2
  69. data/lib/project_types/node/commands/open.rb +4 -2
  70. data/lib/project_types/node/commands/serve.rb +3 -2
  71. data/lib/project_types/node/commands/tunnel.rb +4 -2
  72. data/lib/project_types/node/messages/messages.rb +46 -89
  73. data/lib/project_types/rails/cli.rb +9 -21
  74. data/lib/project_types/rails/commands/connect.rb +8 -2
  75. data/lib/project_types/rails/commands/create.rb +10 -6
  76. data/lib/project_types/rails/commands/deploy.rb +15 -5
  77. data/lib/project_types/rails/commands/deploy/heroku.rb +84 -82
  78. data/lib/project_types/rails/commands/generate.rb +15 -5
  79. data/lib/project_types/rails/commands/generate/webhook.rb +28 -26
  80. data/lib/project_types/rails/commands/open.rb +4 -2
  81. data/lib/project_types/rails/commands/serve.rb +3 -2
  82. data/lib/project_types/rails/commands/tunnel.rb +4 -2
  83. data/lib/project_types/rails/messages/messages.rb +54 -101
  84. data/lib/project_types/script/cli.rb +18 -20
  85. data/lib/project_types/script/commands/create.rb +3 -1
  86. data/lib/project_types/script/commands/push.rb +12 -5
  87. data/lib/project_types/script/config/extension_points.yml +0 -3
  88. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +9 -3
  89. data/lib/project_types/script/layers/application/create_script.rb +6 -5
  90. data/lib/project_types/script/layers/application/push_script.rb +2 -1
  91. data/lib/project_types/script/layers/domain/errors.rb +6 -11
  92. data/lib/project_types/script/layers/domain/push_package.rb +4 -8
  93. data/lib/project_types/script/layers/domain/script_json.rb +32 -0
  94. data/lib/project_types/script/layers/domain/script_project.rb +1 -1
  95. data/lib/project_types/script/layers/infrastructure/errors.rb +14 -18
  96. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_project_creator.rb +105 -0
  97. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb +103 -0
  98. data/lib/project_types/script/layers/infrastructure/languages/project_creator.rb +26 -0
  99. data/lib/project_types/script/layers/infrastructure/languages/rust_project_creator.rb +73 -0
  100. data/lib/project_types/script/layers/infrastructure/languages/rust_task_runner.rb +60 -0
  101. data/lib/project_types/script/layers/infrastructure/languages/task_runner.rb +21 -0
  102. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +2 -4
  103. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +45 -34
  104. data/lib/project_types/script/layers/infrastructure/script_service.rb +20 -14
  105. data/lib/project_types/script/messages/messages.rb +66 -55
  106. data/lib/project_types/script/tasks/ensure_env.rb +22 -1
  107. data/lib/project_types/script/ui/error_handler.rb +32 -32
  108. data/lib/project_types/theme/cli.rb +15 -27
  109. data/lib/project_types/theme/commands/check.rb +33 -0
  110. data/lib/project_types/theme/commands/delete.rb +64 -0
  111. data/lib/project_types/theme/commands/language_server.rb +16 -0
  112. data/lib/project_types/theme/commands/package.rb +55 -0
  113. data/lib/project_types/theme/commands/publish.rb +43 -0
  114. data/lib/project_types/theme/commands/pull.rb +51 -0
  115. data/lib/project_types/theme/commands/push.rb +58 -32
  116. data/lib/project_types/theme/commands/serve.rb +7 -17
  117. data/lib/project_types/theme/forms/confirm_store.rb +15 -0
  118. data/lib/project_types/theme/forms/select.rb +59 -0
  119. data/lib/project_types/theme/messages/messages.rb +110 -106
  120. data/lib/project_types/theme/ui/sync_progress_bar.rb +20 -0
  121. data/lib/shopify-cli/admin_api.rb +53 -35
  122. data/lib/shopify-cli/admin_api/populate_resource_command.rb +6 -14
  123. data/lib/shopify-cli/admin_api/schema.rb +1 -10
  124. data/lib/shopify-cli/api.rb +29 -14
  125. data/lib/shopify-cli/command.rb +15 -3
  126. data/lib/shopify-cli/commands.rb +7 -2
  127. data/lib/shopify-cli/commands/help.rb +2 -29
  128. data/lib/shopify-cli/commands/login.rb +95 -0
  129. data/lib/shopify-cli/commands/logout.rb +24 -8
  130. data/lib/shopify-cli/commands/populate.rb +23 -0
  131. data/lib/{project_types/node → shopify-cli}/commands/populate/customer.rb +2 -8
  132. data/lib/{project_types/node → shopify-cli}/commands/populate/draft_order.rb +2 -2
  133. data/lib/{project_types/node → shopify-cli}/commands/populate/product.rb +2 -8
  134. data/lib/shopify-cli/commands/store.rb +15 -0
  135. data/lib/shopify-cli/commands/switch.rb +39 -0
  136. data/lib/shopify-cli/commands/system.rb +12 -0
  137. data/lib/shopify-cli/commands/whoami.rb +28 -0
  138. data/lib/shopify-cli/connect.rb +32 -0
  139. data/lib/shopify-cli/context.rb +65 -4
  140. data/lib/shopify-cli/core/entry_point.rb +3 -22
  141. data/lib/shopify-cli/db.rb +4 -4
  142. data/lib/shopify-cli/http_request.rb +10 -0
  143. data/lib/shopify-cli/identity_auth.rb +282 -0
  144. data/lib/shopify-cli/{oauth → identity_auth}/servlet.rb +11 -12
  145. data/lib/shopify-cli/messages/messages.rb +133 -39
  146. data/lib/shopify-cli/partners_api.rb +21 -41
  147. data/lib/shopify-cli/partners_api/organizations.rb +8 -0
  148. data/lib/shopify-cli/project_commands.rb +16 -0
  149. data/lib/shopify-cli/project_type.rb +0 -31
  150. data/lib/shopify-cli/resources/env_file.rb +1 -1
  151. data/lib/shopify-cli/shopifolk.rb +8 -11
  152. data/lib/shopify-cli/sub_command.rb +1 -0
  153. data/lib/shopify-cli/tasks.rb +3 -0
  154. data/lib/shopify-cli/tasks/confirm_store.rb +18 -0
  155. data/lib/shopify-cli/tasks/create_api_client.rb +2 -2
  156. data/lib/shopify-cli/tasks/ensure_authenticated.rb +13 -0
  157. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +1 -1
  158. data/lib/shopify-cli/tasks/ensure_project_type.rb +12 -0
  159. data/lib/shopify-cli/tasks/select_org_and_shop.rb +0 -3
  160. data/lib/shopify-cli/theme/dev_server.rb +98 -0
  161. data/lib/shopify-cli/theme/dev_server/certificate_manager.rb +79 -0
  162. data/lib/shopify-cli/theme/dev_server/header_hash.rb +94 -0
  163. data/lib/shopify-cli/theme/dev_server/hot-reload.js +93 -0
  164. data/lib/shopify-cli/theme/dev_server/hot_reload.rb +76 -0
  165. data/lib/shopify-cli/theme/dev_server/local_assets.rb +87 -0
  166. data/lib/shopify-cli/theme/dev_server/proxy.rb +205 -0
  167. data/lib/shopify-cli/theme/dev_server/sse.rb +75 -0
  168. data/lib/shopify-cli/theme/dev_server/watcher.rb +59 -0
  169. data/lib/shopify-cli/theme/dev_server/web_server.rb +140 -0
  170. data/lib/shopify-cli/theme/development_theme.rb +69 -0
  171. data/lib/shopify-cli/theme/file.rb +112 -0
  172. data/lib/shopify-cli/theme/ignore_filter.rb +109 -0
  173. data/lib/shopify-cli/theme/mime_type.rb +34 -0
  174. data/lib/shopify-cli/theme/syncer.rb +328 -0
  175. data/lib/shopify-cli/theme/theme.rb +204 -0
  176. data/lib/shopify-cli/version.rb +1 -1
  177. data/lib/shopify_cli.rb +18 -11
  178. data/shopify-cli.gemspec +12 -5
  179. data/shopify.fish +1 -1
  180. data/shopify.sh +1 -1
  181. metadata +95 -41
  182. data/.github/workflows/release.yml +0 -61
  183. data/lib/project_types/extension/features/argo_serve_options.rb +0 -40
  184. data/lib/project_types/node/commands/populate.rb +0 -23
  185. data/lib/project_types/rails/commands/populate.rb +0 -23
  186. data/lib/project_types/rails/commands/populate/customer.rb +0 -31
  187. data/lib/project_types/rails/commands/populate/draft_order.rb +0 -28
  188. data/lib/project_types/rails/commands/populate/product.rb +0 -30
  189. data/lib/project_types/script/layers/domain/config_ui.rb +0 -16
  190. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +0 -95
  191. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +0 -101
  192. data/lib/project_types/script/layers/infrastructure/project_creator.rb +0 -24
  193. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +0 -71
  194. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +0 -58
  195. data/lib/project_types/script/layers/infrastructure/task_runner.rb +0 -19
  196. data/lib/project_types/theme/commands/connect.rb +0 -54
  197. data/lib/project_types/theme/commands/create.rb +0 -48
  198. data/lib/project_types/theme/commands/deploy.rb +0 -38
  199. data/lib/project_types/theme/commands/generate.rb +0 -20
  200. data/lib/project_types/theme/commands/generate/env.rb +0 -79
  201. data/lib/project_types/theme/forms/connect.rb +0 -34
  202. data/lib/project_types/theme/forms/create.rb +0 -22
  203. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +0 -78
  204. data/lib/project_types/theme/themekit.rb +0 -113
  205. data/lib/shopify-cli/commands/connect.rb +0 -64
  206. data/lib/shopify-cli/commands/create.rb +0 -50
  207. data/lib/shopify-cli/oauth.rb +0 -198
@@ -1,61 +0,0 @@
1
- name: Create Release
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*'
7
-
8
- jobs:
9
- create-release:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Extract tag name
13
- id: tag
14
- run: echo "::set-output name=value::${GITHUB_REF##*/}"
15
- - uses: actions/checkout@v2
16
-
17
- - name: Set up Ruby
18
- uses: actions/setup-ruby@v1.1.2
19
- with:
20
- ruby-version: 2.6
21
-
22
- - name: Install dependencies
23
- run: bundle install
24
-
25
- - name: Create package
26
- run: bundle exec rake package
27
-
28
- - name: Get Directory
29
- id: folder
30
- run: |
31
- cd packaging/builds
32
- echo ::set-output name=name::$(ls)
33
-
34
- - name: Get Packages
35
- id: binaries
36
- run: |
37
- cd packaging/builds/${{ steps.folder.outputs.name }}
38
- deb=$(find . -type f -name '*.deb')
39
- rpm=$(find . -type f -name "*.rpm")
40
- echo ::set-output name=deb_file::"${deb:2}"
41
- echo ::set-output name=rpm_file::"${rpm:2}"
42
-
43
- - uses: dawidd6/action-homebrew-bump-formula@v3
44
- with:
45
- token: ${{secrets.BREW_TOKEN}}
46
- tap: shopify/shopify
47
- formula: shopify-cli
48
- tag: ${{ steps.folder.outputs.name }}
49
-
50
- - name: Create Release # https://hub.github.com/hub-release.1.html
51
- env:
52
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53
- run: |
54
- cd packaging/builds/${{ steps.folder.outputs.name }}
55
- hub release create ${{ steps.tag.outputs.value }} \
56
- -a ${{ steps.binaries.outputs.deb_file }} \
57
- -a ${{ steps.binaries.outputs.rpm_file }} \
58
- -m "Version ${{ steps.folder.outputs.name }}
59
-
60
- Release of version ${{ steps.folder.outputs.name }} of the Shopify App CLI
61
- Please refer to [CHANGELOG](https://github.com/Shopify/shopify-app-cli/blob/master/CHANGELOG.md) for details."
@@ -1,40 +0,0 @@
1
- module Extension
2
- module Features
3
- class ArgoServeOptions
4
- include SmartProperties
5
-
6
- property! :argo_runtime, accepts: Features::ArgoRuntime
7
- property! :context, accepts: ShopifyCli::Context
8
- property :port, accepts: Integer, default: 39351
9
- property :public_url, accepts: String, default: ""
10
- property! :required_fields, accepts: Array, default: -> { [] }
11
- property! :renderer_package, accepts: Models::NpmPackage
12
-
13
- YARN_SERVE_COMMAND = %w(server)
14
- NPM_SERVE_COMMAND = %w(run-script server)
15
-
16
- def yarn_serve_command
17
- YARN_SERVE_COMMAND + options
18
- end
19
-
20
- def npm_serve_command
21
- NPM_SERVE_COMMAND + ["--"] + options
22
- end
23
-
24
- private
25
-
26
- def options
27
- project = ExtensionProject.current
28
-
29
- @serve_options ||= [].tap do |options|
30
- options << "--port=#{port}" if argo_runtime.accepts_port?
31
- options << "--shop=#{project.env.shop}" if required_fields.include?(:shop)
32
- options << "--apiKey=#{project.env.api_key}" if required_fields.include?(:api_key)
33
- options << "--argoVersion=#{renderer_package.version}" if argo_runtime.accepts_argo_version?
34
- options << "--uuid=#{project.registration_uuid}" if argo_runtime.accepts_uuid?
35
- options << "--publicUrl=#{public_url}" if argo_runtime.accepts_tunnel_url?
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,23 +0,0 @@
1
- require "shopify_cli"
2
-
3
- module Node
4
- module Commands
5
- class Populate < ShopifyCli::Command
6
- subcommand :Customer, "customers", Project.project_filepath("commands/populate/customer")
7
- subcommand :DraftOrder, "draftorders", Project.project_filepath("commands/populate/draft_order")
8
- subcommand :Product, "products", Project.project_filepath("commands/populate/product")
9
-
10
- def call(_args, _name)
11
- @ctx.puts(self.class.help)
12
- end
13
-
14
- def self.help
15
- ShopifyCli::Context.message("node.populate.help", ShopifyCli::TOOL_NAME)
16
- end
17
-
18
- def self.extended_help
19
- ShopifyCli::Context.message("node.populate.extended_help", ShopifyCli::TOOL_NAME)
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require "shopify_cli"
2
-
3
- module Rails
4
- module Commands
5
- class Populate < ShopifyCli::Command
6
- subcommand :Product, "products", Project.project_filepath("commands/populate/product")
7
- subcommand :Customer, "customers", Project.project_filepath("commands/populate/customer")
8
- subcommand :DraftOrder, "draftorders", Project.project_filepath("commands/populate/draft_order")
9
-
10
- def call(_args, _name)
11
- @ctx.puts(self.class.help)
12
- end
13
-
14
- def self.help
15
- ShopifyCli::Context.message("rails.populate.help", ShopifyCli::TOOL_NAME)
16
- end
17
-
18
- def self.extended_help
19
- ShopifyCli::Context.message("rails.populate.extended_help", ShopifyCli::TOOL_NAME)
20
- end
21
- end
22
- end
23
- end
@@ -1,31 +0,0 @@
1
- require "shopify_cli"
2
-
3
- module Rails
4
- module Commands
5
- class Populate
6
- class Customer < ShopifyCli::AdminAPI::PopulateResourceCommand
7
- @input_type = :CustomerInput
8
-
9
- def defaults
10
- first_name, last_name = ShopifyCli::Helpers::Haikunator.name
11
- {
12
- firstName: first_name,
13
- lastName: last_name,
14
- }
15
- end
16
-
17
- def message(data)
18
- ret = data["customerCreate"]["customer"]
19
- id = ShopifyCli::API.gid_to_id(ret["id"])
20
- @ctx.message(
21
- "rails.populate.customer.added",
22
- ret["displayName"],
23
- ShopifyCli::Project.current.env.shop,
24
- admin_url,
25
- id
26
- )
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,28 +0,0 @@
1
- require "shopify_cli"
2
-
3
- module Rails
4
- module Commands
5
- class Populate
6
- class DraftOrder < ShopifyCli::AdminAPI::PopulateResourceCommand
7
- @input_type = :DraftOrderInput
8
-
9
- def defaults
10
- {
11
- lineItems: [{
12
- originalUnitPrice: price,
13
- quantity: 1,
14
- weight: { value: 10, unit: "GRAMS" },
15
- title: ShopifyCli::Helpers::Haikunator.title,
16
- }],
17
- }
18
- end
19
-
20
- def message(data)
21
- ret = data["draftOrderCreate"]["draftOrder"]
22
- id = ShopifyCli::API.gid_to_id(ret["id"])
23
- @ctx.message("rails.populate.draft_order.added", ShopifyCli::Project.current.env.shop, admin_url, id)
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,30 +0,0 @@
1
- require "shopify_cli"
2
-
3
- module Rails
4
- module Commands
5
- class Populate
6
- class Product < ShopifyCli::AdminAPI::PopulateResourceCommand
7
- @input_type = :ProductInput
8
-
9
- def defaults
10
- {
11
- title: ShopifyCli::Helpers::Haikunator.title,
12
- variants: [{ price: price }],
13
- }
14
- end
15
-
16
- def message(data)
17
- ret = data["productCreate"]["product"]
18
- id = ShopifyCli::API.gid_to_id(ret["id"])
19
- @ctx.message(
20
- "rails.populate.product.added",
21
- ret["title"],
22
- ShopifyCli::Project.current.env.shop,
23
- admin_url,
24
- id
25
- )
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Layers
5
- module Domain
6
- class ConfigUi
7
- attr_reader :filename, :content
8
-
9
- def initialize(filename:, content:)
10
- @filename = filename
11
- @content = content
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Layers
5
- module Infrastructure
6
- class AssemblyScriptProjectCreator
7
- include SmartProperties
8
- property! :ctx, accepts: ShopifyCli::Context
9
- property! :extension_point, accepts: Domain::ExtensionPoint
10
- property! :script_name, accepts: String
11
- property! :path_to_project, accepts: String
12
-
13
- BOOTSTRAP = "npx --no-install shopify-scripts-toolchain-as bootstrap --from %{extension_point} --dest %{base}"
14
- BUILD = "shopify-scripts-toolchain-as build --src src/shopify_main.ts " \
15
- "--binary build/script.wasm --metadata build/metadata.json"
16
- MIN_NODE_VERSION = "14.5.0"
17
- ASC_ARGS = "-- --lib node_modules --optimize --use Date="
18
-
19
- def setup_dependencies
20
- write_npmrc
21
- write_package_json
22
- end
23
-
24
- def bootstrap
25
- command_runner.call(bootstap_command)
26
- end
27
-
28
- private
29
-
30
- def command_runner
31
- @command_runner ||= CommandRunner.new(ctx: ctx)
32
- end
33
-
34
- def write_npmrc
35
- command_runner.call("npm --userconfig ./.npmrc config set @shopify:registry https://registry.npmjs.com")
36
- command_runner.call("npm --userconfig ./.npmrc config set engine-strict true")
37
- end
38
-
39
- def extension_point_version
40
- return extension_point.sdks.assemblyscript.version if extension_point.sdks.assemblyscript.versioned?
41
-
42
- out = command_runner.call("npm show #{extension_point.sdks.assemblyscript.package} version --json")
43
- "^#{JSON.parse(out)}"
44
- end
45
-
46
- def write_package_json
47
- package_json = <<~HERE
48
- {
49
- "name": "#{script_name}",
50
- "version": "1.0.0",
51
- "devDependencies": {
52
- "@shopify/scripts-sdk-as": "#{extension_point.sdks.assemblyscript.sdk_version}",
53
- "@shopify/scripts-toolchain-as": "#{extension_point.sdks.assemblyscript.toolchain_version}",
54
- "#{extension_point.sdks.assemblyscript.package}": "#{extension_point_version}",
55
- "@as-pect/cli": "^6.0.0",
56
- "assemblyscript": "^0.18.13"
57
- },
58
- "scripts": {
59
- "test": "asp --summary --verbose",
60
- "build": "#{build_command}"
61
- },
62
- "engines": {
63
- "node": ">=#{MIN_NODE_VERSION}"
64
- }
65
- }
66
- HERE
67
- ctx.write("package.json", package_json)
68
- end
69
-
70
- def bootstap_command
71
- type = extension_point.dasherize_type
72
- base_command = format(BOOTSTRAP, extension_point: type, base: path_to_project)
73
- domain = extension_point.domain
74
-
75
- if domain.nil?
76
- base_command
77
- else
78
- "#{base_command} --domain #{domain}"
79
- end
80
- end
81
-
82
- def build_command
83
- type = extension_point.dasherize_type
84
- domain = extension_point.domain
85
-
86
- if domain.nil?
87
- "#{BUILD} #{ASC_ARGS}"
88
- else
89
- "#{BUILD} --domain #{domain} --ep #{type} #{ASC_ARGS}"
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Layers
5
- module Infrastructure
6
- class AssemblyScriptTaskRunner
7
- BYTECODE_FILE = "build/%{name}.wasm"
8
- METADATA_FILE = "build/metadata.json"
9
- SCRIPT_SDK_BUILD = "npm run build"
10
-
11
- attr_reader :ctx, :script_name
12
-
13
- def initialize(ctx, script_name)
14
- @ctx = ctx
15
- @script_name = script_name
16
- end
17
-
18
- def build
19
- compile
20
- bytecode
21
- end
22
-
23
- def compiled_type
24
- "wasm"
25
- end
26
-
27
- def install_dependencies
28
- check_node_version!
29
-
30
- output, status = ctx.capture2e("npm install --no-audit --no-optional --legacy-peer-deps --loglevel error")
31
- raise Errors::DependencyInstallError, output unless status.success?
32
- end
33
-
34
- def dependencies_installed?
35
- # Assuming if node_modules folder exist at root of script folder, all deps are installed
36
- ctx.dir_exist?("node_modules")
37
- end
38
-
39
- def metadata
40
- unless @ctx.file_exist?(METADATA_FILE)
41
- msg = @ctx.message("script.error.metadata_not_found_cause", METADATA_FILE)
42
- raise Domain::Errors::MetadataNotFoundError, msg
43
- end
44
-
45
- raw_contents = File.read(METADATA_FILE)
46
- Domain::Metadata.create_from_json(@ctx, raw_contents)
47
- end
48
-
49
- private
50
-
51
- def check_node_version!
52
- output, status = @ctx.capture2e("node", "--version")
53
- raise Errors::DependencyInstallError, output unless status.success?
54
-
55
- require "semantic/semantic"
56
- version = ::Semantic::Version.new(output[1..-1])
57
- unless version >= ::Semantic::Version.new(AssemblyScriptProjectCreator::MIN_NODE_VERSION)
58
- raise Errors::DependencyInstallError,
59
- "Node version must be >= v#{AssemblyScriptProjectCreator::MIN_NODE_VERSION}. "\
60
- "Current version: #{output.strip}."
61
- end
62
- end
63
-
64
- def compile
65
- check_compilation_dependencies!
66
- CommandRunner.new(ctx: ctx).call(SCRIPT_SDK_BUILD)
67
- end
68
-
69
- def check_compilation_dependencies!
70
- pkg = JSON.parse(File.read("package.json"))
71
- build_script = pkg.dig("scripts", "build")
72
-
73
- raise Errors::BuildScriptNotFoundError,
74
- "Build script not found" if build_script.nil?
75
-
76
- unless build_script.start_with?("shopify-scripts")
77
- raise Errors::InvalidBuildScriptError, "Invalid build script"
78
- end
79
- end
80
-
81
- def bytecode
82
- legacy_filename = format(BYTECODE_FILE, name: script_name)
83
- filename = format(BYTECODE_FILE, name: "script")
84
-
85
- bytecode_file = if ctx.file_exist?(filename)
86
- filename
87
- elsif ctx.file_exist?(legacy_filename)
88
- legacy_filename
89
- else
90
- raise Errors::WebAssemblyBinaryNotFoundError
91
- end
92
-
93
- contents = ctx.binread(bytecode_file)
94
- ctx.rm(bytecode_file)
95
-
96
- contents
97
- end
98
- end
99
- end
100
- end
101
- end