shopify-cli 1.10.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +1 -0
- data/.github/workflows/release.yml +2 -4
- data/CHANGELOG.md +31 -1
- data/Gemfile.lock +1 -1
- data/lib/project_types/extension/cli.rb +6 -2
- data/lib/project_types/extension/commands/serve.rb +69 -1
- data/lib/project_types/extension/commands/tunnel.rb +3 -1
- data/lib/project_types/extension/extension_project.rb +1 -0
- data/lib/project_types/extension/features/argo.rb +15 -24
- data/lib/project_types/extension/features/argo_runtime.rb +91 -0
- data/lib/project_types/extension/features/argo_serve.rb +35 -27
- data/lib/project_types/extension/features/argo_serve_options.rb +42 -0
- data/lib/project_types/extension/messages/messages.rb +3 -0
- data/lib/project_types/extension/models/npm_package.rb +14 -0
- data/lib/project_types/extension/models/specification.rb +1 -0
- data/lib/project_types/extension/models/specification_handlers/checkout_argo_extension.rb +18 -0
- data/lib/project_types/extension/models/specification_handlers/default.rb +33 -3
- data/lib/project_types/extension/tasks/choose_next_available_port.rb +36 -0
- data/lib/project_types/extension/tasks/configure_features.rb +2 -0
- data/lib/project_types/extension/tasks/find_npm_packages.rb +106 -0
- data/lib/project_types/script/cli.rb +14 -13
- data/lib/project_types/script/commands/push.rb +8 -3
- data/lib/project_types/script/config/extension_points.yml +0 -3
- data/lib/project_types/script/graphql/app_script_update_or_create.graphql +9 -3
- data/lib/project_types/script/layers/application/create_script.rb +6 -5
- data/lib/project_types/script/layers/application/push_script.rb +2 -1
- data/lib/project_types/script/layers/domain/errors.rb +6 -13
- data/lib/project_types/script/layers/domain/push_package.rb +4 -8
- data/lib/project_types/script/layers/domain/script_json.rb +32 -0
- data/lib/project_types/script/layers/domain/script_project.rb +1 -1
- data/lib/project_types/script/layers/infrastructure/command_runner.rb +19 -0
- data/lib/project_types/script/layers/infrastructure/errors.rb +25 -20
- data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_project_creator.rb +105 -0
- data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb +103 -0
- data/lib/project_types/script/layers/infrastructure/languages/project_creator.rb +26 -0
- data/lib/project_types/script/layers/infrastructure/languages/rust_project_creator.rb +73 -0
- data/lib/project_types/script/layers/infrastructure/languages/rust_task_runner.rb +60 -0
- data/lib/project_types/script/layers/infrastructure/languages/task_runner.rb +21 -0
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +6 -8
- data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +44 -59
- data/lib/project_types/script/layers/infrastructure/script_service.rb +21 -15
- data/lib/project_types/script/messages/messages.rb +28 -22
- data/lib/project_types/script/tasks/ensure_env.rb +32 -3
- data/lib/project_types/script/ui/error_handler.rb +37 -36
- data/lib/shopify-cli/admin_api.rb +7 -4
- data/lib/shopify-cli/context.rb +13 -0
- data/lib/shopify-cli/messages/messages.rb +48 -43
- data/lib/shopify-cli/method_object.rb +4 -4
- data/lib/shopify-cli/oauth.rb +7 -1
- data/lib/shopify-cli/partners_api.rb +7 -4
- data/lib/shopify-cli/partners_api/organizations.rb +3 -3
- data/lib/shopify-cli/resources/env_file.rb +1 -1
- data/lib/shopify-cli/shopifolk.rb +1 -1
- data/lib/shopify-cli/tasks/select_org_and_shop.rb +6 -4
- data/lib/shopify-cli/tunnel.rb +22 -1
- data/lib/shopify-cli/version.rb +1 -1
- metadata +17 -11
- data/lib/project_types/extension/features/argo_renderer_package.rb +0 -47
- data/lib/project_types/script/layers/domain/config_ui.rb +0 -16
- data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +0 -100
- data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +0 -95
- data/lib/project_types/script/layers/infrastructure/project_creator.rb +0 -24
- data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +0 -72
- data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +0 -59
- data/lib/project_types/script/layers/infrastructure/task_runner.rb +0 -19
@@ -52,8 +52,8 @@ module ShopifyCli
|
|
52
52
|
# invokes the original `call` implementation and wraps its return value
|
53
53
|
# into a result object.
|
54
54
|
#
|
55
|
-
def call(*args, **kwargs)
|
56
|
-
Result.wrap { super(*args, **kwargs) }.call
|
55
|
+
def call(*args, **kwargs, &block)
|
56
|
+
Result.wrap { kwargs.any? ? super(*args, **kwargs, &block) : super(*args, &block) }.call
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -64,10 +64,10 @@ module ShopifyCli
|
|
64
64
|
# initializer or to `call`. If the keyword argument matches the name of
|
65
65
|
# property, it is forwarded to the initializer, otherwise to call.
|
66
66
|
#
|
67
|
-
def call(*args, **kwargs)
|
67
|
+
def call(*args, **kwargs, &block)
|
68
68
|
properties.keys.yield_self do |properties|
|
69
69
|
new(**kwargs.slice(*properties))
|
70
|
-
.call(*args, **kwargs.slice(*(kwargs.keys - properties)))
|
70
|
+
.call(*args, **kwargs.slice(*(kwargs.keys - properties)), &block)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
data/lib/shopify-cli/oauth.rb
CHANGED
@@ -80,7 +80,13 @@ module ShopifyCli
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def output_authentication_info(uri)
|
83
|
-
login_location =
|
83
|
+
login_location = if service == "admin"
|
84
|
+
ctx.message("core.oauth.location.admin")
|
85
|
+
elsif Shopifolk.acting_as_shopify_organization?
|
86
|
+
ctx.message("core.oauth.location.shopifolk")
|
87
|
+
else
|
88
|
+
ctx.message("core.oauth.location.partner")
|
89
|
+
end
|
84
90
|
ctx.puts(ctx.message("core.oauth.authentication_required", login_location))
|
85
91
|
ctx.open_url!(uri)
|
86
92
|
end
|
@@ -59,11 +59,14 @@ module ShopifyCli
|
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
-
def authenticated_req(ctx)
|
63
|
-
|
62
|
+
def authenticated_req(ctx, &block)
|
63
|
+
CLI::Kit::Util
|
64
|
+
.begin(&block)
|
65
|
+
.retry_after(API::APIRequestUnauthorizedError, retries: 1) do
|
66
|
+
authenticate(ctx)
|
67
|
+
end
|
64
68
|
rescue API::APIRequestUnauthorizedError
|
65
|
-
|
66
|
-
retry
|
69
|
+
ctx.abort(ctx.message("core.api.error.failed_auth"))
|
67
70
|
rescue API::APIRequestNotFoundError
|
68
71
|
ctx.puts(ctx.message("core.partners_api.error.account_not_found", ShopifyCli::TOOL_NAME))
|
69
72
|
end
|
@@ -4,7 +4,7 @@ module ShopifyCli
|
|
4
4
|
class << self
|
5
5
|
def fetch_all(ctx)
|
6
6
|
resp = PartnersAPI.query(ctx, "all_organizations")
|
7
|
-
(resp
|
7
|
+
(resp&.dig("data", "organizations", "nodes") || []).map do |org|
|
8
8
|
org["stores"] = (org.dig("stores", "nodes") || [])
|
9
9
|
org
|
10
10
|
end
|
@@ -12,7 +12,7 @@ module ShopifyCli
|
|
12
12
|
|
13
13
|
def fetch(ctx, id:)
|
14
14
|
resp = PartnersAPI.query(ctx, "find_organization", id: id)
|
15
|
-
org = resp
|
15
|
+
org = resp&.dig("data", "organizations", "nodes")&.first
|
16
16
|
return nil if org.nil?
|
17
17
|
org["stores"] = (org.dig("stores", "nodes") || [])
|
18
18
|
org
|
@@ -20,7 +20,7 @@ module ShopifyCli
|
|
20
20
|
|
21
21
|
def fetch_with_app(ctx)
|
22
22
|
resp = PartnersAPI.query(ctx, "all_orgs_with_apps")
|
23
|
-
(resp
|
23
|
+
(resp&.dig("data", "organizations", "nodes") || []).map do |org|
|
24
24
|
org["stores"] = (org.dig("stores", "nodes") || [])
|
25
25
|
org["apps"] = (org.dig("apps", "nodes") || [])
|
26
26
|
org
|
@@ -22,7 +22,7 @@ module ShopifyCli
|
|
22
22
|
def parse(directory)
|
23
23
|
File.read(File.join(directory, FILENAME))
|
24
24
|
.gsub("\r\n", "\n").split("\n").each_with_object({}) do |line, output|
|
25
|
-
match = /\A([A-Za-z_0-9]+)
|
25
|
+
match = /\A([A-Za-z_0-9]+)\s*=\s*(.*)\z/.match(line)
|
26
26
|
if match
|
27
27
|
key = match[1]
|
28
28
|
output[key] = case match[2]
|
@@ -33,7 +33,7 @@ module ShopifyCli
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def acting_as_shopify_organization?
|
36
|
-
|
36
|
+
!!(@acting_as_shopify_organization || (Project.has_current? && Project.current.config["shopify_organization"]))
|
37
37
|
end
|
38
38
|
|
39
39
|
def reset
|
@@ -35,14 +35,16 @@ module ShopifyCli
|
|
35
35
|
@organization ||= if !organization_id.nil?
|
36
36
|
org = ShopifyCli::PartnersAPI::Organizations.fetch(ctx, id: organization_id)
|
37
37
|
if org.nil?
|
38
|
-
ctx.puts(ctx.message("core.tasks.select_org_and_shop.
|
38
|
+
ctx.puts(ctx.message("core.tasks.select_org_and_shop.authentication_issue", ShopifyCli::TOOL_NAME))
|
39
39
|
ctx.abort(ctx.message("core.tasks.select_org_and_shop.error.organization_not_found"))
|
40
40
|
end
|
41
41
|
org
|
42
42
|
elsif organizations.count == 0
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
if Shopifolk.acting_as_shopify_organization?
|
44
|
+
ctx.abort(ctx.message("core.tasks.select_org_and_shop.error.shopifolk_notice", ShopifyCli::TOOL_NAME))
|
45
|
+
else
|
46
|
+
ctx.abort(ctx.message("core.tasks.select_org_and_shop.error.no_organizations"))
|
47
|
+
end
|
46
48
|
elsif organizations.count == 1
|
47
49
|
org = organizations.first
|
48
50
|
ctx.puts(ctx.message("core.tasks.select_org_and_shop.organization", org["businessName"], org["id"]))
|
data/lib/shopify-cli/tunnel.rb
CHANGED
@@ -2,6 +2,7 @@ require "json"
|
|
2
2
|
require "fileutils"
|
3
3
|
require "shopify_cli"
|
4
4
|
require "forwardable"
|
5
|
+
require "uri"
|
5
6
|
|
6
7
|
module ShopifyCli
|
7
8
|
##
|
@@ -11,7 +12,7 @@ module ShopifyCli
|
|
11
12
|
class Tunnel
|
12
13
|
extend SingleForwardable
|
13
14
|
|
14
|
-
def_delegators :new, :start, :stop, :auth, :stats, :urls
|
15
|
+
def_delegators :new, :start, :stop, :auth, :stats, :urls, :running_on?
|
15
16
|
|
16
17
|
class FetchUrlError < RuntimeError; end
|
17
18
|
class NgrokError < RuntimeError; end
|
@@ -26,6 +27,7 @@ module ShopifyCli
|
|
26
27
|
|
27
28
|
NGROK_TUNNELS_URI = URI.parse("http://localhost:4040/api/tunnels")
|
28
29
|
TUNNELS_FIELD = "tunnels"
|
30
|
+
TUNNEL_ADDRESS_KEY_PATH = ["config", "addr"]
|
29
31
|
PUBLIC_URL_FIELD = "public_url"
|
30
32
|
|
31
33
|
##
|
@@ -120,6 +122,25 @@ module ShopifyCli
|
|
120
122
|
[]
|
121
123
|
end
|
122
124
|
|
125
|
+
##
|
126
|
+
# Returns Boolean if a tunnel is running on a given port
|
127
|
+
#
|
128
|
+
# #### Parameters
|
129
|
+
#
|
130
|
+
# * `port` - port to check
|
131
|
+
#
|
132
|
+
# #### Returns
|
133
|
+
#
|
134
|
+
# * true / false
|
135
|
+
#
|
136
|
+
def running_on?(port)
|
137
|
+
extract_port = ->(tunnel) { URI(tunnel.dig(*TUNNEL_ADDRESS_KEY_PATH)).port }
|
138
|
+
matches_port = ->(occupied_port) { occupied_port == port }
|
139
|
+
stats.fetch(TUNNELS_FIELD, []).map(&extract_port).any?(&matches_port)
|
140
|
+
rescue
|
141
|
+
false
|
142
|
+
end
|
143
|
+
|
123
144
|
private
|
124
145
|
|
125
146
|
def install(ctx)
|
data/lib/shopify-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,8 +144,9 @@ files:
|
|
144
144
|
- lib/project_types/extension/features/argo.rb
|
145
145
|
- lib/project_types/extension/features/argo_config.rb
|
146
146
|
- lib/project_types/extension/features/argo_dependencies.rb
|
147
|
-
- lib/project_types/extension/features/
|
147
|
+
- lib/project_types/extension/features/argo_runtime.rb
|
148
148
|
- lib/project_types/extension/features/argo_serve.rb
|
149
|
+
- lib/project_types/extension/features/argo_serve_options.rb
|
149
150
|
- lib/project_types/extension/features/argo_setup.rb
|
150
151
|
- lib/project_types/extension/features/argo_setup_step.rb
|
151
152
|
- lib/project_types/extension/features/argo_setup_steps.rb
|
@@ -157,13 +158,16 @@ files:
|
|
157
158
|
- lib/project_types/extension/messages/messages.rb
|
158
159
|
- lib/project_types/extension/models/app.rb
|
159
160
|
- lib/project_types/extension/models/lazy_specification_handler.rb
|
161
|
+
- lib/project_types/extension/models/npm_package.rb
|
160
162
|
- lib/project_types/extension/models/registration.rb
|
161
163
|
- lib/project_types/extension/models/specification.rb
|
164
|
+
- lib/project_types/extension/models/specification_handlers/checkout_argo_extension.rb
|
162
165
|
- lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb
|
163
166
|
- lib/project_types/extension/models/specification_handlers/default.rb
|
164
167
|
- lib/project_types/extension/models/specifications.rb
|
165
168
|
- lib/project_types/extension/models/validation_error.rb
|
166
169
|
- lib/project_types/extension/models/version.rb
|
170
|
+
- lib/project_types/extension/tasks/choose_next_available_port.rb
|
167
171
|
- lib/project_types/extension/tasks/configure_features.rb
|
168
172
|
- lib/project_types/extension/tasks/converters/app_converter.rb
|
169
173
|
- lib/project_types/extension/tasks/converters/registration_converter.rb
|
@@ -171,6 +175,7 @@ files:
|
|
171
175
|
- lib/project_types/extension/tasks/converters/version_converter.rb
|
172
176
|
- lib/project_types/extension/tasks/create_extension.rb
|
173
177
|
- lib/project_types/extension/tasks/fetch_specifications.rb
|
178
|
+
- lib/project_types/extension/tasks/find_npm_packages.rb
|
174
179
|
- lib/project_types/extension/tasks/get_app.rb
|
175
180
|
- lib/project_types/extension/tasks/get_apps.rb
|
176
181
|
- lib/project_types/extension/tasks/update_draft.rb
|
@@ -222,23 +227,24 @@ files:
|
|
222
227
|
- lib/project_types/script/layers/application/extension_points.rb
|
223
228
|
- lib/project_types/script/layers/application/project_dependencies.rb
|
224
229
|
- lib/project_types/script/layers/application/push_script.rb
|
225
|
-
- lib/project_types/script/layers/domain/config_ui.rb
|
226
230
|
- lib/project_types/script/layers/domain/errors.rb
|
227
231
|
- lib/project_types/script/layers/domain/extension_point.rb
|
228
232
|
- lib/project_types/script/layers/domain/metadata.rb
|
229
233
|
- lib/project_types/script/layers/domain/push_package.rb
|
234
|
+
- lib/project_types/script/layers/domain/script_json.rb
|
230
235
|
- lib/project_types/script/layers/domain/script_project.rb
|
231
|
-
- lib/project_types/script/layers/infrastructure/
|
232
|
-
- lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb
|
236
|
+
- lib/project_types/script/layers/infrastructure/command_runner.rb
|
233
237
|
- lib/project_types/script/layers/infrastructure/errors.rb
|
234
238
|
- lib/project_types/script/layers/infrastructure/extension_point_repository.rb
|
235
|
-
- lib/project_types/script/layers/infrastructure/
|
239
|
+
- lib/project_types/script/layers/infrastructure/languages/assemblyscript_project_creator.rb
|
240
|
+
- lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb
|
241
|
+
- lib/project_types/script/layers/infrastructure/languages/project_creator.rb
|
242
|
+
- lib/project_types/script/layers/infrastructure/languages/rust_project_creator.rb
|
243
|
+
- lib/project_types/script/layers/infrastructure/languages/rust_task_runner.rb
|
244
|
+
- lib/project_types/script/layers/infrastructure/languages/task_runner.rb
|
236
245
|
- lib/project_types/script/layers/infrastructure/push_package_repository.rb
|
237
|
-
- lib/project_types/script/layers/infrastructure/rust_project_creator.rb
|
238
|
-
- lib/project_types/script/layers/infrastructure/rust_task_runner.rb
|
239
246
|
- lib/project_types/script/layers/infrastructure/script_project_repository.rb
|
240
247
|
- lib/project_types/script/layers/infrastructure/script_service.rb
|
241
|
-
- lib/project_types/script/layers/infrastructure/task_runner.rb
|
242
248
|
- lib/project_types/script/messages/messages.rb
|
243
249
|
- lib/project_types/script/tasks/ensure_env.rb
|
244
250
|
- lib/project_types/script/ui/error_handler.rb
|
@@ -465,7 +471,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
465
471
|
- !ruby/object:Gem::Version
|
466
472
|
version: '0'
|
467
473
|
requirements: []
|
468
|
-
rubygems_version: 3.
|
474
|
+
rubygems_version: 3.2.17
|
469
475
|
signing_key:
|
470
476
|
specification_version: 4
|
471
477
|
summary: Shopify CLI helps you build Shopify apps faster.
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Extension
|
2
|
-
module Features
|
3
|
-
class ArgoRendererPackage
|
4
|
-
include SmartProperties
|
5
|
-
|
6
|
-
ARGO_CHECKOUT = "@shopify/argo-checkout"
|
7
|
-
ARGO_ADMIN = "@shopify/argo-admin"
|
8
|
-
ARGO_POST_PURCHASE = "@shopify/argo-post-purchase"
|
9
|
-
|
10
|
-
PACKAGE_NAMES = [
|
11
|
-
ARGO_CHECKOUT,
|
12
|
-
ARGO_ADMIN,
|
13
|
-
ARGO_POST_PURCHASE,
|
14
|
-
].freeze
|
15
|
-
MINIMUM_ARGO_VERSION = "0.9.3".freeze
|
16
|
-
|
17
|
-
property! :package_name, accepts: PACKAGE_NAMES
|
18
|
-
property! :version, accepts: String
|
19
|
-
|
20
|
-
class << self
|
21
|
-
def from_package_manager(package_manager_output)
|
22
|
-
pattern = /(?<name>#{PACKAGE_NAMES.join("|")})@(?<version>\d.*)$/
|
23
|
-
match = package_manager_output.match(pattern)
|
24
|
-
raise PackageNotFound, package_manager_output if match.nil?
|
25
|
-
new(package_name: match[:name], version: match[:version].strip)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def checkout?
|
30
|
-
package_name == ARGO_CHECKOUT
|
31
|
-
end
|
32
|
-
|
33
|
-
def admin?
|
34
|
-
package_name == ARGO_ADMIN
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
# Temporarily returns false in all cases as the argo webpack server is
|
39
|
-
# unable to handle the UUID flag.
|
40
|
-
def supports_uuid_flag?
|
41
|
-
false
|
42
|
-
# return false if checkout?
|
43
|
-
# Gem::Version.new(version) > Gem::Version.new(MINIMUM_ARGO_VERSION)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
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,100 +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_name}.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
|
-
out, status = ctx.capture2e(bootstap_command)
|
26
|
-
raise Domain::Errors::ServiceFailureError, out unless status.success?
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def write_npmrc
|
32
|
-
ctx.system(
|
33
|
-
"npm", "--userconfig", "./.npmrc", "config", "set", "@shopify:registry", "https://registry.npmjs.com"
|
34
|
-
)
|
35
|
-
ctx.system(
|
36
|
-
"npm", "--userconfig", "./.npmrc", "config", "set", "engine-strict", "true"
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def extension_point_version
|
41
|
-
if extension_point.sdks.assemblyscript.versioned?
|
42
|
-
return extension_point.sdks.assemblyscript.version
|
43
|
-
end
|
44
|
-
|
45
|
-
out, status = ctx.capture2e("npm show #{extension_point.sdks.assemblyscript.package} version --json")
|
46
|
-
raise Domain::Errors::ServiceFailureError, out unless status.success?
|
47
|
-
"^#{JSON.parse(out)}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def write_package_json
|
51
|
-
package_json = <<~HERE
|
52
|
-
{
|
53
|
-
"name": "#{script_name}",
|
54
|
-
"version": "1.0.0",
|
55
|
-
"devDependencies": {
|
56
|
-
"@shopify/scripts-sdk-as": "#{extension_point.sdks.assemblyscript.sdk_version}",
|
57
|
-
"@shopify/scripts-toolchain-as": "#{extension_point.sdks.assemblyscript.toolchain_version}",
|
58
|
-
"#{extension_point.sdks.assemblyscript.package}": "#{extension_point_version}",
|
59
|
-
"@as-pect/cli": "^6.0.0",
|
60
|
-
"assemblyscript": "^0.18.13"
|
61
|
-
},
|
62
|
-
"scripts": {
|
63
|
-
"test": "asp --summary --verbose",
|
64
|
-
"build": "#{build_command}"
|
65
|
-
},
|
66
|
-
"engines": {
|
67
|
-
"node": ">=#{MIN_NODE_VERSION}"
|
68
|
-
}
|
69
|
-
}
|
70
|
-
HERE
|
71
|
-
ctx.write("package.json", package_json)
|
72
|
-
end
|
73
|
-
|
74
|
-
def bootstap_command
|
75
|
-
type = extension_point.dasherize_type
|
76
|
-
base_command = format(BOOTSTRAP, extension_point: type, base: path_to_project)
|
77
|
-
domain = extension_point.domain
|
78
|
-
|
79
|
-
if domain.nil?
|
80
|
-
base_command
|
81
|
-
else
|
82
|
-
"#{base_command} --domain #{domain}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def build_command
|
87
|
-
type = extension_point.dasherize_type
|
88
|
-
base_command = format(BUILD, script_name: script_name)
|
89
|
-
domain = extension_point.domain
|
90
|
-
|
91
|
-
if domain.nil?
|
92
|
-
"#{base_command} #{ASC_ARGS}"
|
93
|
-
else
|
94
|
-
"#{base_command} --domain #{domain} --ep #{type} #{ASC_ARGS}"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,95 +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
|
-
|
67
|
-
out, status = ctx.capture2e(SCRIPT_SDK_BUILD)
|
68
|
-
raise Domain::Errors::ServiceFailureError, out unless status.success?
|
69
|
-
end
|
70
|
-
|
71
|
-
def check_compilation_dependencies!
|
72
|
-
pkg = JSON.parse(File.read("package.json"))
|
73
|
-
build_script = pkg.dig("scripts", "build")
|
74
|
-
|
75
|
-
raise Errors::BuildScriptNotFoundError,
|
76
|
-
"Build script not found" if build_script.nil?
|
77
|
-
|
78
|
-
unless build_script.start_with?("shopify-scripts")
|
79
|
-
raise Errors::InvalidBuildScriptError, "Invalid build script"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def bytecode
|
84
|
-
filename = format(BYTECODE_FILE, name: script_name)
|
85
|
-
raise Errors::WebAssemblyBinaryNotFoundError unless ctx.file_exist?(filename)
|
86
|
-
|
87
|
-
contents = ctx.binread(filename)
|
88
|
-
ctx.rm(filename)
|
89
|
-
|
90
|
-
contents
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|