shopify-cli 1.12.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) 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 +52 -21
  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 +31 -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 -59
  50. data/lib/project_types/extension/features/argo_serve.rb +25 -21
  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 +13 -13
  58. data/lib/project_types/extension/models/specification_handlers/theme_app_extension.rb +89 -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 +37 -16
  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 +16 -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/init.rb +42 -0
  112. data/lib/project_types/theme/commands/language_server.rb +16 -0
  113. data/lib/project_types/theme/commands/package.rb +55 -0
  114. data/lib/project_types/theme/commands/publish.rb +43 -0
  115. data/lib/project_types/theme/commands/pull.rb +51 -0
  116. data/lib/project_types/theme/commands/push.rb +58 -32
  117. data/lib/project_types/theme/commands/serve.rb +8 -16
  118. data/lib/project_types/theme/forms/confirm_store.rb +15 -0
  119. data/lib/project_types/theme/forms/select.rb +59 -0
  120. data/lib/project_types/theme/messages/messages.rb +117 -102
  121. data/lib/project_types/theme/ui/sync_progress_bar.rb +20 -0
  122. data/lib/shopify-cli/admin_api.rb +53 -35
  123. data/lib/shopify-cli/admin_api/populate_resource_command.rb +6 -14
  124. data/lib/shopify-cli/admin_api/schema.rb +1 -10
  125. data/lib/shopify-cli/api.rb +29 -14
  126. data/lib/shopify-cli/command.rb +15 -3
  127. data/lib/shopify-cli/commands.rb +7 -2
  128. data/lib/shopify-cli/commands/help.rb +2 -29
  129. data/lib/shopify-cli/commands/login.rb +95 -0
  130. data/lib/shopify-cli/commands/logout.rb +24 -8
  131. data/lib/shopify-cli/commands/populate.rb +23 -0
  132. data/lib/{project_types/node → shopify-cli}/commands/populate/customer.rb +2 -8
  133. data/lib/{project_types/node → shopify-cli}/commands/populate/draft_order.rb +2 -2
  134. data/lib/{project_types/node → shopify-cli}/commands/populate/product.rb +2 -8
  135. data/lib/shopify-cli/commands/store.rb +15 -0
  136. data/lib/shopify-cli/commands/switch.rb +39 -0
  137. data/lib/shopify-cli/commands/system.rb +12 -0
  138. data/lib/shopify-cli/commands/whoami.rb +28 -0
  139. data/lib/shopify-cli/connect.rb +32 -0
  140. data/lib/shopify-cli/context.rb +65 -4
  141. data/lib/shopify-cli/core/entry_point.rb +3 -22
  142. data/lib/shopify-cli/db.rb +4 -4
  143. data/lib/shopify-cli/http_request.rb +16 -0
  144. data/lib/shopify-cli/identity_auth.rb +282 -0
  145. data/lib/shopify-cli/{oauth → identity_auth}/servlet.rb +11 -12
  146. data/lib/shopify-cli/messages/messages.rb +133 -39
  147. data/lib/shopify-cli/partners_api.rb +21 -41
  148. data/lib/shopify-cli/partners_api/organizations.rb +8 -0
  149. data/lib/shopify-cli/project_commands.rb +16 -0
  150. data/lib/shopify-cli/project_type.rb +0 -31
  151. data/lib/shopify-cli/resources/env_file.rb +1 -1
  152. data/lib/shopify-cli/shopifolk.rb +8 -11
  153. data/lib/shopify-cli/sub_command.rb +1 -0
  154. data/lib/shopify-cli/tasks.rb +3 -0
  155. data/lib/shopify-cli/tasks/confirm_store.rb +18 -0
  156. data/lib/shopify-cli/tasks/create_api_client.rb +2 -2
  157. data/lib/shopify-cli/tasks/ensure_authenticated.rb +13 -0
  158. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +1 -1
  159. data/lib/shopify-cli/tasks/ensure_project_type.rb +12 -0
  160. data/lib/shopify-cli/tasks/select_org_and_shop.rb +0 -3
  161. data/lib/shopify-cli/theme/dev_server.rb +98 -0
  162. data/lib/shopify-cli/theme/dev_server/certificate_manager.rb +79 -0
  163. data/lib/shopify-cli/theme/dev_server/header_hash.rb +94 -0
  164. data/lib/shopify-cli/theme/dev_server/hot-reload.js +93 -0
  165. data/lib/shopify-cli/theme/dev_server/hot_reload.rb +76 -0
  166. data/lib/shopify-cli/theme/dev_server/local_assets.rb +87 -0
  167. data/lib/shopify-cli/theme/dev_server/proxy.rb +205 -0
  168. data/lib/shopify-cli/theme/dev_server/sse.rb +75 -0
  169. data/lib/shopify-cli/theme/dev_server/watcher.rb +59 -0
  170. data/lib/shopify-cli/theme/dev_server/web_server.rb +140 -0
  171. data/lib/shopify-cli/theme/development_theme.rb +69 -0
  172. data/lib/shopify-cli/theme/file.rb +112 -0
  173. data/lib/shopify-cli/theme/ignore_filter.rb +109 -0
  174. data/lib/shopify-cli/theme/mime_type.rb +34 -0
  175. data/lib/shopify-cli/theme/syncer.rb +328 -0
  176. data/lib/shopify-cli/theme/theme.rb +204 -0
  177. data/lib/shopify-cli/version.rb +1 -1
  178. data/lib/shopify_cli.rb +18 -11
  179. data/shopify-cli.gemspec +12 -5
  180. data/shopify.fish +1 -1
  181. data/shopify.sh +1 -1
  182. metadata +96 -41
  183. data/.github/workflows/release.yml +0 -61
  184. data/lib/project_types/extension/features/argo_serve_options.rb +0 -41
  185. data/lib/project_types/node/commands/populate.rb +0 -23
  186. data/lib/project_types/rails/commands/populate.rb +0 -23
  187. data/lib/project_types/rails/commands/populate/customer.rb +0 -31
  188. data/lib/project_types/rails/commands/populate/draft_order.rb +0 -28
  189. data/lib/project_types/rails/commands/populate/product.rb +0 -30
  190. data/lib/project_types/script/layers/domain/config_ui.rb +0 -16
  191. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +0 -95
  192. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +0 -101
  193. data/lib/project_types/script/layers/infrastructure/project_creator.rb +0 -24
  194. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +0 -71
  195. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +0 -58
  196. data/lib/project_types/script/layers/infrastructure/task_runner.rb +0 -19
  197. data/lib/project_types/theme/commands/connect.rb +0 -54
  198. data/lib/project_types/theme/commands/create.rb +0 -48
  199. data/lib/project_types/theme/commands/deploy.rb +0 -38
  200. data/lib/project_types/theme/commands/generate.rb +0 -20
  201. data/lib/project_types/theme/commands/generate/env.rb +0 -79
  202. data/lib/project_types/theme/forms/connect.rb +0 -34
  203. data/lib/project_types/theme/forms/create.rb +0 -22
  204. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +0 -78
  205. data/lib/project_types/theme/themekit.rb +0 -113
  206. data/lib/shopify-cli/commands/connect.rb +0 -64
  207. data/lib/shopify-cli/commands/create.rb +0 -50
  208. data/lib/shopify-cli/oauth.rb +0 -198
