pakyow-assets 0.1.2 → 1.0.0.rc1
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 +5 -5
- data/LICENSE +3 -19
- data/lib/pakyow/assets.rb +19 -0
- data/lib/pakyow/assets/actions/process.rb +63 -0
- data/lib/pakyow/assets/actions/public.rb +75 -0
- data/lib/pakyow/assets/asset.rb +238 -0
- data/lib/pakyow/assets/babel.rb +34 -0
- data/lib/pakyow/assets/behavior/assets.rb +45 -0
- data/lib/pakyow/assets/behavior/config.rb +137 -0
- data/lib/pakyow/assets/behavior/externals.rb +58 -0
- data/lib/pakyow/assets/behavior/packs.rb +162 -0
- data/lib/pakyow/assets/behavior/prelaunching.rb +19 -0
- data/lib/pakyow/assets/behavior/processing.rb +27 -0
- data/lib/pakyow/assets/behavior/rendering/install_assets.rb +39 -0
- data/lib/pakyow/assets/behavior/silencing.rb +35 -0
- data/lib/pakyow/assets/behavior/watching.rb +25 -0
- data/lib/pakyow/assets/errors.rb +16 -0
- data/lib/pakyow/assets/external.rb +103 -0
- data/lib/pakyow/assets/framework.rb +52 -0
- data/lib/pakyow/assets/pack.rb +171 -0
- data/lib/pakyow/assets/precompiler.rb +63 -0
- data/lib/pakyow/assets/source_map.rb +99 -0
- data/lib/pakyow/assets/tasks/precompile.rake +9 -0
- data/lib/pakyow/assets/tasks/update.rake +20 -0
- data/lib/pakyow/assets/types/css.rb +45 -0
- data/lib/pakyow/assets/types/js.rb +98 -0
- data/lib/pakyow/assets/types/sass.rb +69 -0
- data/lib/pakyow/assets/types/scss.rb +14 -0
- data/src/@babel/standalone@7.3.1/babel.min.js +165 -0
- data/src/@babel/standalone@7.4.5/babel.min.js +92359 -0
- metadata +146 -46
- data/CHANGELOG.md +0 -18
- data/README.md +0 -58
- data/lib/assets.rb +0 -221
- data/lib/config.rb +0 -37
- data/lib/middleware.rb +0 -42
- data/lib/pakyow-assets.rb +0 -31
- data/lib/preprocessors/css-preprocessor.rb +0 -16
- data/lib/preprocessors/image-preprocessor.rb +0 -1
- data/lib/preprocessors/javascript-preprocessor.rb +0 -16
- data/lib/preprocessors/sass-preprocessor.rb +0 -23
- data/lib/version.rb +0 -5
- data/pakyow-assets.gemspec +0 -21
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/extension"
|
4
|
+
|
5
|
+
require "pakyow/assets/asset"
|
6
|
+
|
7
|
+
module Pakyow
|
8
|
+
module Assets
|
9
|
+
module Behavior
|
10
|
+
# Registers assets from the app's frontend/assets directory.
|
11
|
+
#
|
12
|
+
module Assets
|
13
|
+
extend Support::Extension
|
14
|
+
|
15
|
+
apply_extension do
|
16
|
+
after "load", "load.assets" do
|
17
|
+
config.assets.paths.each do |assets_path|
|
18
|
+
Dir.glob(File.join(assets_path, "**/*")) do |path|
|
19
|
+
next if config.assets.packs.paths.any? { |packs_path|
|
20
|
+
path.start_with?(packs_path)
|
21
|
+
} || File.basename(path).start_with?("_")
|
22
|
+
|
23
|
+
if config.assets.extensions.include?(File.extname(path))
|
24
|
+
prefix = if is_a?(Plugin)
|
25
|
+
self.class.mount_path
|
26
|
+
else
|
27
|
+
"/"
|
28
|
+
end
|
29
|
+
|
30
|
+
self.class.asset << Asset.new_from_path(
|
31
|
+
path,
|
32
|
+
config: config.assets,
|
33
|
+
source_location: assets_path,
|
34
|
+
prefix: prefix,
|
35
|
+
related: state(:asset)
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/extension"
|
4
|
+
require "pakyow/support/path_version"
|
5
|
+
|
6
|
+
module Pakyow
|
7
|
+
module Assets
|
8
|
+
module Behavior
|
9
|
+
module Config
|
10
|
+
extend Support::Extension
|
11
|
+
|
12
|
+
apply_extension do
|
13
|
+
configurable :assets do
|
14
|
+
setting :types,
|
15
|
+
av: %w(.webm .snd .au .aiff .mp3 .mp2 .m2a .m3a .ogx .gg .oga .midi .mid .avi .wav .wave .mp4 .m4v .acc .m4a .flac),
|
16
|
+
data: %w(.json .xml .yml .yaml),
|
17
|
+
fonts: %w(.eot .otf .ttf .woff .woff2),
|
18
|
+
images: %w(.ico .bmp .gif .webp .png .jpg .jpeg .tiff .tif .svg),
|
19
|
+
scripts: %w(.js),
|
20
|
+
styles: %w(.css .sass .scss)
|
21
|
+
|
22
|
+
setting :extensions do
|
23
|
+
config.assets.types.values.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
setting :public, true
|
27
|
+
setting :process, true
|
28
|
+
setting :cache, false
|
29
|
+
setting :minify, false
|
30
|
+
setting :fingerprint, false
|
31
|
+
setting :prefix, "/assets"
|
32
|
+
setting :silent, true
|
33
|
+
setting :source_maps, true
|
34
|
+
|
35
|
+
setting :public_path do
|
36
|
+
File.join(config.root, "public")
|
37
|
+
end
|
38
|
+
|
39
|
+
setting :path do
|
40
|
+
File.join(config.presenter.path, "assets")
|
41
|
+
end
|
42
|
+
|
43
|
+
setting :paths do
|
44
|
+
[
|
45
|
+
config.assets.path
|
46
|
+
]
|
47
|
+
end
|
48
|
+
|
49
|
+
setting :compile_path do
|
50
|
+
config.assets.public_path
|
51
|
+
end
|
52
|
+
|
53
|
+
setting :version do
|
54
|
+
Support::PathVersion.build(config.assets.path, config.assets.public_path)
|
55
|
+
end
|
56
|
+
|
57
|
+
defaults :production do
|
58
|
+
setting :minify, true
|
59
|
+
setting :fingerprint, true
|
60
|
+
setting :process, false
|
61
|
+
setting :cache, true
|
62
|
+
setting :silent, false
|
63
|
+
end
|
64
|
+
|
65
|
+
configurable :packs do
|
66
|
+
setting :autoload, %i[pakyow]
|
67
|
+
|
68
|
+
setting :path do
|
69
|
+
File.join(config.assets.path, "packs")
|
70
|
+
end
|
71
|
+
|
72
|
+
setting :paths do
|
73
|
+
[
|
74
|
+
config.assets.packs.path,
|
75
|
+
config.assets.externals.path
|
76
|
+
]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
configurable :externals do
|
81
|
+
setting :fetch, true
|
82
|
+
setting :pakyow, true
|
83
|
+
setting :provider, "https://unpkg.com/"
|
84
|
+
setting :scripts, []
|
85
|
+
|
86
|
+
setting :path do
|
87
|
+
File.join(config.assets.packs.path, "vendor")
|
88
|
+
end
|
89
|
+
|
90
|
+
defaults :test do
|
91
|
+
setting :fetch, false
|
92
|
+
end
|
93
|
+
|
94
|
+
defaults :production do
|
95
|
+
setting :fetch, false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
configurable :babel do
|
100
|
+
setting :presets, ["es2015"]
|
101
|
+
|
102
|
+
setting :source_maps do
|
103
|
+
config.assets.source_maps
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
configurable :uglifier do
|
108
|
+
configurable :source_map do
|
109
|
+
setting :sources_content, true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
configurable :sass do
|
114
|
+
setting :cache, false
|
115
|
+
setting :omit_source_map_url, true
|
116
|
+
setting :source_map_contents, true
|
117
|
+
|
118
|
+
setting :load_paths do
|
119
|
+
[
|
120
|
+
config.assets.path
|
121
|
+
]
|
122
|
+
end
|
123
|
+
|
124
|
+
setting :style do
|
125
|
+
if config.assets.minify
|
126
|
+
:compressed
|
127
|
+
else
|
128
|
+
:nested
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/extension"
|
4
|
+
|
5
|
+
require "pakyow/assets/external"
|
6
|
+
|
7
|
+
module Pakyow
|
8
|
+
module Assets
|
9
|
+
module Behavior
|
10
|
+
module Externals
|
11
|
+
extend Support::Extension
|
12
|
+
|
13
|
+
def external_script(name, version = nil, package: nil, files: nil)
|
14
|
+
assets_config = if is_a?(Plugin)
|
15
|
+
parent.config.assets
|
16
|
+
else
|
17
|
+
config.assets
|
18
|
+
end
|
19
|
+
|
20
|
+
assets_config.externals.scripts << External.new(
|
21
|
+
name, version: version, package: package, files: files, config: assets_config
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
apply_extension do
|
26
|
+
after "boot", "fetch.assets.externals" do
|
27
|
+
if config.assets.externals.pakyow
|
28
|
+
external_script :pakyow, "^1.0.0-alpha.17", package: "@pakyow/js", files: [
|
29
|
+
"dist/pakyow.js",
|
30
|
+
"dist/components/confirmable.js",
|
31
|
+
"dist/components/form.js",
|
32
|
+
"dist/components/freshener.js",
|
33
|
+
"dist/components/navigable.js",
|
34
|
+
"dist/components/socket.js"
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
if config.assets.externals.fetch
|
39
|
+
fetched = false
|
40
|
+
|
41
|
+
config.assets.externals.scripts.each do |external_script|
|
42
|
+
unless external_script.exist?
|
43
|
+
external_script.fetch!
|
44
|
+
fetched = true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if fetched
|
49
|
+
FileUtils.mkdir_p "./tmp"
|
50
|
+
FileUtils.touch "./tmp/restart.txt"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/extension"
|
4
|
+
|
5
|
+
module Pakyow
|
6
|
+
module Assets
|
7
|
+
module Behavior
|
8
|
+
module Packs
|
9
|
+
extend Support::Extension
|
10
|
+
|
11
|
+
apply_extension do
|
12
|
+
after "initialize", "initialize.assets.packs", priority: :high do
|
13
|
+
config.assets.packs.paths.each do |packs_path|
|
14
|
+
Pathname.glob(File.join(packs_path, "*.*")).group_by { |path|
|
15
|
+
File.join(File.dirname(path), File.basename(path, File.extname(path)))
|
16
|
+
}.to_a.sort { |pack_a, pack_b|
|
17
|
+
pack_b[1] <=> pack_a[1]
|
18
|
+
}.uniq { |pack_path, _|
|
19
|
+
accessible_pack_path(pack_path)
|
20
|
+
}.map { |pack_path, pack_asset_paths|
|
21
|
+
[accessible_pack_path(pack_path), pack_asset_paths]
|
22
|
+
}.reverse.each do |pack_path, pack_asset_paths|
|
23
|
+
prefix = if is_a?(Plugin)
|
24
|
+
self.class.mount_path
|
25
|
+
else
|
26
|
+
"/"
|
27
|
+
end
|
28
|
+
|
29
|
+
asset_pack = Pack.new(File.basename(pack_path).to_sym, config.assets, prefix: prefix)
|
30
|
+
|
31
|
+
pack_asset_paths.each do |pack_asset_path|
|
32
|
+
if config.assets.extensions.include?(File.extname(pack_asset_path))
|
33
|
+
asset_pack << Asset.new_from_path(
|
34
|
+
pack_asset_path,
|
35
|
+
config: config.assets,
|
36
|
+
related: state(:asset)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
self.pack << asset_pack.finalize
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
state(:templates).each do |template_store|
|
46
|
+
build_layout_packs(template_store)
|
47
|
+
build_page_packs(template_store)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def accessible_pack_path(pack_path)
|
53
|
+
pack_path_parts = pack_path.split("/")
|
54
|
+
pack_path_parts[-1] = if pack_path_parts[-1].include?("__")
|
55
|
+
pack_path_parts[-1].split("__", 2)[1]
|
56
|
+
elsif pack_path_parts[-1].include?("@")
|
57
|
+
pack_path_parts[-1].split("@", 2)[0]
|
58
|
+
else
|
59
|
+
pack_path_parts[-1]
|
60
|
+
end
|
61
|
+
|
62
|
+
pack_path_parts.join("/")
|
63
|
+
end
|
64
|
+
|
65
|
+
def packs(view)
|
66
|
+
(autoloaded_packs + view_packs(view) + component_packs(view)).uniq.each_with_object([]) { |pack_name, packs|
|
67
|
+
if found_pack = state(:pack).find { |pack| pack.name == pack_name.to_sym }
|
68
|
+
packs << found_pack
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def autoloaded_packs
|
76
|
+
config.assets.packs.autoload
|
77
|
+
end
|
78
|
+
|
79
|
+
def view_packs(view)
|
80
|
+
view.info(:packs).to_a
|
81
|
+
end
|
82
|
+
|
83
|
+
def component_packs(view)
|
84
|
+
view.object.each_significant_node(:component, descend: true).flat_map { |node|
|
85
|
+
node.label(:components).map { |component|
|
86
|
+
component[:name]
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_layout_packs(template_store)
|
92
|
+
template_store.layouts.each do |layout_name, layout|
|
93
|
+
layout_pack = Pack.new(:"layouts/#{layout_name}", config.assets)
|
94
|
+
register_pack_with_view(layout_pack, layout)
|
95
|
+
|
96
|
+
Pathname.glob(File.join(template_store.layouts_path, "#{layout_name}.*")) do |potential_asset_path|
|
97
|
+
next if template_store.template?(potential_asset_path)
|
98
|
+
layout_pack << Asset.new_from_path(
|
99
|
+
potential_asset_path,
|
100
|
+
config: config.assets,
|
101
|
+
related: state(:asset)
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
self.pack << layout_pack.finalize
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def build_page_packs(template_store)
|
110
|
+
template_store.paths.each do |template_path|
|
111
|
+
template_info = template_store.info(template_path)
|
112
|
+
|
113
|
+
page_pack = Pack.new(:"#{template_info[:page].logical_path[1..-1]}", config.assets)
|
114
|
+
register_pack_with_view(page_pack, template_info[:page])
|
115
|
+
|
116
|
+
# Find all partials used by the page.
|
117
|
+
#
|
118
|
+
partials = template_info[:page].container_views.each_with_object([]) { |page_container, page_container_partials|
|
119
|
+
page_container_partials.concat(page_container.find_partials(template_info[:partials]))
|
120
|
+
} + template_info[:layout].find_partials(template_info[:partials])
|
121
|
+
|
122
|
+
# Include assets for partials used by the page into the page pack.
|
123
|
+
#
|
124
|
+
partials.each do |partial_name|
|
125
|
+
if partial = template_info[:partials][partial_name]
|
126
|
+
Pathname.glob(File.join(config.presenter.path, "#{partial.logical_path}.*")) do |potential_asset_path|
|
127
|
+
next if template_store.template?(potential_asset_path)
|
128
|
+
page_pack << Asset.new_from_path(
|
129
|
+
potential_asset_path,
|
130
|
+
config: config.assets,
|
131
|
+
related: state(:asset)
|
132
|
+
)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Include assets defined for the page itself.
|
138
|
+
#
|
139
|
+
Pathname.glob(File.join(template_info[:page].path.dirname, "#{template_info[:page].path.basename(template_info[:page].path.extname)}.*")) do |potential_asset_path|
|
140
|
+
next if template_store.template?(potential_asset_path)
|
141
|
+
page_pack << Asset.new_from_path(
|
142
|
+
potential_asset_path,
|
143
|
+
config: config.assets,
|
144
|
+
related: state(:asset)
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
self.pack << page_pack.finalize
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def register_pack_with_view(pack, view)
|
153
|
+
unless view.info(:packs)
|
154
|
+
view.add_info(packs: [])
|
155
|
+
end
|
156
|
+
|
157
|
+
view.info(:packs) << pack.name
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/extension"
|
4
|
+
|
5
|
+
module Pakyow
|
6
|
+
module Assets
|
7
|
+
module Behavior
|
8
|
+
module Prelaunching
|
9
|
+
extend Support::Extension
|
10
|
+
|
11
|
+
apply_extension do
|
12
|
+
on "configure" do
|
13
|
+
config.tasks.prelaunch << "assets:precompile"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/extension"
|
4
|
+
|
5
|
+
module Pakyow
|
6
|
+
module Assets
|
7
|
+
module Behavior
|
8
|
+
module Processing
|
9
|
+
extend Support::Extension
|
10
|
+
|
11
|
+
apply_extension do
|
12
|
+
on "load" do
|
13
|
+
if self.class.includes_framework?(:presenter)
|
14
|
+
self.class.processor :html do |content|
|
15
|
+
state(:asset).each do |asset|
|
16
|
+
content.gsub!(asset.logical_path, asset.public_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
content
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|