catalyst-rails 0.1.3 → 2.0.0.beta1
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/catalyst-rails.rb +61 -39
- data/lib/catalyst/builder.rb +31 -24
- data/lib/catalyst/config.rb +38 -20
- data/lib/catalyst/content_type.rb +32 -0
- data/lib/catalyst/helpers.rb +129 -39
- data/lib/catalyst/manifest.rb +73 -19
- data/lib/catalyst/railtie.rb +1 -3
- data/lib/catalyst/tasks/build.rake +4 -2
- data/lib/catalyst/version.rb +1 -1
- metadata +38 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6dbbb378b752078b95029b38eb8b05001cfa37e5bd64a3c32a38f9db3c6bc68
|
4
|
+
data.tar.gz: c6de8f3c01f813d3f7eeea77801d99ce1b44af567c2b9c570eebc370c7d24e56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eda47f5e2b159cb08563b13052993506c52fa04f7ff4a573d099970941af356ef2c13e05d4019c7e5527dfaf08c4b71daf0ed1c67f6d583736ab296459648510
|
7
|
+
data.tar.gz: 4d9bd288e5017a91f7217819f7d8aa60acc5ebb982e0dfc8d159ff08381bb615ffd7674c4a2e23a64dddd7b48934f75846fd12a77a59391b829d3a5fea165db1
|
data/lib/catalyst-rails.rb
CHANGED
@@ -7,32 +7,55 @@ require 'open3'
|
|
7
7
|
module Catalyst
|
8
8
|
extend Dry::Configurable
|
9
9
|
|
10
|
-
default_environment
|
11
|
-
ENV['NODE_ENV']
|
12
|
-
|
13
|
-
Rails
|
10
|
+
def self.default_environment
|
11
|
+
if ENV['NODE_ENV']
|
12
|
+
ENV['NODE_ENV'].to_sym
|
13
|
+
elsif defined?(Rails)
|
14
|
+
Rails.env.to_sym
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
|
-
default_manifest_path
|
17
|
-
|
18
|
+
def self.default_manifest_path
|
19
|
+
return unless defined?(Rails)
|
20
|
+
|
21
|
+
File.expand_path('./public/assets/catalyst.manifest.json', Dir.pwd)
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
setting :dev_server_port, ENV.fetch('DEV_SERVER_PORT') { 8080 }.to_i
|
26
|
-
setting :running_feature_tests, -> {
|
27
|
-
!defined?(RSpec) || RSpec.world.all_example_groups.any? do |group|
|
28
|
-
group.metadata[:type] == :system
|
24
|
+
def self.default_assets_host
|
25
|
+
if defined?(Rails) && !Rails.env.production? && ENV['PORT']
|
26
|
+
"localhost:#{ENV['PORT']}"
|
27
|
+
else
|
28
|
+
ENV.fetch('HOST', nil)
|
29
29
|
end
|
30
|
-
|
30
|
+
end
|
31
31
|
|
32
|
-
def self.
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def self.default_assets_host_protocol
|
33
|
+
!defined?(Rails) || Rails.env.production? ? 'https' : 'http'
|
34
|
+
end
|
35
|
+
|
36
|
+
setting :pwd, Dir.pwd
|
37
|
+
setting :environment, default_environment
|
38
|
+
setting :manifest_path, default_manifest_path
|
39
|
+
setting :assets_host, default_assets_host
|
40
|
+
setting :assets_host_protocol, default_assets_host_protocol
|
41
|
+
setting :dev_server_host, ENV.fetch('DEV_SERVER_HOST', 'localhost')
|
42
|
+
setting :dev_server_port, ENV.fetch('DEV_SERVER_PORT', 8080).to_i
|
43
|
+
setting :dev_server_protocol, ENV.fetch('DEV_SERVER_PROTOCOL', 'http')
|
44
|
+
setting :running_feature_tests,
|
45
|
+
lambda {
|
46
|
+
!defined?(RSpec) || RSpec
|
47
|
+
.world
|
48
|
+
.all_example_groups
|
49
|
+
.any? { |group| group.metadata[:type] == :system }
|
50
|
+
}
|
51
|
+
|
52
|
+
def self.log(message)
|
53
|
+
message =
|
54
|
+
message
|
55
|
+
.split("\n")
|
56
|
+
.reduce('') do |reduction, line|
|
57
|
+
reduction + "\e[35m[Catalyst]\e[0m #{line}\n"
|
58
|
+
end
|
36
59
|
|
37
60
|
puts message
|
38
61
|
end
|
@@ -70,12 +93,10 @@ module Catalyst
|
|
70
93
|
$catalyst_server_pid = wait_thr.pid
|
71
94
|
|
72
95
|
Thread.new do
|
73
|
-
|
74
|
-
|
75
|
-
puts line
|
76
|
-
end
|
77
|
-
rescue IOError
|
96
|
+
while (line = stdout.gets)
|
97
|
+
puts line
|
78
98
|
end
|
99
|
+
rescue IOError
|
79
100
|
end
|
80
101
|
|
81
102
|
at_exit do
|
@@ -86,25 +107,26 @@ module Catalyst
|
|
86
107
|
end
|
87
108
|
|
88
109
|
def self.check_for_yarn!
|
89
|
-
unless system 'which yarn > /dev/null 2>&1'
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
MESSAGE
|
95
|
-
end
|
110
|
+
raise NotInstalled, <<~MESSAGE unless system 'which yarn > /dev/null 2>&1'
|
111
|
+
The yarn binary is not available in this directory.
|
112
|
+
Please follow the instructions here to install it:
|
113
|
+
https://yarnpkg.com/lang/en/docs/install
|
114
|
+
MESSAGE
|
96
115
|
end
|
97
116
|
|
98
117
|
def self.check_for_catalyst!
|
99
118
|
check_for_yarn!
|
100
119
|
|
101
|
-
|
102
|
-
|
103
|
-
The catalyst binary is not available in this directory.
|
104
|
-
Please follow the instructions here to install it:
|
105
|
-
https://github.com/friendsoftheweb/catalyst
|
106
|
-
MESSAGE
|
120
|
+
if File.exist?(File.join(Dir.pwd, 'node_modules/catalyst/lib/bin.js'))
|
121
|
+
return
|
107
122
|
end
|
123
|
+
|
124
|
+
raise NotInstalled, <<~MESSAGE
|
125
|
+
The Catalyst binary is not available in this directory or you are using an unsupported version of Catalyst.
|
126
|
+
|
127
|
+
Please follow the instructions here to install it:
|
128
|
+
https://github.com/friendsoftheweb/catalyst
|
129
|
+
MESSAGE
|
108
130
|
end
|
109
131
|
end
|
110
132
|
|
@@ -113,4 +135,4 @@ require_relative './catalyst/errors'
|
|
113
135
|
require_relative './catalyst/builder'
|
114
136
|
require_relative './catalyst/helpers'
|
115
137
|
require_relative './catalyst/manifest'
|
116
|
-
require_relative './catalyst/railtie' if defined?
|
138
|
+
require_relative './catalyst/railtie' if defined?(::Rails::Railtie)
|
data/lib/catalyst/builder.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'singleton'
|
5
5
|
require 'forwardable'
|
6
|
+
require 'fileutils'
|
6
7
|
require_relative './config'
|
7
8
|
|
8
9
|
module Catalyst
|
@@ -17,18 +18,20 @@ module Catalyst
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def build!(environment = nil)
|
20
|
-
Catalyst.check_for_catalyst!
|
21
|
-
|
22
21
|
environment ||= Catalyst.config.environment
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
FileUtils.cd(Catalyst.config.pwd) do
|
24
|
+
Catalyst.check_for_catalyst!
|
25
|
+
|
26
|
+
case environment
|
27
|
+
when :test
|
28
|
+
test_build!
|
29
|
+
when :production
|
30
|
+
production_build!
|
31
|
+
else
|
32
|
+
raise ArgumentError,
|
33
|
+
'Invalid environment. Must be one of: :test, :production.'
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -70,24 +73,26 @@ module Catalyst
|
|
70
73
|
end
|
71
74
|
|
72
75
|
def production_build!
|
73
|
-
|
74
|
-
Catalyst.log('Failed to compile assets!')
|
76
|
+
return if system("NODE_ENV=production #{BUILD_COMMAND}")
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
+
Catalyst.log('Failed to compile assets!')
|
79
|
+
|
80
|
+
exit 1
|
78
81
|
end
|
79
82
|
|
80
83
|
def assets_last_modified
|
81
|
-
asset_paths
|
82
|
-
|
83
|
-
|
84
|
-
File.ctime(path)
|
85
|
-
|
84
|
+
asset_paths
|
85
|
+
.lazy
|
86
|
+
.select { |path| File.exist?(path) }
|
87
|
+
.map { |path| File.ctime(path) }
|
88
|
+
.max || Time.now
|
86
89
|
end
|
87
90
|
|
88
91
|
def asset_paths
|
89
92
|
if ::Catalyst::Config.context_path
|
90
|
-
Dir.glob(
|
93
|
+
Dir.glob(
|
94
|
+
File.join(::Catalyst::Config.context_path, '**/*.{js,ts,tsx,scss}')
|
95
|
+
) + [
|
91
96
|
File.join(Dir.pwd, 'package.json'),
|
92
97
|
File.join(Dir.pwd, 'yarn.lock'),
|
93
98
|
File.join(Dir.pwd, 'catalyst.config.json')
|
@@ -98,16 +103,18 @@ module Catalyst
|
|
98
103
|
end
|
99
104
|
|
100
105
|
def assets_last_built_file_path
|
101
|
-
if defined?(Rails)
|
102
|
-
Rails.root.join('tmp/assets-last-built')
|
103
|
-
end
|
106
|
+
Rails.root.join('tmp/assets-last-built') if defined?(Rails)
|
104
107
|
end
|
105
108
|
|
106
109
|
def assets_last_built
|
107
110
|
if assets_last_built_file_path.nil?
|
108
111
|
Time.at(0)
|
109
112
|
else
|
110
|
-
|
113
|
+
begin
|
114
|
+
File.mtime(assets_last_built_file_path)
|
115
|
+
rescue StandardError
|
116
|
+
Time.at(0)
|
117
|
+
end
|
111
118
|
end
|
112
119
|
end
|
113
120
|
end
|
data/lib/catalyst/config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'sorbet-runtime'
|
4
5
|
require 'singleton'
|
5
6
|
require 'forwardable'
|
6
7
|
require 'json'
|
@@ -8,8 +9,16 @@ require_relative './errors'
|
|
8
9
|
|
9
10
|
module Catalyst
|
10
11
|
class Config
|
11
|
-
|
12
|
-
|
12
|
+
extend T::Sig
|
13
|
+
sig { returns(String) }
|
14
|
+
def self.catalyst_config_path
|
15
|
+
File.expand_path('./catalyst.config.json', Catalyst.config.pwd)
|
16
|
+
end
|
17
|
+
|
18
|
+
sig { returns(String) }
|
19
|
+
def self.package_path
|
20
|
+
File.expand_path('./package.json', Catalyst.config.pwd)
|
21
|
+
end
|
13
22
|
|
14
23
|
include Singleton
|
15
24
|
|
@@ -18,27 +27,36 @@ module Catalyst
|
|
18
27
|
def_delegators :instance, :context_path
|
19
28
|
end
|
20
29
|
|
30
|
+
sig { void }
|
21
31
|
def initialize
|
22
|
-
@values =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
@values =
|
33
|
+
T.let(
|
34
|
+
if File.exist?(self.class.catalyst_config_path)
|
35
|
+
JSON.parse(File.read(self.class.catalyst_config_path))
|
36
|
+
elsif File.exist?(self.class.package_path)
|
37
|
+
JSON.parse(File.read(self.class.package_path))['catalyst']
|
38
|
+
else
|
39
|
+
raise ::Catalyst::MissingConfig,
|
40
|
+
"Missing 'catalyst.config.json' or 'package.json' file in: #{
|
41
|
+
Catalyst.config.pwd
|
42
|
+
}"
|
43
|
+
end,
|
44
|
+
T::Hash[String, T.untyped]
|
45
|
+
)
|
46
|
+
|
47
|
+
raise ::Catalyst::MissingConfig, <<~MESSAGE if @values.nil?
|
48
|
+
Missing "catalyst" config in package.json file.
|
49
|
+
Please follow the instructions here to set up Catalyst:
|
50
|
+
https://github.com/friendsoftheweb/catalyst
|
51
|
+
MESSAGE
|
38
52
|
end
|
39
53
|
|
54
|
+
sig { returns(String) }
|
40
55
|
def context_path
|
41
|
-
File.join(
|
56
|
+
File.join(
|
57
|
+
Catalyst.config.pwd,
|
58
|
+
@values['contextPath'] || @values['rootPath']
|
59
|
+
)
|
42
60
|
end
|
43
61
|
end
|
44
62
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# typed: strict
|
4
|
+
|
5
|
+
require 'sorbet-runtime'
|
6
|
+
|
7
|
+
module Catalyst
|
8
|
+
module ContentType
|
9
|
+
extend T::Sig
|
10
|
+
|
11
|
+
sig { params(filename: String).returns(Symbol) }
|
12
|
+
def self.for_filename(filename)
|
13
|
+
case File.extname(filename)
|
14
|
+
when /\.(js)\z/
|
15
|
+
:script
|
16
|
+
when /\.(css)\z/
|
17
|
+
:style
|
18
|
+
when /\.(png|jpe?g|gif|webp)\z/
|
19
|
+
:image
|
20
|
+
when /\.(woff2?|ttf|eot)\z/
|
21
|
+
:font
|
22
|
+
when /\.(mp4|webm)\z/
|
23
|
+
:video
|
24
|
+
else
|
25
|
+
raise StandardError,
|
26
|
+
"Could not automatically determine the content type for: #{
|
27
|
+
filename
|
28
|
+
}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/catalyst/helpers.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'sorbet-runtime'
|
4
5
|
require 'action_view'
|
5
6
|
require_relative './manifest'
|
7
|
+
require_relative './content_type'
|
6
8
|
|
7
9
|
module Catalyst
|
8
10
|
module Helpers
|
11
|
+
extend T::Sig
|
12
|
+
include Kernel
|
9
13
|
include ActionView::Helpers::TagHelper
|
10
14
|
include ActionView::Helpers::OutputSafetyHelper
|
11
15
|
|
16
|
+
sig { params(path: T.any(String, Symbol), common: T::Boolean).returns(String) }
|
12
17
|
def catalyst_javascript_include_tag(path, common: true)
|
13
|
-
path = path.to_s.sub(/\.js\z/, '')
|
18
|
+
path = "#{path.to_s.sub(/\.js\z/, '')}.js"
|
14
19
|
|
15
20
|
if catalyst_referenced_files.include?(path)
|
16
21
|
raise ::Catalyst::Manifest::DuplicateAssetReference,
|
@@ -19,29 +24,34 @@ module Catalyst
|
|
19
24
|
|
20
25
|
catalyst_referenced_files << path
|
21
26
|
|
22
|
-
|
23
|
-
return
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
unless common
|
28
|
+
return(
|
29
|
+
content_tag(
|
30
|
+
:script,
|
31
|
+
nil,
|
32
|
+
type: 'text/javascript',
|
33
|
+
crossorigin: 'anonymous',
|
34
|
+
src: catalyst_asset_url(path)
|
35
|
+
)
|
29
36
|
)
|
30
37
|
end
|
31
38
|
|
32
|
-
safe_join(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
safe_join(
|
40
|
+
[
|
41
|
+
catalyst_javascript_vendor_include_tag,
|
42
|
+
catalyst_javascript_common_include_tag,
|
43
|
+
content_tag(
|
44
|
+
:script,
|
45
|
+
nil,
|
46
|
+
type: 'text/javascript',
|
47
|
+
crossorigin: 'anonymous',
|
48
|
+
src: catalyst_asset_url(path)
|
49
|
+
)
|
50
|
+
]
|
51
|
+
)
|
43
52
|
end
|
44
53
|
|
54
|
+
sig { returns(T.nilable(String)) }
|
45
55
|
def catalyst_javascript_vendor_include_tag
|
46
56
|
path = 'vendor-dll.js'
|
47
57
|
|
@@ -51,20 +61,21 @@ module Catalyst
|
|
51
61
|
catalyst_javascript_include_tag(path)
|
52
62
|
end
|
53
63
|
|
64
|
+
sig { returns(T.nilable(String)) }
|
54
65
|
def catalyst_javascript_common_include_tag
|
55
66
|
path = 'common.js'
|
56
67
|
|
57
|
-
return
|
68
|
+
return if catalyst_referenced_files.include?(path)
|
69
|
+
return unless ::Catalyst.development? || ::Catalyst::Manifest.has?(path)
|
58
70
|
|
59
|
-
|
60
|
-
catalyst_javascript_include_tag(path)
|
61
|
-
end
|
71
|
+
catalyst_javascript_include_tag(path)
|
62
72
|
end
|
63
73
|
|
74
|
+
sig { params(path: T.any(String, Symbol)).returns(T.nilable(String)) }
|
64
75
|
def catalyst_stylesheet_link_tag(path)
|
65
76
|
return nil if ::Catalyst.development?
|
66
77
|
|
67
|
-
path = path.to_s.sub(/\.css\z/, '')
|
78
|
+
path = "#{path.to_s.sub(/\.css\z/, '')}.css"
|
68
79
|
|
69
80
|
if catalyst_referenced_files.include?(path)
|
70
81
|
raise ::Catalyst::Manifest::DuplicateAssetReference,
|
@@ -73,37 +84,116 @@ module Catalyst
|
|
73
84
|
|
74
85
|
catalyst_referenced_files << path
|
75
86
|
|
76
|
-
safe_join(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
safe_join(
|
88
|
+
[
|
89
|
+
catalyst_common_stylesheet_link_tag,
|
90
|
+
content_tag(
|
91
|
+
:link,
|
92
|
+
nil,
|
93
|
+
href: catalyst_asset_url(path),
|
94
|
+
media: 'screen',
|
95
|
+
rel: 'stylesheet'
|
96
|
+
)
|
97
|
+
]
|
98
|
+
)
|
86
99
|
end
|
87
100
|
|
101
|
+
sig { returns(T.nilable(String)) }
|
88
102
|
def catalyst_common_stylesheet_link_tag
|
89
103
|
path = 'common.css'
|
90
104
|
|
91
105
|
return nil if catalyst_referenced_files.include?(path)
|
92
106
|
|
93
|
-
if ::Catalyst::Manifest.has?(path)
|
94
|
-
|
95
|
-
|
107
|
+
catalyst_stylesheet_link_tag(path) if ::Catalyst::Manifest.has?(path)
|
108
|
+
end
|
109
|
+
|
110
|
+
sig { params(entry_name: T.any(String, Symbol)).returns(T.untyped) }
|
111
|
+
def catalyst_link_tags_for(entry_name)
|
112
|
+
safe_join(
|
113
|
+
[
|
114
|
+
catalyst_preload_link_tags_for(entry_name),
|
115
|
+
catalyst_prefetch_link_tags_for(entry_name)
|
116
|
+
].flatten
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
sig { params(entry_name: T.any(String, Symbol)).returns(T.untyped) }
|
121
|
+
def catalyst_preload_link_tags_for(entry_name)
|
122
|
+
safe_join(
|
123
|
+
::Catalyst::Manifest
|
124
|
+
.preload_urls_for(entry_name)
|
125
|
+
.map do |url|
|
126
|
+
content_tag(
|
127
|
+
:link,
|
128
|
+
nil,
|
129
|
+
{
|
130
|
+
href: catalyst_asset_url(url),
|
131
|
+
rel: 'preload',
|
132
|
+
as: ::Catalyst::ContentType.for_filename(url)
|
133
|
+
}
|
134
|
+
)
|
135
|
+
end
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
sig { params(entry_name: T.any(String, Symbol)).returns(T.untyped) }
|
140
|
+
def catalyst_prefetch_link_tags_for(entry_name)
|
141
|
+
safe_join(
|
142
|
+
::Catalyst::Manifest
|
143
|
+
.prefetch_urls_for(entry_name)
|
144
|
+
.map do |url|
|
145
|
+
content_tag(
|
146
|
+
:link,
|
147
|
+
nil,
|
148
|
+
{
|
149
|
+
href: catalyst_asset_url(url),
|
150
|
+
rel: 'prefetch',
|
151
|
+
as: ::Catalyst::ContentType.for_filename(url)
|
152
|
+
}
|
153
|
+
)
|
154
|
+
end
|
155
|
+
)
|
156
|
+
end
|
157
|
+
|
158
|
+
sig { params(path: String).returns(T.untyped) }
|
159
|
+
def catalyst_preload_link_tag(path)
|
160
|
+
content_tag(
|
161
|
+
:link,
|
162
|
+
nil,
|
163
|
+
{
|
164
|
+
href: catalyst_asset_url(path),
|
165
|
+
rel: 'preload',
|
166
|
+
as: ::Catalyst::ContentType.for_filename(path)
|
167
|
+
}
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
sig { params(path: String).returns(T.untyped) }
|
172
|
+
def catalyst_prefetch_link_tag(path)
|
173
|
+
content_tag(
|
174
|
+
:link,
|
175
|
+
nil,
|
176
|
+
{
|
177
|
+
href: catalyst_asset_url(path),
|
178
|
+
rel: 'prefetch',
|
179
|
+
as: ::Catalyst::ContentType.for_filename(path)
|
180
|
+
}
|
181
|
+
)
|
96
182
|
end
|
97
183
|
|
184
|
+
sig { params(path: T.any(String, Symbol)).returns(T.nilable(String)) }
|
98
185
|
def catalyst_asset_path(path)
|
99
186
|
::Catalyst::Manifest[path]
|
100
187
|
end
|
101
188
|
|
189
|
+
sig { params(path: T.any(String, Symbol)).returns(T.nilable(String)) }
|
102
190
|
def catalyst_asset_url(path)
|
103
191
|
if ::Catalyst.development? || ::Catalyst.config.assets_host.nil?
|
104
192
|
catalyst_asset_path(path)
|
105
193
|
else
|
106
|
-
"#{Catalyst.config.assets_host_protocol}://#{
|
194
|
+
"#{Catalyst.config.assets_host_protocol}://#{
|
195
|
+
Catalyst.config.assets_host
|
196
|
+
}#{catalyst_asset_path(path)}"
|
107
197
|
end
|
108
198
|
end
|
109
199
|
|
data/lib/catalyst/manifest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'singleton'
|
@@ -11,58 +11,112 @@ module Catalyst
|
|
11
11
|
AssetMissing = Class.new(::Catalyst::CatalystError)
|
12
12
|
DuplicateAssetReference = Class.new(::Catalyst::CatalystError)
|
13
13
|
|
14
|
+
extend T::Sig
|
14
15
|
include Singleton
|
15
16
|
|
16
17
|
class << self
|
17
18
|
extend Forwardable
|
18
|
-
|
19
|
+
|
20
|
+
def_delegators :instance,
|
21
|
+
:[],
|
22
|
+
:has?,
|
23
|
+
:preload_urls_for,
|
24
|
+
:prefetch_urls_for
|
19
25
|
end
|
20
26
|
|
27
|
+
sig { void }
|
21
28
|
def initialize
|
22
29
|
if Catalyst.development?
|
23
|
-
@manifest = {}
|
30
|
+
@manifest = T.let({}, T::Hash[String, T.untyped])
|
24
31
|
else
|
25
32
|
if Catalyst.config.manifest_path.nil?
|
26
33
|
raise 'Missing "manifest_path" configuration.'
|
27
34
|
end
|
28
35
|
|
29
|
-
@manifest =
|
36
|
+
@manifest =
|
37
|
+
T.let(
|
38
|
+
JSON.parse(File.read(Catalyst.config.manifest_path)),
|
39
|
+
T::Hash[String, T.untyped]
|
40
|
+
)
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
44
|
+
sig { params(path: T.any(String, Symbol)).returns(T::Boolean) }
|
33
45
|
def has?(path)
|
34
|
-
path = path.to_s.gsub(
|
46
|
+
path = path.to_s.gsub(%r{\A/+}, '')
|
35
47
|
|
36
|
-
|
37
|
-
false
|
38
|
-
else
|
39
|
-
@manifest.key?(path)
|
40
|
-
end
|
48
|
+
Catalyst.development? ? false : assets.key?(path)
|
41
49
|
end
|
42
50
|
|
51
|
+
sig { params(path: T.any(String, Symbol)).returns(String) }
|
43
52
|
def [](path)
|
44
|
-
path = path.to_s.gsub(
|
53
|
+
path = path.to_s.gsub(%r{\A/+}, '')
|
45
54
|
|
46
55
|
if Catalyst.development?
|
56
|
+
dev_server_protocol = Catalyst.config.dev_server_protocol
|
47
57
|
dev_server_host = Catalyst.config.dev_server_host
|
48
58
|
dev_server_port = Catalyst.config.dev_server_port
|
49
59
|
|
60
|
+
if dev_server_protocol.nil?
|
61
|
+
raise ::Catalyst::CatalystError,
|
62
|
+
'Missing "dev_server_protocol" configuration.'
|
63
|
+
end
|
64
|
+
|
50
65
|
if dev_server_host.nil?
|
51
|
-
raise
|
66
|
+
raise ::Catalyst::CatalystError,
|
67
|
+
'Missing "dev_server_host" configuration.'
|
52
68
|
end
|
53
69
|
|
54
70
|
if dev_server_port.nil?
|
55
|
-
raise
|
71
|
+
raise ::Catalyst::CatalystError,
|
72
|
+
'Missing "dev_server_port" configuration.'
|
56
73
|
end
|
57
74
|
|
58
|
-
|
75
|
+
"#{dev_server_protocol}://#{dev_server_host}:#{dev_server_port}/#{path}"
|
76
|
+
elsif assets.key?(path)
|
77
|
+
T.must(assets[path])
|
59
78
|
else
|
60
|
-
|
61
|
-
return @manifest[path]
|
62
|
-
else
|
63
|
-
raise AssetMissing, "Couldn't find an asset for path: #{path}"
|
64
|
-
end
|
79
|
+
raise AssetMissing, "Couldn't find an asset for path: #{path}"
|
65
80
|
end
|
66
81
|
end
|
82
|
+
|
83
|
+
sig { params(entry_name: T.any(String, Symbol)).returns(T::Array[String]) }
|
84
|
+
def preload_urls_for(entry_name)
|
85
|
+
return [] if Catalyst.development?
|
86
|
+
|
87
|
+
entry_name = entry_name.to_s
|
88
|
+
|
89
|
+
return [] unless preload.key?(entry_name)
|
90
|
+
|
91
|
+
T.must(preload[entry_name])
|
92
|
+
end
|
93
|
+
|
94
|
+
sig { params(entry_name: T.any(String, Symbol)).returns(T::Array[String]) }
|
95
|
+
def prefetch_urls_for(entry_name)
|
96
|
+
return [] if Catalyst.development?
|
97
|
+
|
98
|
+
entry_name = entry_name.to_s
|
99
|
+
|
100
|
+
return [] unless prefetch.key?(entry_name)
|
101
|
+
|
102
|
+
T.must(prefetch[entry_name])
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
sig { returns(T::Hash[String, String]) }
|
108
|
+
def assets
|
109
|
+
@manifest['assets'] || {}
|
110
|
+
end
|
111
|
+
|
112
|
+
sig { returns(T::Hash[String, T::Array[String]]) }
|
113
|
+
def preload
|
114
|
+
@manifest['preload'] || {}
|
115
|
+
end
|
116
|
+
|
117
|
+
sig { returns(T::Hash[String, T::Array[String]]) }
|
118
|
+
def prefetch
|
119
|
+
@manifest['prefetch'] || {}
|
120
|
+
end
|
67
121
|
end
|
68
122
|
end
|
data/lib/catalyst/railtie.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :catalyst do
|
2
4
|
desc 'Build assets with Catalyst'
|
3
5
|
task :build do
|
4
|
-
if File.
|
6
|
+
if File.exist?('./public/assets/manifest.json')
|
5
7
|
Catalyst.log('Removing previous assets...')
|
6
8
|
|
7
9
|
manifest = JSON.parse(File.read('./public/assets/manifest.json'))
|
8
10
|
|
9
|
-
manifest.
|
11
|
+
manifest.each_value do |asset_path|
|
10
12
|
system "rm -f ./public/assets/#{asset_path}*"
|
11
13
|
end
|
12
14
|
end
|
data/lib/catalyst/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catalyst-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: dry-configurable
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,53 +45,47 @@ dependencies:
|
|
25
45
|
- !ruby/object:Gem::Version
|
26
46
|
version: '0.7'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
48
|
+
name: sorbet-runtime
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.0'
|
34
|
-
- - "<"
|
51
|
+
- - "~>"
|
35
52
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
53
|
+
version: 0.5.0
|
37
54
|
type: :runtime
|
38
55
|
prerelease: false
|
39
56
|
version_requirements: !ruby/object:Gem::Requirement
|
40
57
|
requirements:
|
41
|
-
- - "
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '3.0'
|
44
|
-
- - "<"
|
58
|
+
- - "~>"
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
60
|
+
version: 0.5.0
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
62
|
+
name: rubocop
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
type: :
|
67
|
+
version: '1.7'
|
68
|
+
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - "~>"
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
74
|
+
version: '1.7'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: sorbet
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
66
80
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
81
|
+
version: 0.5.0
|
68
82
|
type: :development
|
69
83
|
prerelease: false
|
70
84
|
version_requirements: !ruby/object:Gem::Requirement
|
71
85
|
requirements:
|
72
86
|
- - "~>"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
88
|
+
version: 0.5.0
|
75
89
|
description:
|
76
90
|
email: dan@friendsoftheweb.com
|
77
91
|
executables: []
|
@@ -81,6 +95,7 @@ files:
|
|
81
95
|
- lib/catalyst-rails.rb
|
82
96
|
- lib/catalyst/builder.rb
|
83
97
|
- lib/catalyst/config.rb
|
98
|
+
- lib/catalyst/content_type.rb
|
84
99
|
- lib/catalyst/errors.rb
|
85
100
|
- lib/catalyst/helpers.rb
|
86
101
|
- lib/catalyst/manifest.rb
|
@@ -99,15 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
114
|
requirements:
|
100
115
|
- - ">="
|
101
116
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
117
|
+
version: 2.5.0
|
103
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
119
|
requirements:
|
105
|
-
- - "
|
120
|
+
- - ">"
|
106
121
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
122
|
+
version: 1.3.1
|
108
123
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.7.6.2
|
124
|
+
rubygems_version: 3.1.2
|
111
125
|
signing_key:
|
112
126
|
specification_version: 4
|
113
127
|
summary: Ruby helpers for the "catalyst" node package
|