@@ -8,7 +8,8 @@ module Script
8
8
  def call(ctx:, force:)
9
9
  script_project_repo = Infrastructure::ScriptProjectRepository.new(ctx: ctx)
10
10
  script_project = script_project_repo.get
11
- task_runner = Infrastructure::TaskRunner.for(ctx, script_project.language, script_project.script_name)
11
+ task_runner = Infrastructure::Languages::TaskRunner
12
+ .for(ctx, script_project.language, script_project.script_name)
12
13
 
13
14
  ProjectDependencies.install(ctx: ctx, task_runner: task_runner)
14
15
  BuildScript.call(ctx: ctx, task_runner: task_runner, script_project: script_project)
@@ -14,21 +14,16 @@ module Script
14
14
  end
15
15
  end
16
16
 
17
- class InvalidConfigUiDefinitionError < ScriptProjectError
18
- attr_reader :filename
19
- def initialize(filename)
17
+ class MissingScriptJsonFieldError < ScriptProjectError
18
+ attr_reader :field
19
+ def initialize(field)
20
20
  super()
21
- @filename = filename
21
+ @field = field
22
22
  end
23
23
  end
24
24
 
25
- class MissingSpecifiedConfigUiDefinitionError < ScriptProjectError
26
- attr_reader :filename
27
- def initialize(filename)
28
- super()
29
- @filename = filename
30
- end
31
- end
25
+ class InvalidScriptJsonDefinitionError < ScriptProjectError; end
26
+ class NoScriptJsonFile < ScriptProjectError; end
32
27
 
