klenod-build 0.0.5 → 0.0.6
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/lib/klenod/build/asset.rb +5 -3
- data/lib/klenod/build/config.rb +14 -4
- data/lib/klenod/build/context.rb +8 -1
- data/lib/klenod/build/graph.rb +21 -3
- data/lib/klenod/build/plugins/asset_javascript_metadata.rb +1 -1
- data/lib/klenod/build/plugins/google_fonts_plugin.rb +6 -4
- data/lib/klenod/build/plugins/image_plugin.rb +21 -19
- data/lib/klenod/build/plugins/svg_plugin.rb +14 -12
- data/lib/klenod/build/version.rb +1 -1
- metadata +12 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37a480cf40ba06385175cb0156563e300599b888366ea96b5a4c64dc5b7c2af9
|
|
4
|
+
data.tar.gz: 3aba70e34cb4e0c1c8328cea78682181f2079e28dbded35513f57a135becc405
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a86cb133c6ce093ef722b7f21b7f10402d80e80f3e8cdef85afb853420f0f552b1ccff4d6b42fb6565e0e898ea42ad713e98d385283842d12066b444fd27fbe
|
|
7
|
+
data.tar.gz: c7e07833d11dd65c47fcf702163157c62a8a670aa44c0017b14018ef658f646088700350b6ffe0e24cfeae475f7e4c5aa6d67b0325a5029904d8765958728a0c
|
data/lib/klenod/build/asset.rb
CHANGED
|
@@ -8,8 +8,9 @@ module Klenod
|
|
|
8
8
|
module Build
|
|
9
9
|
class Asset
|
|
10
10
|
attr_reader :logical_name, :content_hash, :output_path, :source_path, :content_type, :metadata, :queue_kind, :error
|
|
11
|
+
attr_accessor :url
|
|
11
12
|
|
|
12
|
-
def initialize(logical_name, content_hash, output_path, source_path, bytes, content_type, metadata, generator: nil, writer: nil, queue: nil, queue_kind: :cpu)
|
|
13
|
+
def initialize(logical_name, content_hash, output_path, source_path, bytes, content_type, metadata, url: nil, generator: nil, writer: nil, queue: nil, queue_kind: :cpu)
|
|
13
14
|
@logical_name = logical_name
|
|
14
15
|
@content_hash = content_hash
|
|
15
16
|
@output_path = output_path
|
|
@@ -17,6 +18,7 @@ module Klenod
|
|
|
17
18
|
@bytes = bytes
|
|
18
19
|
@content_type = content_type
|
|
19
20
|
@metadata = metadata
|
|
21
|
+
@url = url
|
|
20
22
|
@generator = generator
|
|
21
23
|
@writer = writer
|
|
22
24
|
@queue = queue
|
|
@@ -28,8 +30,8 @@ module Klenod
|
|
|
28
30
|
@error = nil
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
def self.generated(logical_name, content_hash, output_path, source_path, content_type, metadata, writer: nil, queue: nil, queue_kind: :cpu, &generator)
|
|
32
|
-
new(logical_name, content_hash, output_path, source_path, nil, content_type, metadata, generator: generator, writer: writer, queue: queue, queue_kind: queue_kind)
|
|
33
|
+
def self.generated(logical_name, content_hash, output_path, source_path, content_type, metadata, url: nil, writer: nil, queue: nil, queue_kind: :cpu, &generator)
|
|
34
|
+
new(logical_name, content_hash, output_path, source_path, nil, content_type, metadata, url:, generator: generator, writer: writer, queue: queue, queue_kind: queue_kind)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def bytes
|
data/lib/klenod/build/config.rb
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module Klenod
|
|
4
4
|
module Build
|
|
5
5
|
Config =
|
|
6
|
-
Data.define(:source_dir, :entrypoints, :output, :assets_dir, :plugins, :mode, :base_dir) do
|
|
7
|
-
def initialize(source_dir: "src", entrypoints: [], output: "dist/klenod.bundle", assets_dir: nil, plugins: Context::DEFAULT_PLUGINS, mode: :development, base_dir: Dir.pwd)
|
|
6
|
+
Data.define(:source_dir, :entrypoints, :output, :assets_dir, :plugins, :mode, :base_dir, :base) do
|
|
7
|
+
def initialize(source_dir: "src", entrypoints: [], output: "dist/klenod.bundle", assets_dir: nil, plugins: Context::DEFAULT_PLUGINS, mode: :development, base_dir: Dir.pwd, base: Runtime::AssetUrl::DEFAULT_BASE)
|
|
8
8
|
super(
|
|
9
9
|
source_dir: source_dir,
|
|
10
10
|
entrypoints: Array(entrypoints),
|
|
@@ -12,7 +12,8 @@ module Klenod
|
|
|
12
12
|
assets_dir: assets_dir,
|
|
13
13
|
plugins: plugins,
|
|
14
14
|
mode: mode,
|
|
15
|
-
base_dir: base_dir
|
|
15
|
+
base_dir: base_dir,
|
|
16
|
+
base: Runtime::AssetUrl.normalize(base)
|
|
16
17
|
)
|
|
17
18
|
end
|
|
18
19
|
|
|
@@ -25,6 +26,7 @@ module Klenod
|
|
|
25
26
|
source_dir: source_path,
|
|
26
27
|
plugins: plugins,
|
|
27
28
|
mode: mode,
|
|
29
|
+
base: base,
|
|
28
30
|
**overrides
|
|
29
31
|
)
|
|
30
32
|
end
|
|
@@ -60,6 +62,7 @@ module Klenod
|
|
|
60
62
|
@plugins = Context::DEFAULT_PLUGINS
|
|
61
63
|
@mode = :development
|
|
62
64
|
@base_dir = base_dir
|
|
65
|
+
@base = Runtime::AssetUrl::DEFAULT_BASE
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
def source_dir(value = nil)
|
|
@@ -100,6 +103,12 @@ module Klenod
|
|
|
100
103
|
@mode = value
|
|
101
104
|
end
|
|
102
105
|
|
|
106
|
+
def base(value = nil)
|
|
107
|
+
return @base unless value
|
|
108
|
+
|
|
109
|
+
@base = value
|
|
110
|
+
end
|
|
111
|
+
|
|
103
112
|
def config
|
|
104
113
|
Config.new(
|
|
105
114
|
source_dir: @source_dir,
|
|
@@ -108,7 +117,8 @@ module Klenod
|
|
|
108
117
|
assets_dir: @assets_dir,
|
|
109
118
|
plugins: @plugins,
|
|
110
119
|
mode: @mode,
|
|
111
|
-
base_dir: @base_dir
|
|
120
|
+
base_dir: @base_dir,
|
|
121
|
+
base: @base
|
|
112
122
|
)
|
|
113
123
|
end
|
|
114
124
|
end
|
data/lib/klenod/build/context.rb
CHANGED
|
@@ -108,6 +108,7 @@ module Klenod
|
|
|
108
108
|
source_dir:,
|
|
109
109
|
plugins: DEFAULT_PLUGINS,
|
|
110
110
|
mode: :development,
|
|
111
|
+
base: Runtime::AssetUrl::DEFAULT_BASE,
|
|
111
112
|
asset_generation_concurrency: AssetGenerationQueue::DEFAULT_CONCURRENCY,
|
|
112
113
|
asset_download_concurrency: AssetGenerationQueue::DEFAULT_DOWNLOAD_CONCURRENCY,
|
|
113
114
|
profiler: nil
|
|
@@ -116,19 +117,21 @@ module Klenod
|
|
|
116
117
|
plugins = plugins.to_a if plugins.equal?(DEFAULT_PLUGINS)
|
|
117
118
|
@plugins = plugins
|
|
118
119
|
@mode = mode
|
|
120
|
+
@base = Runtime::AssetUrl.normalize(base)
|
|
119
121
|
@update_handlers = []
|
|
120
122
|
@graph =
|
|
121
123
|
Graph.new(
|
|
122
124
|
source_dir: source_dir,
|
|
123
125
|
plugins: plugins,
|
|
124
126
|
mode: mode,
|
|
127
|
+
base: @base,
|
|
125
128
|
asset_generation_concurrency: asset_generation_concurrency,
|
|
126
129
|
asset_download_concurrency: asset_download_concurrency,
|
|
127
130
|
profiler: profiler
|
|
128
131
|
)
|
|
129
132
|
end
|
|
130
133
|
|
|
131
|
-
attr_reader :graph, :mode
|
|
134
|
+
attr_reader :graph, :mode, :base
|
|
132
135
|
|
|
133
136
|
def evaluate(specifier)
|
|
134
137
|
@graph.load(specifier)
|
|
@@ -177,6 +180,10 @@ module Klenod
|
|
|
177
180
|
@graph.asset(output_path)
|
|
178
181
|
end
|
|
179
182
|
|
|
183
|
+
def asset_url(asset_or_output_path)
|
|
184
|
+
@graph.asset_url(asset_or_output_path)
|
|
185
|
+
end
|
|
186
|
+
|
|
180
187
|
def exports(record_or_module_id)
|
|
181
188
|
return record_or_module_id.exports if record_or_module_id.is_a?(LoadedModule)
|
|
182
189
|
|
data/lib/klenod/build/graph.rb
CHANGED
|
@@ -56,13 +56,14 @@ module Klenod
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
attr_reader :records, :mods, :asset_generation_queue, :mode, :profiler
|
|
59
|
+
attr_reader :records, :mods, :asset_generation_queue, :mode, :profiler, :base
|
|
60
60
|
attr_reader :plugins
|
|
61
61
|
|
|
62
62
|
def initialize(
|
|
63
63
|
source_dir:,
|
|
64
64
|
plugins:,
|
|
65
65
|
mode: :development,
|
|
66
|
+
base: Runtime::AssetUrl::DEFAULT_BASE,
|
|
66
67
|
asset_generation_concurrency: AssetGenerationQueue::DEFAULT_CONCURRENCY,
|
|
67
68
|
asset_download_concurrency: AssetGenerationQueue::DEFAULT_DOWNLOAD_CONCURRENCY,
|
|
68
69
|
profiler: nil
|
|
@@ -71,6 +72,7 @@ module Klenod
|
|
|
71
72
|
@resolver = Resolver.new(source_dir: source_dir, profiler: @profiler)
|
|
72
73
|
@plugins = plugins
|
|
73
74
|
@mode = mode
|
|
75
|
+
@base = Runtime::AssetUrl.normalize(base)
|
|
74
76
|
@asset_generation_queue =
|
|
75
77
|
AssetGenerationQueue.new(
|
|
76
78
|
concurrency: asset_generation_concurrency,
|
|
@@ -112,7 +114,8 @@ module Klenod
|
|
|
112
114
|
loaded_entrypoints,
|
|
113
115
|
runtime_module_specs,
|
|
114
116
|
runtime_asset_specs,
|
|
115
|
-
source_root: source_dir.to_s
|
|
117
|
+
source_root: source_dir.to_s,
|
|
118
|
+
base: base
|
|
116
119
|
)
|
|
117
120
|
end
|
|
118
121
|
end
|
|
@@ -125,6 +128,15 @@ module Klenod
|
|
|
125
128
|
assets.fetch(output_path)
|
|
126
129
|
end
|
|
127
130
|
|
|
131
|
+
def asset_url(asset_or_output_path)
|
|
132
|
+
if asset_or_output_path.respond_to?(:output_path)
|
|
133
|
+
asset = assets.fetch(asset_or_output_path.output_path, asset_or_output_path)
|
|
134
|
+
return asset.url || Runtime::AssetUrl.join(base, asset.output_path)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
Runtime::AssetUrl.join(base, asset_or_output_path)
|
|
138
|
+
end
|
|
139
|
+
|
|
128
140
|
def exports(record_or_module_id)
|
|
129
141
|
module_id = module_id_for(record_or_module_id)
|
|
130
142
|
evaluate_module(module_id).const_get(:Exports)
|
|
@@ -574,6 +586,7 @@ module Klenod
|
|
|
574
586
|
end
|
|
575
587
|
|
|
576
588
|
def build_module_record(module_id, source, source_hash, transformed_hash, transform, resolved_dependencies, cached_or_mod)
|
|
589
|
+
bind_asset_urls(transform.assets)
|
|
577
590
|
version =
|
|
578
591
|
if cached_or_mod.is_a?(Runtime::Mod)
|
|
579
592
|
cached_or_mod.version
|
|
@@ -600,6 +613,10 @@ module Klenod
|
|
|
600
613
|
)
|
|
601
614
|
end
|
|
602
615
|
|
|
616
|
+
def bind_asset_urls(assets)
|
|
617
|
+
assets.each { |asset| asset.url ||= Runtime::AssetUrl.join(base, asset.output_path) }
|
|
618
|
+
end
|
|
619
|
+
|
|
603
620
|
def load_dependency_records(resolved_dependencies)
|
|
604
621
|
return {} if resolved_dependencies.empty?
|
|
605
622
|
|
|
@@ -771,7 +788,8 @@ module Klenod
|
|
|
771
788
|
asset.content_hash,
|
|
772
789
|
asset.output_path,
|
|
773
790
|
asset.content_type,
|
|
774
|
-
asset.metadata
|
|
791
|
+
asset.metadata,
|
|
792
|
+
asset.url
|
|
775
793
|
)
|
|
776
794
|
]
|
|
777
795
|
end
|
|
@@ -172,13 +172,14 @@ module Klenod
|
|
|
172
172
|
font_url = Regexp.last_match[:url]
|
|
173
173
|
asset = font_assets[font_url] ||= font_asset(font_url, font_faces[font_url], context)
|
|
174
174
|
|
|
175
|
-
%(url(#{quote}#{asset.
|
|
175
|
+
%(url(#{quote}#{asset.url}#{quote}))
|
|
176
176
|
end
|
|
177
177
|
rewritten_css = append_fallback_font_faces(rewritten_css, font_faces.values) if @adjust_font_fallback
|
|
178
178
|
|
|
179
179
|
css_asset = css_asset(module_id, url, rewritten_css, font_assets.keys)
|
|
180
|
+
css_asset.url = context.asset_url(css_asset.output_path)
|
|
180
181
|
@assets_by_module_id[module_id] = [css_asset, *font_assets.values]
|
|
181
|
-
ruby_module_source(css_asset.
|
|
182
|
+
ruby_module_source(css_asset.url)
|
|
182
183
|
end
|
|
183
184
|
|
|
184
185
|
def transform(module_id, code, _context)
|
|
@@ -242,7 +243,7 @@ module Klenod
|
|
|
242
243
|
|
|
243
244
|
def css_asset(module_id, url, css, font_source_urls)
|
|
244
245
|
hash = Hashing.short(css)
|
|
245
|
-
output_path = "
|
|
246
|
+
output_path = "/#{google_fonts_asset_name(url)}.#{hash}.css"
|
|
246
247
|
|
|
247
248
|
Asset.new(
|
|
248
249
|
module_id.to_s,
|
|
@@ -296,7 +297,7 @@ module Klenod
|
|
|
296
297
|
hash = Hashing.short(url)
|
|
297
298
|
uri = URI.parse(url)
|
|
298
299
|
extname = File.extname(uri.path)
|
|
299
|
-
output_path = "
|
|
300
|
+
output_path = "/#{font_asset_name(uri, font_face)}.#{hash}#{extname}"
|
|
300
301
|
|
|
301
302
|
Asset.generated(
|
|
302
303
|
url,
|
|
@@ -314,6 +315,7 @@ module Klenod
|
|
|
314
315
|
},
|
|
315
316
|
writer: ->(io) { write_fetch(url, io) },
|
|
316
317
|
queue: context.asset_generation_queue,
|
|
318
|
+
url: context.asset_url(output_path),
|
|
317
319
|
queue_kind: :io
|
|
318
320
|
) do
|
|
319
321
|
fetch(url)
|
|
@@ -51,7 +51,9 @@ module Klenod
|
|
|
51
51
|
image_options = image_options_for(module_id)
|
|
52
52
|
asset = default_image_asset(module_id, source_path, source_hash, dimensions, image_options, context.asset_generation_queue)
|
|
53
53
|
variant_assets = generate_variant_assets(module_id, source_path, source_hash, dimensions, image_options, context.asset_generation_queue)
|
|
54
|
-
|
|
54
|
+
[asset, *variant_assets].each { |image_asset| image_asset.url = context.asset_url(image_asset.output_path) }
|
|
55
|
+
javascript_asset = javascript_image_asset(module_id, asset, variant_assets, context)
|
|
56
|
+
javascript_asset.url = context.asset_url(javascript_asset.output_path)
|
|
55
57
|
assets = [asset, *variant_assets]
|
|
56
58
|
image_runtime_dependency =
|
|
57
59
|
Dependency
|
|
@@ -64,7 +66,7 @@ module Klenod
|
|
|
64
66
|
|
|
65
67
|
transform =
|
|
66
68
|
TransformResult.new(
|
|
67
|
-
image_module_source(module_id, assets, image_runtime_dependency),
|
|
69
|
+
image_module_source(module_id, assets, image_runtime_dependency, context),
|
|
68
70
|
[image_runtime_dependency],
|
|
69
71
|
nil,
|
|
70
72
|
assets,
|
|
@@ -126,7 +128,7 @@ module Klenod
|
|
|
126
128
|
Asset.new(
|
|
127
129
|
module_id.path,
|
|
128
130
|
hash,
|
|
129
|
-
"
|
|
131
|
+
"/#{asset_name(module_id)}.#{hash}#{module_id.extname}",
|
|
130
132
|
source_path,
|
|
131
133
|
nil,
|
|
132
134
|
content_type(module_id.extname),
|
|
@@ -154,7 +156,7 @@ module Klenod
|
|
|
154
156
|
Asset.generated(
|
|
155
157
|
module_id.path,
|
|
156
158
|
hash,
|
|
157
|
-
"
|
|
159
|
+
"/#{asset_name(module_id)}.#{hash}#{extname}",
|
|
158
160
|
source_path,
|
|
159
161
|
content_type(extname),
|
|
160
162
|
metadata,
|
|
@@ -217,15 +219,15 @@ module Klenod
|
|
|
217
219
|
"# image asset: #{module_id}\n"
|
|
218
220
|
end
|
|
219
221
|
|
|
220
|
-
def image_module_source(module_id, assets, image_runtime_dependency)
|
|
222
|
+
def image_module_source(module_id, assets, image_runtime_dependency, context)
|
|
221
223
|
asset = image_asset(assets)
|
|
222
|
-
variants = image_variant_assets(assets).map { |variant_asset| image_variant_source(variant_asset) }
|
|
224
|
+
variants = image_variant_assets(assets).map { |variant_asset| image_variant_source(variant_asset, context) }
|
|
223
225
|
|
|
224
226
|
<<~RUBY
|
|
225
227
|
ImageRuntime = __klenod_import__(#{image_runtime_dependency.id.inspect})
|
|
226
228
|
Default =
|
|
227
229
|
ImageRuntime::ImageMetadata.new(
|
|
228
|
-
src: #{asset.
|
|
230
|
+
src: #{asset.url.inspect},
|
|
229
231
|
width: #{asset.metadata[:width].inspect},
|
|
230
232
|
height: #{asset.metadata[:height].inspect},
|
|
231
233
|
content_type: #{asset.content_type.inspect},
|
|
@@ -238,10 +240,10 @@ module Klenod
|
|
|
238
240
|
RUBY
|
|
239
241
|
end
|
|
240
242
|
|
|
241
|
-
def image_variant_source(asset)
|
|
243
|
+
def image_variant_source(asset, context)
|
|
242
244
|
<<~RUBY.chomp
|
|
243
245
|
ImageRuntime::ImageVariant.new(
|
|
244
|
-
src: #{asset.
|
|
246
|
+
src: #{asset.url.inspect},
|
|
245
247
|
width: #{asset.metadata[:width].inspect},
|
|
246
248
|
height: #{asset.metadata[:height].inspect},
|
|
247
249
|
content_type: #{asset.content_type.inspect},
|
|
@@ -253,13 +255,13 @@ module Klenod
|
|
|
253
255
|
RUBY
|
|
254
256
|
end
|
|
255
257
|
|
|
256
|
-
def javascript_image_asset(module_id, asset, variant_assets)
|
|
257
|
-
code = javascript_image_module_source(asset, variant_assets)
|
|
258
|
+
def javascript_image_asset(module_id, asset, variant_assets, context)
|
|
259
|
+
code = javascript_image_module_source(asset, variant_assets, context)
|
|
258
260
|
hash = Hashing.short(code)
|
|
259
261
|
Asset.new(
|
|
260
262
|
module_id.path,
|
|
261
263
|
hash,
|
|
262
|
-
"
|
|
264
|
+
"/#{asset_name(module_id)}.#{hash}#{module_id.extname}.js",
|
|
263
265
|
nil,
|
|
264
266
|
code,
|
|
265
267
|
"application/javascript",
|
|
@@ -267,10 +269,10 @@ module Klenod
|
|
|
267
269
|
)
|
|
268
270
|
end
|
|
269
271
|
|
|
270
|
-
def javascript_image_module_source(asset, variant_assets)
|
|
271
|
-
variants = variant_assets.map { "new ImageVariant(#{AssetJavaScriptMetadata.object_literal(javascript_image_variant(it))})" }
|
|
272
|
+
def javascript_image_module_source(asset, variant_assets, context)
|
|
273
|
+
variants = variant_assets.map { "new ImageVariant(#{AssetJavaScriptMetadata.object_literal(javascript_image_variant(it, context))})" }
|
|
272
274
|
properties = {
|
|
273
|
-
src: asset.
|
|
275
|
+
src: asset.url,
|
|
274
276
|
width: asset.metadata[:width],
|
|
275
277
|
height: asset.metadata[:height],
|
|
276
278
|
contentType: asset.content_type,
|
|
@@ -279,14 +281,14 @@ module Klenod
|
|
|
279
281
|
properties << %(variants:[#{variants.join(",")}])
|
|
280
282
|
|
|
281
283
|
<<~JAVASCRIPT
|
|
282
|
-
import ImageMetadata, { ImageVariant } from #{AssetJavaScriptMetadata::OUTPUT_PATH.inspect};
|
|
284
|
+
import ImageMetadata, { ImageVariant } from #{context.asset_url(AssetJavaScriptMetadata::OUTPUT_PATH).inspect};
|
|
283
285
|
export default new ImageMetadata({#{properties.join(",")}});
|
|
284
286
|
JAVASCRIPT
|
|
285
287
|
end
|
|
286
288
|
|
|
287
|
-
def javascript_image_variant(asset)
|
|
289
|
+
def javascript_image_variant(asset, context)
|
|
288
290
|
{
|
|
289
|
-
src: asset.
|
|
291
|
+
src: asset.url,
|
|
290
292
|
width: asset.metadata[:width],
|
|
291
293
|
height: asset.metadata[:height],
|
|
292
294
|
contentType: asset.content_type,
|
|
@@ -338,7 +340,7 @@ module Klenod
|
|
|
338
340
|
extname = ".#{format}"
|
|
339
341
|
descriptor = "#{width}w"
|
|
340
342
|
hash = Hashing.short("#{source_hash}:#{width}:#{format}:#{quality}")
|
|
341
|
-
output_path = "
|
|
343
|
+
output_path = "/#{asset_name(module_id)}.#{width}w.#{hash}#{extname}"
|
|
342
344
|
metadata = {
|
|
343
345
|
type: :image_variant,
|
|
344
346
|
width: width,
|
|
@@ -34,14 +34,14 @@ module Klenod
|
|
|
34
34
|
svg_runtime_source
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def transform(module_id, code,
|
|
37
|
+
def transform(module_id, code, context)
|
|
38
38
|
return super unless EXTENSIONS.include?(module_id.extname)
|
|
39
39
|
|
|
40
40
|
raise UnsupportedFileError, "SVG imports do not support query options: #{module_id}" if module_id.query
|
|
41
41
|
|
|
42
42
|
dimensions = svg_dimensions(code)
|
|
43
43
|
hash = Hashing.short(code)
|
|
44
|
-
output_path = "
|
|
44
|
+
output_path = "/#{asset_name(module_id)}.#{hash}.svg"
|
|
45
45
|
asset =
|
|
46
46
|
Asset.new(
|
|
47
47
|
module_id.path,
|
|
@@ -56,7 +56,9 @@ module Klenod
|
|
|
56
56
|
height: dimensions.height
|
|
57
57
|
}
|
|
58
58
|
)
|
|
59
|
-
|
|
59
|
+
asset.url = context.asset_url(asset.output_path)
|
|
60
|
+
javascript_asset = javascript_svg_asset(module_id, asset, context)
|
|
61
|
+
javascript_asset.url = context.asset_url(javascript_asset.output_path)
|
|
60
62
|
svg_runtime_dependency =
|
|
61
63
|
Dependency
|
|
62
64
|
.create(
|
|
@@ -67,7 +69,7 @@ module Klenod
|
|
|
67
69
|
.with(id: "#{module_id}:svg_runtime")
|
|
68
70
|
|
|
69
71
|
TransformResult.new(
|
|
70
|
-
svg_module_source(asset, svg_runtime_dependency),
|
|
72
|
+
svg_module_source(asset, svg_runtime_dependency, context),
|
|
71
73
|
[svg_runtime_dependency],
|
|
72
74
|
nil,
|
|
73
75
|
[asset],
|
|
@@ -100,12 +102,12 @@ module Klenod
|
|
|
100
102
|
RUBY
|
|
101
103
|
end
|
|
102
104
|
|
|
103
|
-
def svg_module_source(asset, svg_runtime_dependency)
|
|
105
|
+
def svg_module_source(asset, svg_runtime_dependency, context)
|
|
104
106
|
<<~RUBY
|
|
105
107
|
SvgRuntime = __klenod_import__(#{svg_runtime_dependency.id.inspect})
|
|
106
108
|
Default =
|
|
107
109
|
SvgRuntime::SvgMetadata.new(
|
|
108
|
-
src: #{asset.
|
|
110
|
+
src: #{asset.url.inspect},
|
|
109
111
|
width: #{asset.metadata[:width].inspect},
|
|
110
112
|
height: #{asset.metadata[:height].inspect},
|
|
111
113
|
content_type: #{asset.content_type.inspect},
|
|
@@ -115,13 +117,13 @@ module Klenod
|
|
|
115
117
|
RUBY
|
|
116
118
|
end
|
|
117
119
|
|
|
118
|
-
def javascript_svg_asset(module_id, asset)
|
|
119
|
-
code = javascript_svg_module_source(asset)
|
|
120
|
+
def javascript_svg_asset(module_id, asset, context)
|
|
121
|
+
code = javascript_svg_module_source(asset, context)
|
|
120
122
|
hash = Hashing.short(code)
|
|
121
123
|
Asset.new(
|
|
122
124
|
module_id.path,
|
|
123
125
|
hash,
|
|
124
|
-
"
|
|
126
|
+
"/#{asset_name(module_id)}.#{hash}#{module_id.extname}.js",
|
|
125
127
|
nil,
|
|
126
128
|
code,
|
|
127
129
|
"application/javascript",
|
|
@@ -129,9 +131,9 @@ module Klenod
|
|
|
129
131
|
)
|
|
130
132
|
end
|
|
131
133
|
|
|
132
|
-
def javascript_svg_module_source(asset)
|
|
134
|
+
def javascript_svg_module_source(asset, context)
|
|
133
135
|
metadata = {
|
|
134
|
-
src: asset.
|
|
136
|
+
src: asset.url,
|
|
135
137
|
width: asset.metadata[:width],
|
|
136
138
|
height: asset.metadata[:height],
|
|
137
139
|
contentType: asset.content_type,
|
|
@@ -139,7 +141,7 @@ module Klenod
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
<<~JAVASCRIPT
|
|
142
|
-
import { SvgMetadata } from #{AssetJavaScriptMetadata::OUTPUT_PATH.inspect};
|
|
144
|
+
import { SvgMetadata } from #{context.asset_url(AssetJavaScriptMetadata::OUTPUT_PATH).inspect};
|
|
143
145
|
export default new SvgMetadata(#{AssetJavaScriptMetadata.object_literal(metadata)});
|
|
144
146
|
JAVASCRIPT
|
|
145
147
|
end
|
data/lib/klenod/build/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-build
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0.
|
|
18
|
+
version: 0.0.6
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0.
|
|
25
|
+
version: 0.0.6
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: async
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -41,16 +41,22 @@ dependencies:
|
|
|
41
41
|
name: async-http
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
|
-
- - "
|
|
44
|
+
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
46
|
version: 0.95.1
|
|
47
|
+
- - "<"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 0.104.0
|
|
47
50
|
type: :runtime
|
|
48
51
|
prerelease: false
|
|
49
52
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
53
|
requirements:
|
|
51
|
-
- - "
|
|
54
|
+
- - ">="
|
|
52
55
|
- !ruby/object:Gem::Version
|
|
53
56
|
version: 0.95.1
|
|
57
|
+
- - "<"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 0.104.0
|
|
54
60
|
- !ruby/object:Gem::Dependency
|
|
55
61
|
name: brotli
|
|
56
62
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -297,7 +303,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
297
303
|
requirements:
|
|
298
304
|
- - ">="
|
|
299
305
|
- !ruby/object:Gem::Version
|
|
300
|
-
version: 4.0
|
|
306
|
+
version: '4.0'
|
|
301
307
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
308
|
requirements:
|
|
303
309
|
- - ">="
|