catalyst-rails 0.1.0 → 2.0.0.beta2
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 +62 -39
- data/lib/catalyst/builder.rb +32 -20
- data/lib/catalyst/config.rb +38 -19
- data/lib/catalyst/content_type.rb +32 -0
- data/lib/catalyst/errors.rb +1 -0
- data/lib/catalyst/helpers.rb +129 -38
- data/lib/catalyst/manifest.rb +73 -18
- data/lib/catalyst/railtie.rb +3 -3
- data/lib/catalyst/tasks/build.rake +4 -2
- data/lib/catalyst/version.rb +2 -1
- metadata +59 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 12cc6ca1565fb8e3c4321bcc233fb5acde2ccbbe11c6e21e9a7f0f1a5fe7d68e
|
|
4
|
+
data.tar.gz: d21bae4fbec785d6452c0cfb0ea921c1a2faaa162d617fd2c4690605037ef10c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52667390f225ad5ff5697d57bbbb371b4dca9ecc79ec3f0da1c0b901d66508633abe21d8253f0c76b0610fad7cfd37e9475892b6f48295b686d0315eb557dae6
|
|
7
|
+
data.tar.gz: 51e1b1fab5a2110ee356d28805219581be119da97338cd585decbefabb612a073c367c5da8cecc322d82ac1b24ab6b7bb50eb8fc0890d1708d9279bfd020d0f3
|
data/lib/catalyst-rails.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# typed: false
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'dry-configurable'
|
|
@@ -6,32 +7,55 @@ require 'open3'
|
|
|
6
7
|
module Catalyst
|
|
7
8
|
extend Dry::Configurable
|
|
8
9
|
|
|
9
|
-
default_environment
|
|
10
|
-
ENV['NODE_ENV']
|
|
11
|
-
|
|
12
|
-
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
|
|
13
16
|
end
|
|
14
17
|
|
|
15
|
-
default_manifest_path
|
|
16
|
-
|
|
18
|
+
def self.default_manifest_path
|
|
19
|
+
return unless defined?(Rails)
|
|
20
|
+
|
|
21
|
+
File.expand_path('./public/assets/catalyst.manifest.json', Dir.pwd)
|
|
17
22
|
end
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
setting :dev_server_port, ENV.fetch('DEV_SERVER_PORT') { 8080 }.to_i
|
|
25
|
-
setting :running_feature_tests, -> {
|
|
26
|
-
!defined?(RSpec) || RSpec.world.all_example_groups.any? do |group|
|
|
27
|
-
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)
|
|
28
29
|
end
|
|
29
|
-
|
|
30
|
+
end
|
|
30
31
|
|
|
31
|
-
def self.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
35
59
|
|
|
36
60
|
puts message
|
|
37
61
|
end
|
|
@@ -69,12 +93,10 @@ module Catalyst
|
|
|
69
93
|
$catalyst_server_pid = wait_thr.pid
|
|
70
94
|
|
|
71
95
|
Thread.new do
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
puts line
|
|
75
|
-
end
|
|
76
|
-
rescue IOError
|
|
96
|
+
while (line = stdout.gets)
|
|
97
|
+
puts line
|
|
77
98
|
end
|
|
99
|
+
rescue IOError
|
|
78
100
|
end
|
|
79
101
|
|
|
80
102
|
at_exit do
|
|
@@ -85,25 +107,26 @@ module Catalyst
|
|
|
85
107
|
end
|
|
86
108
|
|
|
87
109
|
def self.check_for_yarn!
|
|
88
|
-
unless system 'which yarn > /dev/null 2>&1'
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
MESSAGE
|
|
94
|
-
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
|
|
95
115
|
end
|
|
96
116
|
|
|
97
117
|
def self.check_for_catalyst!
|
|
98
118
|
check_for_yarn!
|
|
99
119
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
The catalyst binary is not available in this directory.
|
|
103
|
-
Please follow the instructions here to install it:
|
|
104
|
-
https://github.com/friendsoftheweb/catalyst
|
|
105
|
-
MESSAGE
|
|
120
|
+
if File.exist?(File.join(Dir.pwd, 'node_modules/catalyst/lib/bin.js'))
|
|
121
|
+
return
|
|
106
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
|
|
107
130
|
end
|
|
108
131
|
end
|
|
109
132
|
|
|
@@ -112,4 +135,4 @@ require_relative './catalyst/errors'
|
|
|
112
135
|
require_relative './catalyst/builder'
|
|
113
136
|
require_relative './catalyst/helpers'
|
|
114
137
|
require_relative './catalyst/manifest'
|
|
115
|
-
require_relative './catalyst/railtie' if defined?
|
|
138
|
+
require_relative './catalyst/railtie' if defined?(::Rails::Railtie)
|
data/lib/catalyst/builder.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# typed: false
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'singleton'
|
|
4
5
|
require 'forwardable'
|
|
6
|
+
require 'fileutils'
|
|
5
7
|
require_relative './config'
|
|
6
8
|
|
|
7
9
|
module Catalyst
|
|
@@ -16,18 +18,20 @@ module Catalyst
|
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def build!(environment = nil)
|
|
19
|
-
Catalyst.check_for_catalyst!
|
|
20
|
-
|
|
21
21
|
environment ||= Catalyst.config.environment
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
31
35
|
end
|
|
32
36
|
end
|
|
33
37
|
|
|
@@ -69,20 +73,26 @@ module Catalyst
|
|
|
69
73
|
end
|
|
70
74
|
|
|
71
75
|
def production_build!
|
|
72
|
-
|
|
73
|
-
Catalyst.log('Failed to compile assets!')
|
|
76
|
+
return if system("NODE_ENV=production #{BUILD_COMMAND}")
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
Catalyst.log('Failed to compile assets!')
|
|
79
|
+
|
|
80
|
+
exit 1
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
def assets_last_modified
|
|
80
|
-
asset_paths
|
|
84
|
+
asset_paths
|
|
85
|
+
.lazy
|
|
86
|
+
.select { |path| File.exist?(path) }
|
|
87
|
+
.map { |path| File.ctime(path) }
|
|
88
|
+
.max || Time.now
|
|
81
89
|
end
|
|
82
90
|
|
|
83
91
|
def asset_paths
|
|
84
92
|
if ::Catalyst::Config.context_path
|
|
85
|
-
Dir.glob(
|
|
93
|
+
Dir.glob(
|
|
94
|
+
File.join(::Catalyst::Config.context_path, '**/*.{js,ts,tsx,scss}')
|
|
95
|
+
) + [
|
|
86
96
|
File.join(Dir.pwd, 'package.json'),
|
|
87
97
|
File.join(Dir.pwd, 'yarn.lock'),
|
|
88
98
|
File.join(Dir.pwd, 'catalyst.config.json')
|
|
@@ -93,16 +103,18 @@ module Catalyst
|
|
|
93
103
|
end
|
|
94
104
|
|
|
95
105
|
def assets_last_built_file_path
|
|
96
|
-
if defined?(Rails)
|
|
97
|
-
Rails.root.join('tmp/assets-last-built')
|
|
98
|
-
end
|
|
106
|
+
Rails.root.join('tmp/assets-last-built') if defined?(Rails)
|
|
99
107
|
end
|
|
100
108
|
|
|
101
109
|
def assets_last_built
|
|
102
110
|
if assets_last_built_file_path.nil?
|
|
103
111
|
Time.at(0)
|
|
104
112
|
else
|
|
105
|
-
|
|
113
|
+
begin
|
|
114
|
+
File.mtime(assets_last_built_file_path)
|
|
115
|
+
rescue StandardError
|
|
116
|
+
Time.at(0)
|
|
117
|
+
end
|
|
106
118
|
end
|
|
107
119
|
end
|
|
108
120
|
end
|
data/lib/catalyst/config.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# typed: strict
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
4
|
+
require 'sorbet-runtime'
|
|
3
5
|
require 'singleton'
|
|
4
6
|
require 'forwardable'
|
|
5
7
|
require 'json'
|
|
@@ -7,8 +9,16 @@ require_relative './errors'
|
|
|
7
9
|
|
|
8
10
|
module Catalyst
|
|
9
11
|
class Config
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
12
22
|
|
|
13
23
|
include Singleton
|
|
14
24
|
|
|
@@ -17,27 +27,36 @@ module Catalyst
|
|
|
17
27
|
def_delegators :instance, :context_path
|
|
18
28
|
end
|
|
19
29
|
|
|
30
|
+
sig { void }
|
|
20
31
|
def initialize
|
|
21
|
-
@values =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
37
52
|
end
|
|
38
53
|
|
|
54
|
+
sig { returns(String) }
|
|
39
55
|
def context_path
|
|
40
|
-
File.join(
|
|
56
|
+
File.join(
|
|
57
|
+
Catalyst.config.pwd,
|
|
58
|
+
@values['contextPath'] || @values['rootPath']
|
|
59
|
+
)
|
|
41
60
|
end
|
|
42
61
|
end
|
|
43
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|svg|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/errors.rb
CHANGED
data/lib/catalyst/helpers.rb
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
# typed: true
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
4
|
+
require 'sorbet-runtime'
|
|
3
5
|
require 'action_view'
|
|
4
6
|
require_relative './manifest'
|
|
7
|
+
require_relative './content_type'
|
|
5
8
|
|
|
6
9
|
module Catalyst
|
|
7
10
|
module Helpers
|
|
11
|
+
extend T::Sig
|
|
12
|
+
include Kernel
|
|
8
13
|
include ActionView::Helpers::TagHelper
|
|
9
14
|
include ActionView::Helpers::OutputSafetyHelper
|
|
10
15
|
|
|
16
|
+
sig { params(path: T.any(String, Symbol), common: T::Boolean).returns(String) }
|
|
11
17
|
def catalyst_javascript_include_tag(path, common: true)
|
|
12
|
-
path = path.to_s.sub(/\.js\z/, '')
|
|
18
|
+
path = "#{path.to_s.sub(/\.js\z/, '')}.js"
|
|
13
19
|
|
|
14
20
|
if catalyst_referenced_files.include?(path)
|
|
15
21
|
raise ::Catalyst::Manifest::DuplicateAssetReference,
|
|
@@ -18,29 +24,34 @@ module Catalyst
|
|
|
18
24
|
|
|
19
25
|
catalyst_referenced_files << path
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
)
|
|
28
36
|
)
|
|
29
37
|
end
|
|
30
38
|
|
|
31
|
-
safe_join(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
)
|
|
42
52
|
end
|
|
43
53
|
|
|
54
|
+
sig { returns(T.nilable(String)) }
|
|
44
55
|
def catalyst_javascript_vendor_include_tag
|
|
45
56
|
path = 'vendor-dll.js'
|
|
46
57
|
|
|
@@ -50,20 +61,21 @@ module Catalyst
|
|
|
50
61
|
catalyst_javascript_include_tag(path)
|
|
51
62
|
end
|
|
52
63
|
|
|
64
|
+
sig { returns(T.nilable(String)) }
|
|
53
65
|
def catalyst_javascript_common_include_tag
|
|
54
66
|
path = 'common.js'
|
|
55
67
|
|
|
56
|
-
return
|
|
68
|
+
return if catalyst_referenced_files.include?(path)
|
|
69
|
+
return unless ::Catalyst.development? || ::Catalyst::Manifest.has?(path)
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
catalyst_javascript_include_tag(path)
|
|
60
|
-
end
|
|
71
|
+
catalyst_javascript_include_tag(path)
|
|
61
72
|
end
|
|
62
73
|
|
|
74
|
+
sig { params(path: T.any(String, Symbol)).returns(T.nilable(String)) }
|
|
63
75
|
def catalyst_stylesheet_link_tag(path)
|
|
64
76
|
return nil if ::Catalyst.development?
|
|
65
77
|
|
|
66
|
-
path = path.to_s.sub(/\.css\z/, '')
|
|
78
|
+
path = "#{path.to_s.sub(/\.css\z/, '')}.css"
|
|
67
79
|
|
|
68
80
|
if catalyst_referenced_files.include?(path)
|
|
69
81
|
raise ::Catalyst::Manifest::DuplicateAssetReference,
|
|
@@ -72,37 +84,116 @@ module Catalyst
|
|
|
72
84
|
|
|
73
85
|
catalyst_referenced_files << path
|
|
74
86
|
|
|
75
|
-
safe_join(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
)
|
|
85
99
|
end
|
|
86
100
|
|
|
101
|
+
sig { returns(T.nilable(String)) }
|
|
87
102
|
def catalyst_common_stylesheet_link_tag
|
|
88
103
|
path = 'common.css'
|
|
89
104
|
|
|
90
105
|
return nil if catalyst_referenced_files.include?(path)
|
|
91
106
|
|
|
92
|
-
if ::Catalyst::Manifest.has?(path)
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
)
|
|
95
182
|
end
|
|
96
183
|
|
|
184
|
+
sig { params(path: T.any(String, Symbol)).returns(T.nilable(String)) }
|
|
97
185
|
def catalyst_asset_path(path)
|
|
98
186
|
::Catalyst::Manifest[path]
|
|
99
187
|
end
|
|
100
188
|
|
|
189
|
+
sig { params(path: T.any(String, Symbol)).returns(T.nilable(String)) }
|
|
101
190
|
def catalyst_asset_url(path)
|
|
102
191
|
if ::Catalyst.development? || ::Catalyst.config.assets_host.nil?
|
|
103
192
|
catalyst_asset_path(path)
|
|
104
193
|
else
|
|
105
|
-
"#{Catalyst.config.assets_host_protocol}://#{
|
|
194
|
+
"#{Catalyst.config.assets_host_protocol}://#{
|
|
195
|
+
Catalyst.config.assets_host
|
|
196
|
+
}#{catalyst_asset_path(path)}"
|
|
106
197
|
end
|
|
107
198
|
end
|
|
108
199
|
|
data/lib/catalyst/manifest.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# typed: strict
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'singleton'
|
|
@@ -10,58 +11,112 @@ module Catalyst
|
|
|
10
11
|
AssetMissing = Class.new(::Catalyst::CatalystError)
|
|
11
12
|
DuplicateAssetReference = Class.new(::Catalyst::CatalystError)
|
|
12
13
|
|
|
14
|
+
extend T::Sig
|
|
13
15
|
include Singleton
|
|
14
16
|
|
|
15
17
|
class << self
|
|
16
18
|
extend Forwardable
|
|
17
|
-
|
|
19
|
+
|
|
20
|
+
def_delegators :instance,
|
|
21
|
+
:[],
|
|
22
|
+
:has?,
|
|
23
|
+
:preload_urls_for,
|
|
24
|
+
:prefetch_urls_for
|
|
18
25
|
end
|
|
19
26
|
|
|
27
|
+
sig { void }
|
|
20
28
|
def initialize
|
|
21
29
|
if Catalyst.development?
|
|
22
|
-
@manifest = {}
|
|
30
|
+
@manifest = T.let({}, T::Hash[String, T.untyped])
|
|
23
31
|
else
|
|
24
32
|
if Catalyst.config.manifest_path.nil?
|
|
25
33
|
raise 'Missing "manifest_path" configuration.'
|
|
26
34
|
end
|
|
27
35
|
|
|
28
|
-
@manifest =
|
|
36
|
+
@manifest =
|
|
37
|
+
T.let(
|
|
38
|
+
JSON.parse(File.read(Catalyst.config.manifest_path)),
|
|
39
|
+
T::Hash[String, T.untyped]
|
|
40
|
+
)
|
|
29
41
|
end
|
|
30
42
|
end
|
|
31
43
|
|
|
44
|
+
sig { params(path: T.any(String, Symbol)).returns(T::Boolean) }
|
|
32
45
|
def has?(path)
|
|
33
|
-
path = path.to_s.gsub(
|
|
46
|
+
path = path.to_s.gsub(%r{\A/+}, '')
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
false
|
|
37
|
-
else
|
|
38
|
-
@manifest.key?(path)
|
|
39
|
-
end
|
|
48
|
+
Catalyst.development? ? false : assets.key?(path)
|
|
40
49
|
end
|
|
41
50
|
|
|
51
|
+
sig { params(path: T.any(String, Symbol)).returns(String) }
|
|
42
52
|
def [](path)
|
|
43
|
-
path = path.to_s.gsub(
|
|
53
|
+
path = path.to_s.gsub(%r{\A/+}, '')
|
|
44
54
|
|
|
45
55
|
if Catalyst.development?
|
|
56
|
+
dev_server_protocol = Catalyst.config.dev_server_protocol
|
|
46
57
|
dev_server_host = Catalyst.config.dev_server_host
|
|
47
58
|
dev_server_port = Catalyst.config.dev_server_port
|
|
48
59
|
|
|
60
|
+
if dev_server_protocol.nil?
|
|
61
|
+
raise ::Catalyst::CatalystError,
|
|
62
|
+
'Missing "dev_server_protocol" configuration.'
|
|
63
|
+
end
|
|
64
|
+
|
|
49
65
|
if dev_server_host.nil?
|
|
50
|
-
raise
|
|
66
|
+
raise ::Catalyst::CatalystError,
|
|
67
|
+
'Missing "dev_server_host" configuration.'
|
|
51
68
|
end
|
|
52
69
|
|
|
53
70
|
if dev_server_port.nil?
|
|
54
|
-
raise
|
|
71
|
+
raise ::Catalyst::CatalystError,
|
|
72
|
+
'Missing "dev_server_port" configuration.'
|
|
55
73
|
end
|
|
56
74
|
|
|
57
|
-
|
|
75
|
+
"#{dev_server_protocol}://#{dev_server_host}:#{dev_server_port}/#{path}"
|
|
76
|
+
elsif assets.key?(path)
|
|
77
|
+
T.must(assets[path])
|
|
58
78
|
else
|
|
59
|
-
|
|
60
|
-
return @manifest[path]
|
|
61
|
-
else
|
|
62
|
-
raise AssetMissing, "Couldn't find an asset for path: #{path}"
|
|
63
|
-
end
|
|
79
|
+
raise AssetMissing, "Couldn't find an asset for path: #{path}"
|
|
64
80
|
end
|
|
65
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
|
|
66
121
|
end
|
|
67
122
|
end
|
data/lib/catalyst/railtie.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# typed: ignore
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
4
|
+
require 'rails'
|
|
3
5
|
require_relative './helpers'
|
|
4
6
|
|
|
5
7
|
module Catalyst
|
|
@@ -8,8 +10,6 @@ module Catalyst
|
|
|
8
10
|
ActionView::Base.include(::Catalyst::Helpers)
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
rake_tasks
|
|
12
|
-
load File.expand_path('./tasks/build.rake', __dir__)
|
|
13
|
-
end
|
|
13
|
+
rake_tasks { load File.expand_path('./tasks/build.rake', __dir__) }
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -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.beta2
|
|
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: 2021-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,25 +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
|
-
- - "
|
|
58
|
+
- - "~>"
|
|
42
59
|
- !ruby/object:Gem::Version
|
|
43
|
-
version:
|
|
44
|
-
|
|
60
|
+
version: 0.5.0
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rubocop
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.7'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
45
73
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
74
|
+
version: '1.7'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: sorbet
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 0.5.0
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 0.5.0
|
|
47
89
|
description:
|
|
48
90
|
email: dan@friendsoftheweb.com
|
|
49
91
|
executables: []
|
|
@@ -53,6 +95,7 @@ files:
|
|
|
53
95
|
- lib/catalyst-rails.rb
|
|
54
96
|
- lib/catalyst/builder.rb
|
|
55
97
|
- lib/catalyst/config.rb
|
|
98
|
+
- lib/catalyst/content_type.rb
|
|
56
99
|
- lib/catalyst/errors.rb
|
|
57
100
|
- lib/catalyst/helpers.rb
|
|
58
101
|
- lib/catalyst/manifest.rb
|
|
@@ -71,15 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
71
114
|
requirements:
|
|
72
115
|
- - ">="
|
|
73
116
|
- !ruby/object:Gem::Version
|
|
74
|
-
version:
|
|
117
|
+
version: 2.5.0
|
|
75
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
119
|
requirements:
|
|
77
|
-
- - "
|
|
120
|
+
- - ">"
|
|
78
121
|
- !ruby/object:Gem::Version
|
|
79
|
-
version:
|
|
122
|
+
version: 1.3.1
|
|
80
123
|
requirements: []
|
|
81
|
-
|
|
82
|
-
rubygems_version: 2.7.6.2
|
|
124
|
+
rubygems_version: 3.1.2
|
|
83
125
|
signing_key:
|
|
84
126
|
specification_version: 4
|
|
85
127
|
summary: Ruby helpers for the "catalyst" node package
|