33
28
  class ScriptNotFoundError < ScriptProjectError
34
29
  attr_reader :script_name, :extension_point_type
@@ -7,8 +7,7 @@ module Script
7
7
  attr_reader :id,
8
8
  :uuid,
9
9
  :extension_point_type,
10
- :script_name,
11
- :config_ui,
10
+ :script_json,
12
11
  :script_content,
13
12
  :compiled_type,
14
13
  :metadata
@@ -17,33 +16,30 @@ module Script
17
16
  id:,
18
17
  uuid:,
19
18
  extension_point_type:,
20
- script_name:,
21
19
  script_content:,
22
20
  compiled_type:,
23
21
  metadata:,
24
- config_ui:
22
+ script_json:
25
23
  )
26
24
  @id = id
27
25
  @uuid = uuid
28
26
  @extension_point_type = extension_point_type
29
- @script_name = script_name
30
27
  @script_content = script_content
31
28
  @compiled_type = compiled_type
32
29
  @metadata = metadata
33
- @config_ui = config_ui
30
+ @script_json = script_json
34
31
  end
35
32
 
36
33
  def push(script_service, api_key, force)
37
34
  script_service.push(
38
35
  uuid: @uuid,
39
36
  extension_point_type: @extension_point_type,
40
- script_name: @script_name,
41
37
  script_content: @script_content,
42
38
  compiled_type: @compiled_type,
43
39
  api_key: api_key,
44
40
  force: force,
45
41
  metadata: @metadata,
46
- config_ui: @config_ui,
42
+ script_json: @script_json,
47
43
  )
48
44
  end
49
45
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Domain
6
+ class ScriptJson
7
+ attr_reader :content, :version, :title, :description, :configuration_ui, :configuration
8
+
9
+ REQUIRED_FIELDS = %w(version title)
10
+
11
+ def initialize(content:)
12
+ validate_content!(content)
13
+
14
+ @content = content
15
+ @version = @content["version"].to_s
16
+ @title = @content["title"]
17
+ @description = @content["description"]
18
+ @configuration_ui = @content["configurationUi"]
19
+ @configuration = @content["configuration"]
20
+ end
21
+
22
+ private
23
+
24
+ def validate_content!(content)
25
+ REQUIRED_FIELDS.each do |field|
26
+ raise Errors::MissingScriptJsonFieldError, field if content[field].nil?
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -15,7 +15,7 @@ module Script
15
15
  property! :script_name, accepts: String
16
16
  property! :language, accepts: String
17
17
 
18
- property :config_ui, accepts: ConfigUi
18
+ property :script_json, accepts: ScriptJson
19
19
 
20
20
  def initialize(*)
21
21
  super
@@ -6,40 +6,36 @@ module Script
6
6
  module Errors
7
7
  class AppNotInstalledError < ScriptProjectError; end
8
8
  class BuildError < ScriptProjectError; end
9
- class ConfigUiSyntaxError < ScriptProjectError; end
9
+ class ScriptJsonSyntaxError < ScriptProjectError; end
10
10
 
