Class: Extension::Models::SpecificationHandlers::ThemeAppExtension
- Inherits:
-
Default
- Object
- Default
- Extension::Models::SpecificationHandlers::ThemeAppExtension
show all
- Defined in:
- lib/project_types/extension/models/specification_handlers/theme_app_extension.rb
Constant Summary
collapse
- SUPPORTED_BUCKETS =
%w(assets blocks snippets locales)
- BUNDLE_SIZE_LIMIT =
10 * 1024 * 1024
- LIQUID_SIZE_LIMIT =
100 * 1024
- SUPPORTED_ASSET_EXTS =
%w(.jpg .js .css .png .svg)
- SUPPORTED_LOCALE_EXTS =
%w(.json)
Instance Attribute Summary
Attributes inherited from Default
#specification
Instance Method Summary
collapse
Methods inherited from Default
#argo_runtime, #build_resource_url, #cli_package, #extension_context, #graphql_identifier, #identifier, #initialize, #message_for_extension, #renderer_package, #server_config_file, #server_config_path, #supplies_resource_url?, #tagline, #valid_extension_contexts
Instance Method Details
#choose_port?(_ctx) ⇒ Boolean
68
69
70
|
# File 'lib/project_types/extension/models/specification_handlers/theme_app_extension.rb', line 68
def choose_port?(_ctx)
false
end
|
#config(context) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/project_types/extension/models/specification_handlers/theme_app_extension.rb', line 27
def config(context)
current_size = 0
current_liquid_size = 0
Dir.chdir(context.root) do
Dir["**/*"].select { |filename| File.file?(filename) && validate(filename) }
.map do |filename|
dirname = File.dirname(filename)
if dirname == "assets"
mode = "rb"
encoding = "BINARY"
else
mode = "rt"
encoding = "UTF-8"
if dirname == "snippets" || dirname == "blocks"
current_liquid_size += File.size(filename)
end
end
current_size += File.size(filename)
if current_size > BUNDLE_SIZE_LIMIT
raise Extension::Errors::BundleTooLargeError,
"Total size of all files must be less than #{CLI::Kit::Util.to_filesize(BUNDLE_SIZE_LIMIT)}"
end
if current_liquid_size > LIQUID_SIZE_LIMIT
raise Extension::Errors::BundleTooLargeError,
"Total size of all liquid must be less than #{CLI::Kit::Util.to_filesize(LIQUID_SIZE_LIMIT)}"
end
[filename, Base64.encode64(File.read(filename, mode: mode, encoding: encoding))]
end
.yield_self do |encoded_files_by_name|
{ "theme_extension" => { "files" => encoded_files_by_name.to_h } }
end
end
end
|
#create(directory_name, context, getting_started: false) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/project_types/extension/models/specification_handlers/theme_app_extension.rb', line 16
def create(directory_name, context, getting_started: false)
context.root = File.join(context.root, directory_name)
if getting_started
ShopifyCLI::Git.clone("https://github.com/Shopify/theme-extension-getting-started", context.root)
context.rm_r(".git")
else
FileUtils.makedirs(SUPPORTED_BUCKETS.map { |b| File.join(context.root, b) })
end
end
|
#establish_tunnel?(_ctx) ⇒ Boolean
72
73
74
|
# File 'lib/project_types/extension/models/specification_handlers/theme_app_extension.rb', line 72
def establish_tunnel?(_ctx)
false
end
|
#name ⇒ Object
64
65
66
|
# File 'lib/project_types/extension/models/specification_handlers/theme_app_extension.rb', line 64
def name
"Theme App Extension"
end
|
#serve(**options) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/project_types/extension/models/specification_handlers/theme_app_extension.rb', line 76
def serve(**options)
@ctx = options[:context]
root = options[:context]&.root
project = options[:project]
properties = options
.slice(:port, :theme, :generate_tmp_theme)
.compact
.merge({
project: project,
specification_handler: self,
})
ShopifyCLI::Theme::Extension::DevServer.start(@ctx, root, **properties)
end
|