react-rails-hot-loader 0.6.0 → 0.7.0
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/README.md +2 -3
- data/lib/assets/react-rails-hot-loader.js.erb +15 -5
- data/lib/hot_loader/asset_change_set.rb +8 -6
- data/lib/hot_loader/server.rb +4 -1
- data/lib/hot_loader/version.rb +1 -1
- data/react-rails-hot-loader.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab9de518bb75c50cbeacaea338a7f88aab57810d
|
4
|
+
data.tar.gz: 416ae157991bbba3f40e672b1867509fe407e293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72353bf21ad48fe6dfbfc0a8b04f2f97ead8bf77c83e9d1ebd247e42b7e73ab4662d609f335b200110fbb9869cdc3d0a165cafdfaad29bc9c54c5c195211d4f5
|
7
|
+
data.tar.gz: 1357768dddb36e755a9bb920a1258ce2bd03146c464d92ffa57278075c7a4332ebb0178374755349f937c8120c63dc01449b476ca071ecb763cdcfb39f196670
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ If you notice that your assets are not being recompiled and hot loaded, it could
|
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
# config/initializers/react_rails_hot_loader.rb
|
48
|
-
React::Rails::HotLoader::AssetChangeSet.asset_glob = "**/*.{js,rb}*" # I <3 Opal
|
48
|
+
React::Rails::HotLoader::AssetChangeSet.asset_glob = "**/*.{css,sass,scss,js,rb}*" # I <3 Opal
|
49
49
|
```
|
50
50
|
|
51
51
|
You can choose a port to start it on (default is `8082`):
|
@@ -60,10 +60,9 @@ React::Rails::HotLoader.port = 8088
|
|
60
60
|
`react-rails-hot-loader` ...
|
61
61
|
|
62
62
|
- __does__ set up a WebSocket server & client
|
63
|
-
- __does__ reload JS assets when they change (from `/app/assets/javascripts/*.{js,coffee}*`)
|
63
|
+
- __does__ reload JS assets when they change (from `/app/assets/javascripts/*.{css,js,coffee}*`)
|
64
64
|
- __does__ remount components (via `ReactRailsUJS`) after reloading assets
|
65
65
|
- __doesn't__ reload Rails view files (`html`, `erb`, `slim`, etc)
|
66
|
-
- __doesn't__ reload CSS (although that could be fixed)
|
67
66
|
|
68
67
|
## TODO
|
69
68
|
|
@@ -52,11 +52,21 @@ var ReactRailsHotLoader = {
|
|
52
52
|
_hotLoad: function(changes) {
|
53
53
|
this.log("updating: " + changes.changed_file_names.join(", ") )
|
54
54
|
|
55
|
-
changes.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
changes.changed_file_names.forEach(function(fileName, i) {
|
56
|
+
var changedAssetContent = changes.changed_asset_contents[i]
|
57
|
+
|
58
|
+
if (fileName.indexOf(".js") > -1) {
|
59
|
+
// Reload JS
|
60
|
+
try {
|
61
|
+
eval.call(window, changedAssetContent)
|
62
|
+
} catch (err) {
|
63
|
+
_this.log(err)
|
64
|
+
}
|
65
|
+
} else {
|
66
|
+
// Reload CSS
|
67
|
+
var styleTag = document.createElement("style")
|
68
|
+
styleTag.textContent = changedAssetContent
|
69
|
+
document.head.appendChild(styleTag)
|
60
70
|
}
|
61
71
|
})
|
62
72
|
ReactRailsUJS.mountComponents()
|
@@ -5,17 +5,17 @@ module React
|
|
5
5
|
attr_reader :since, :path, :changed_files, :changed_file_names
|
6
6
|
class_attribute :asset_glob, :bankruptcy_count
|
7
7
|
# Search for changes with this glob
|
8
|
-
self.asset_glob = "/**/*.{js,coffee}*"
|
8
|
+
self.asset_glob = "/**/*.{css,sass,scss,js,coffee}*"
|
9
9
|
# If this many files change at once, give up hope! (Probably checked out a new branch)
|
10
10
|
self.bankruptcy_count = 5
|
11
11
|
|
12
12
|
# initialize with a path and time
|
13
13
|
# to find files which changed since that time
|
14
|
-
def initialize(since:, path: ::Rails.root.join("app/assets
|
14
|
+
def initialize(since:, path: ::Rails.root.join("app/assets"))
|
15
15
|
@since = since
|
16
16
|
@path = path.to_s
|
17
17
|
asset_glob = File.join(path, AssetChangeSet.asset_glob)
|
18
|
-
@changed_files = Dir.glob(asset_glob).select { |f| File.mtime(f) >= since }
|
18
|
+
@changed_files = Dir.glob(asset_glob).select { |f| File.mtime(f) >= since }.uniq
|
19
19
|
@changed_file_names = changed_files.map { |f| File.basename(f) }
|
20
20
|
end
|
21
21
|
|
@@ -48,9 +48,11 @@ module React
|
|
48
48
|
|
49
49
|
def to_logical_path(asset_path)
|
50
50
|
asset_path
|
51
|
-
.sub(@path, "")
|
52
|
-
.sub(
|
53
|
-
.sub(
|
51
|
+
.sub(@path, "") # remove the basepath
|
52
|
+
.sub(/(javascripts|stylesheets)\//, '') # remove the asset directory
|
53
|
+
.sub(/^\//, '') # remove any leading /
|
54
|
+
.sub(/\.js.*/, '.js') # uniform .js for js
|
55
|
+
.sub(/\.[sac]{1,2}ss.*/, '.css') # uniform .css for styles
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
data/lib/hot_loader/server.rb
CHANGED
@@ -10,6 +10,7 @@ module React
|
|
10
10
|
@host = host
|
11
11
|
@port = port
|
12
12
|
@change_set_class = change_set_class
|
13
|
+
@processed_msg = Hash.new
|
13
14
|
end
|
14
15
|
|
15
16
|
# Restarts the server _if_ it has stopped
|
@@ -37,9 +38,10 @@ module React
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
# Check for any changes since `msg`, respond if there are any changes
|
41
|
+
# Check for any changes since `msg`, respond if there are any changes, skip if msg was already processed (queue issue)
|
41
42
|
def handle_message(ws, msg)
|
42
43
|
# React::Rails::HotLoader.log("received message: #{msg}")
|
44
|
+
return true if @processed_msg[ws.signature] == msg
|
43
45
|
since_time = Time.at(msg.to_i)
|
44
46
|
changes = change_set_class.new(since: since_time)
|
45
47
|
if changes.bankrupt?
|
@@ -55,6 +57,7 @@ module React
|
|
55
57
|
elsif changes.any?
|
56
58
|
React::Rails::HotLoader.log("sent changes: #{changes.changed_file_names}")
|
57
59
|
ws.send(changes.to_json)
|
60
|
+
@processed_msg[ws.signature] = msg
|
58
61
|
end
|
59
62
|
rescue StandardError => err
|
60
63
|
React::Rails::HotLoader.error(err)
|
data/lib/hot_loader/version.rb
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "guard-minitest"
|
31
31
|
spec.add_development_dependency "minitest"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "sass-rails"
|
33
34
|
spec.add_development_dependency "sqlite3"
|
34
35
|
spec.add_development_dependency "thin"
|
35
36
|
spec.add_development_dependency "websocket-client-simple"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react-rails-hot-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-websocket
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '10.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sass-rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: sqlite3
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|