11
- class ConfigUiMissingKeysError < ScriptProjectError
12
- attr_reader :filename, :missing_keys
13
- def initialize(filename, missing_keys)
11
+ class ScriptJsonMissingKeysError < ScriptProjectError
12
+ attr_reader :missing_keys
13
+ def initialize(missing_keys)
14
14
  super()
15
- @filename = filename
16
15
  @missing_keys = missing_keys
17
16
  end
18
17
  end
19
18
 
20
- class ConfigUiInvalidInputModeError < ScriptProjectError
21
- attr_reader :filename, :valid_input_modes
22
- def initialize(filename, valid_input_modes)
19
+ class ScriptJsonInvalidValueError < ScriptProjectError
20
+ attr_reader :valid_input_modes
21
+ def initialize(valid_input_modes)
23
22
  super()
24
- @filename = filename
25
23
  @valid_input_modes = valid_input_modes
26
24
  end
27
25
  end
28
26
 
29
- class ConfigUiFieldsMissingKeysError < ScriptProjectError
30
- attr_reader :filename, :missing_keys
31
- def initialize(filename, missing_keys)
27
+ class ScriptJsonFieldsMissingKeysError < ScriptProjectError
28
+ attr_reader :missing_keys
29
+ def initialize(missing_keys)
32
30
  super()
33
- @filename = filename
34
31
  @missing_keys = missing_keys
35
32
  end
36
33
  end
37
34
 
38
- class ConfigUiFieldsInvalidTypeError < ScriptProjectError
39
- attr_reader :filename, :valid_types
40
- def initialize(filename, valid_types)
35
+ class ScriptJsonFieldsInvalidValueError < ScriptProjectError
36
+ attr_reader :valid_types
37
+ def initialize(valid_types)
41
38
  super()
42
- @filename = filename
43
39
  @valid_types = valid_types
44
40
  end
45
41
  end
@@ -72,7 +68,7 @@ module Script
72
68
  class SystemCallFailureError < ScriptProjectError
73
69
  attr_reader :out, :cmd
74
70
  def initialize(out:, cmd:)
75
- super()
71
+ super(out)
76
72
  @out = out
77
73
  @cmd = cmd
78
74
  end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ module Languages
7
+ class AssemblyScriptProjectCreator
8
+ include SmartProperties
9
+ property! :ctx, accepts: ShopifyCli::Context
10
+ property! :extension_point, accepts: Domain::ExtensionPoint
11
+ property! :script_name, accepts: String
12
+ property! :path_to_project, accepts: String
13
+
14
+ BOOTSTRAP = "npx --no-install shopify-scripts-toolchain-as bootstrap --from %{extension_point} --dest %{base}"
15
+ BUILD = "shopify-scripts-toolchain-as build --src src/shopify_main.ts " \
16
+ "--binary build/script.wasm --metadata build/metadata.json"
17
+ MIN_NODE_VERSION = "14.5.0"
18
+ ASC_ARGS = "-- --lib node_modules --optimize --use Date="
19
+
20
+ def setup_dependencies
21
+ write_npmrc
22
+ write_package_json
23
+ end
24
+
25
+ def bootstrap
26
+ command_runner.call(bootstap_command)
27
+ end
28
+
29
+ private
30
+
31
+ def command_runner
32
+ @command_runner ||= CommandRunner.new(ctx: ctx)
33
+ end
34
+
35
+ def write_npmrc
36
+ command_runner.call("npm --userconfig ./.npmrc config set @shopify:registry https://registry.npmjs.com")
37
+ command_runner.call("npm --userconfig ./.npmrc config set engine-strict true")
38
+ end
39
+
40
+ def extension_point_version
41
+ return extension_point.sdks.assemblyscript.version if extension_point.sdks.assemblyscript.versioned?
42
+
43
+ out = command_runner.call("npm show #{extension_point.sdks.assemblyscript.package} version --json")
44
+ "^#{JSON.parse(out)}"
45
+ end
46
+
47
+ def write_package_json
48
+ package_json = {
49
+ name: script_name,
50
+ version: "1.0.0",
51
+ devDependencies: dev_dependencies,
52
+ scripts: {
53
+ test: "asp --summary --verbose",
54
+ build: build_command,
55
+ },
56
+ engines: {
57
+ node: ">=#{MIN_NODE_VERSION}",
58
+ },
59
+ }
60
+
61
+ ctx.write("package.json", JSON.pretty_generate(package_json))
62
+ end
63
+
64
+ def bootstap_command
65
+ type = extension_point.dasherize_type
66
+ base_command = format(BOOTSTRAP, extension_point: type, base: path_to_project)
67
+ domain = extension_point.domain
68
+
69
+ if domain.nil?
70
+ base_command
71
+ else
72
+ "#{base_command} --domain #{domain}"
73
+ end
74
+ end
75
+
76
+ def build_command
77
+ type = extension_point.dasherize_type
78
+ domain = extension_point.domain
79
+
80
+ if domain.nil?
81
+ "#{BUILD} #{ASC_ARGS}"
82
+ else
83
+ "#{BUILD} --domain #{domain} --ep #{type} #{ASC_ARGS}"
84
+ end
85
+ end
86
+
87
+ def dev_dependencies
88
+ dependencies = {
89
+ "@as-pect/cli": "^6.0.0",
90
+ "assemblyscript": "^0.18.13",
91
+ "@shopify/scripts-toolchain-as": extension_point.sdks.assemblyscript.toolchain_version,
92
+ "#{extension_point.sdks.assemblyscript.package}": extension_point_version,
93
+ }
94
+
95
+ if extension_point.sdks.assemblyscript.sdk_version
96
+ dependencies["@shopify/scripts-sdk-as"] = extension_point.sdks.assemblyscript.sdk_version
97
+ end
98
+
99
+ dependencies
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ module Languages
7
+ class AssemblyScriptTaskRunner
8
+ BYTECODE_FILE = "build/%{name}.wasm"
9
+ METADATA_FILE = "build/metadata.json"
10
+ SCRIPT_SDK_BUILD = "npm run build"
11
+
12
+ attr_reader :ctx, :script_name
13
+
14
+ def initialize(ctx, script_name)
15
+ @ctx = ctx
16
+ @script_name = script_name
17
+ end
18
+
19
+ def build
20
+ compile
21
+ bytecode
22
+ end
23
+
24
+ def compiled_type
25
+ "wasm"
26
+ end
27
+
28
+ def install_dependencies
29
+ check_node_version!
30
+
31
+ output, status = ctx.capture2e("npm install --no-audit --no-optional --legacy-peer-deps --loglevel error")
32
+ raise Errors::DependencyInstallError, output unless status.success?
33
+ end
34
+
35
+ def dependencies_installed?
36
+ # Assuming if node_modules folder exist at root of script folder, all deps are installed
37
+ ctx.dir_exist?("node_modules")
38
+ end
39
+
40
+ def metadata
41
+ unless @ctx.file_exist?(METADATA_FILE)
42
+ msg = @ctx.message("script.error.metadata_not_found_cause", METADATA_FILE)
43
+ raise Domain::Errors::MetadataNotFoundError, msg
44
+ end
45
+
46
+ raw_contents = File.read(METADATA_FILE)
47
+ Domain::Metadata.create_from_json(@ctx, raw_contents)
48
+ end
49
+
50
+ private
51
+
52
+ def check_node_version!
53
+ output, status = @ctx.capture2e("node", "--version")
54
+ raise Errors::DependencyInstallError, output unless status.success?
55
+
56
+ require "semantic/semantic"
57
+ version = ::Semantic::Version.new(output[1..-1])
58
+ unless version >= ::Semantic::Version.new(AssemblyScriptProjectCreator::MIN_NODE_VERSION)
59
+ raise Errors::DependencyInstallError,
60
+ "Node version must be >= v#{AssemblyScriptProjectCreator::MIN_NODE_VERSION}. "\
61
+ "Current version: #{output.strip}."
62
+ end
63
+ end
64
+
65
+ def compile
66
+ check_compilation_dependencies!
67
+ CommandRunner.new(ctx: ctx).call(SCRIPT_SDK_BUILD)
68
+ end
69
+
70
+ def check_compilation_dependencies!
71
+ pkg = JSON.parse(File.read("package.json"))
72
+ build_script = pkg.dig("scripts", "build")
73
+
74
+ raise Errors::BuildScriptNotFoundError,
75
+ "Build script not found" if build_script.nil?
76
+
77
+ unless build_script.start_with?("shopify-scripts")
78
+ raise Errors::InvalidBuildScriptError, "Invalid build script"
79
+ end
80
+ end
81
+
82
+ def bytecode
83
+ legacy_filename = format(BYTECODE_FILE, name: script_name)
84
+ filename = format(BYTECODE_FILE, name: "script")
85
+
86
+ bytecode_file = if ctx.file_exist?(filename)
87
+ filename
88
+ elsif ctx.file_exist?(legacy_filename)
89
+ legacy_filename
90
+ else
91
+ raise Errors::WebAssemblyBinaryNotFoundError
92
+ end
93
+
94
+ contents = ctx.binread(bytecode_file)
95
+ ctx.rm(bytecode_file)
96
+
97
+ contents
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ module Languages
7
+ class ProjectCreator
8
+ PROJECT_CREATORS = {
9
+ "assemblyscript" => AssemblyScriptProjectCreator,
10
+ "rust" => RustProjectCreator,
11
+ }
12
+
13
+ def self.for(ctx, language, extension_point, script_name, path_to_project)
14
+ raise Errors::ProjectCreatorNotFoundError unless PROJECT_CREATORS[language]
15
+ PROJECT_CREATORS[language].new(
16
+ ctx: ctx,
17
+ extension_point: extension_point,
18
+ script_name: script_name,
19
+ path_to_project: path_to_project
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ module Languages
7
+ class RustProjectCreator
8
+ include SmartProperties
9
+ property! :ctx, accepts: ShopifyCli::Context
10
+ property! :extension_point, accepts: Domain::ExtensionPoint
11
+ property! :script_name, accepts: String
12
+ property! :path_to_project, accepts: String
13
+
14
+ ORIGIN_BRANCH = "main"
15
+ SAMPLE_PATH = "default"
16
+
17
+ def setup_dependencies
18
+ git_init
19
+ setup_remote
20
+ setup_sparse_checkout
21
+ pull
22
+ clean
23
+ set_script_name
24
+ end
25
+
26
+ def bootstrap
27
+ end
28
+
29
+ private
30
+
31
+ def command_runner
32
+ @command_runner ||= CommandRunner.new(ctx: ctx)
33
+ end
34
+
35
+ def git_init
36
+ command_runner.call("git init")
37
+ end
38
+
39
+ def setup_remote
40
+ repo = extension_point.sdks.rust.package
41
+ command_runner.call("git remote add -f origin #{repo}")
42
+ end
43
+
44
+ def setup_sparse_checkout
45
+ type = extension_point.type
46
+ command_runner.call("git config core.sparsecheckout true")
47
+ command_runner.call("echo #{type}/#{SAMPLE_PATH} >> .git/info/sparse-checkout")
48
+ end
49
+
50
+ def pull
51
+ command_runner.call("git pull origin #{ORIGIN_BRANCH}")
52
+ end
53
+
54
+ def clean
55
+ type = extension_point.type
56
+ ctx.rm_rf(".git")
57
+ source = File.join(path_to_project, File.join(type, SAMPLE_PATH))
58
+ FileUtils.copy_entry(source, path_to_project)
59
+ ctx.rm_rf(type)
60
+ end
61
+
62
+ def set_script_name
63
+ config_file = "Cargo.toml"
64
+ upstream_name = "#{extension_point.type.gsub("_", "-")}-default"
65
+ contents = File.read(config_file)
66
+ new_contents = contents.sub(upstream_name, script_name)
67
+ File.write(config_file, new_contents)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end