assets-watchify 0.0.1 → 0.1.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/.gitignore +18 -17
- data/FarMenu.ini +9 -0
- data/README.md +42 -1
- data/assets-watchify.gemspec +5 -2
- data/lib/assets/watchify.rb +13 -4
- data/lib/assets/watchify/boot.rb +15 -0
- data/lib/assets/watchify/main.rb +87 -0
- data/lib/assets/watchify/sprockets.rb +5 -0
- data/lib/assets/watchify/version.rb +1 -1
- data/rakelib/apps.rake +47 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6519bce265467ff70f9aa5a3395b57b8c9bd6e43
|
4
|
+
data.tar.gz: 42714426fe29eb535132b497c19195a8ed6b449d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 818a3e4dbabb7b1bcbb6942f347f30c16a5185a3c8ad9d4442247459475222fefe7b0eb5087d447e6ecc583808477bc97d2e851d56779df9968560b2be64abf7
|
7
|
+
data.tar.gz: 7ef6c60bc8bbc2e410bdf35fd8deb3bbd8b6e80f2571a9699c7a4abedc703824cb4f6ea8dab16c4e5929f8db7b376946b6b1a40549c26a6a751914ee5d0b9f76
|
data/.gitignore
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
/test
|
data/FarMenu.ini
CHANGED
@@ -7,3 +7,12 @@ L: Install gem locally
|
|
7
7
|
bundle exec rake install
|
8
8
|
U: Uninstall gem
|
9
9
|
gem uninstall -a assets-watchify
|
10
|
+
--:
|
11
|
+
R: Run Rails
|
12
|
+
cd test/v3
|
13
|
+
rails s -p 3003 -new_console:cb
|
14
|
+
cd ../..
|
15
|
+
cd test/v4
|
16
|
+
rails s -p 3004 -new_console:cb
|
17
|
+
cd ../..
|
18
|
+
start test/index.html
|
data/README.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# Assets::Watchify
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/assets-watchify)
|
4
|
+
|
3
5
|
Fast serving Rails assets in development.
|
4
6
|
|
7
|
+
This Gem doesn't use Watchify, Browserify or Node.js.
|
8
|
+
Rails Assets Pipeline is smart enough to do all the job.
|
9
|
+
We just set a couple of hooks.
|
10
|
+
|
5
11
|
## Installation
|
6
12
|
|
7
13
|
Add this line to your application's Gemfile:
|
@@ -21,14 +27,49 @@ $ gem install assets-watchify
|
|
21
27
|
```
|
22
28
|
## Usage
|
23
29
|
|
24
|
-
Create folder `public
|
30
|
+
Create folder `public/assets/w6y` and start rails server.
|
31
|
+
|
32
|
+
## Operation
|
33
|
+
|
34
|
+
The Gem:
|
35
|
+
|
36
|
+
* Instructs Rails to concatenate CSS files together
|
37
|
+
* Installs hook on generating JavaScript tag
|
38
|
+
* Combines all JavaScript assets into single file
|
39
|
+
* Generates SourceMap for concatenated JavaScript
|
40
|
+
* Listens to changes in asset folders and rebuilds JavaScript files
|
41
|
+
|
42
|
+
For Rails v3 it's enough.
|
43
|
+
|
44
|
+
Rails v4 is slooow serving large files (and combined JavaScript is large!).
|
45
|
+
Use nginx as reverse proxy:
|
25
46
|
|
47
|
+
```
|
48
|
+
server {
|
49
|
+
listen 80;
|
50
|
+
|
51
|
+
root /my/Rails/app/public;
|
52
|
+
|
53
|
+
location @Rails {
|
54
|
+
proxy_pass http://127.0.0.1:3000;
|
55
|
+
}
|
56
|
+
|
57
|
+
location / {
|
58
|
+
try_files $uri @Rails;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
```
|
26
63
|
|
27
64
|
## See also
|
28
65
|
|
66
|
+
* [OpenSSL::Win::Root](https://github.com/ukoloff/openssl-win-root)
|
29
67
|
* [ExecJS::Xtrn](https://github.com/ukoloff/execjs-xtrn)
|
30
68
|
|
31
69
|
## Credits
|
32
70
|
|
33
71
|
* [Ruby](https://www.ruby-lang.org/)
|
34
72
|
* [Ruby on Rails](http://rubyonrails.org/)
|
73
|
+
* [nginx](http://nginx.org/)
|
74
|
+
* Gem [source_map](https://github.com/ConradIrwin/ruby-source_map)
|
75
|
+
* [Listen](https://github.com/guard/listen)
|
data/assets-watchify.gemspec
CHANGED
@@ -21,8 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "railties"
|
22
22
|
spec.add_dependency 'source_map'
|
23
23
|
spec.add_dependency 'listen'
|
24
|
-
|
25
|
-
|
24
|
+
if Gem.win_platform?
|
25
|
+
spec.add_dependency 'wdm'
|
26
|
+
spec.add_dependency 'execjs-xtrn'
|
27
|
+
spec.add_dependency 'openssl-win-root'
|
28
|
+
end
|
26
29
|
|
27
30
|
spec.add_development_dependency "bundler", "~> 1.3"
|
28
31
|
spec.add_development_dependency "rake"
|
data/lib/assets/watchify.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
|
1
|
+
require_relative "watchify/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
if Gem.win_platform?
|
4
|
+
require 'execjs/xtrn'
|
5
|
+
require 'openssl/win/root'
|
6
|
+
end
|
7
|
+
|
8
|
+
class Rails::Application
|
9
|
+
initializer :assets_watchify do
|
10
|
+
require_relative 'watchify/boot'
|
6
11
|
end
|
7
12
|
end
|
13
|
+
|
14
|
+
module Assets::Watchify
|
15
|
+
Bundles={}
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "version"
|
2
|
+
|
3
|
+
module Assets::Watchify
|
4
|
+
Folder='w6y'
|
5
|
+
|
6
|
+
Root=Rails.root.join "public/assets", Folder
|
7
|
+
|
8
|
+
def self.use?
|
9
|
+
defined?(Rails::Server) &&
|
10
|
+
'development'==Rails.env &&
|
11
|
+
Dir.exist?(Root)
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative "main" if use?
|
15
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'source_map'
|
2
|
+
require 'listen'
|
3
|
+
require 'wdm' if Gem.win_platform?
|
4
|
+
|
5
|
+
module Assets::Watchify
|
6
|
+
Helper=Sprockets::Helpers::RailsHelper rescue Sprockets::Rails::Helper
|
7
|
+
|
8
|
+
require_relative 'sprockets'
|
9
|
+
|
10
|
+
def self.clean
|
11
|
+
Dir.glob Root.join '**', '*' do |f|
|
12
|
+
File.delete f rescue nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.mkdir
|
17
|
+
FileUtils.mkpath Root
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.rmdir
|
21
|
+
FileUtils.remove_entry Root
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.ms seconds
|
25
|
+
seconds.round 3
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.jstag name
|
29
|
+
return unless String===name
|
30
|
+
t1 = Time.now
|
31
|
+
name+='.js' if File.extname(name).empty?
|
32
|
+
begin
|
33
|
+
z = Rails.application.assets[name]
|
34
|
+
rescue=> e
|
35
|
+
return "<div class='alert alert-error'><pre>#{e.message}</pre></div>"
|
36
|
+
end
|
37
|
+
|
38
|
+
t2 = Time.now
|
39
|
+
|
40
|
+
unless File.exist? js = Root.join(z.digest_path)
|
41
|
+
File.delete Bundles[name], "#{Bundles[name]}.map" rescue nil if Bundles[name]
|
42
|
+
Bundles[name] = js
|
43
|
+
FileUtils.mkpath js.dirname
|
44
|
+
jsf = File.open js, 'w+'
|
45
|
+
map = SourceMap.new file: js.basename, source_root: '/assets', generated_output: jsf
|
46
|
+
z.to_a.each {|d| map.add_generated d.source, source: d.logical_path+'?body=1'}
|
47
|
+
map.save "#{js}.map"
|
48
|
+
jsf.puts
|
49
|
+
jsf.puts "//# sourceMappingURL=#{File::basename js}.map"
|
50
|
+
jsf.close
|
51
|
+
t3 = Time.now
|
52
|
+
puts "#{self} built '#{name}' (#{ms t2-t1}+#{ms t3-t2}=#{ms t3-t1})..."
|
53
|
+
end
|
54
|
+
"<script src='/assets/#{Folder}/#{z.digest_path}'></script><!-- #{z.length}/#{z.to_a.length} -->"
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.ping
|
58
|
+
Bundles.keys.each{|name| jstag name}
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.start!
|
62
|
+
clean
|
63
|
+
Rails.application.config.assets.debug = false # Let CSS to glue either
|
64
|
+
|
65
|
+
paths=Rails.application.config.assets.paths
|
66
|
+
|
67
|
+
Thread.new do
|
68
|
+
listener = Listen.to paths do |m,a,r|
|
69
|
+
m.each {|f| puts "~ #{f}"}
|
70
|
+
a.each {|f| puts "+ #{f}"}
|
71
|
+
r.each {|f| puts "- #{f}"}
|
72
|
+
ping
|
73
|
+
end
|
74
|
+
listener.start
|
75
|
+
puts "#{self} listening to changes in #{paths.count} folders..."
|
76
|
+
at_exit do
|
77
|
+
puts "#{self } stop listening to folders..."
|
78
|
+
listener.stop
|
79
|
+
clean
|
80
|
+
end
|
81
|
+
sleep 1
|
82
|
+
ping
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
start!
|
87
|
+
end
|
data/rakelib/apps.rake
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
namespace :apps do
|
2
|
+
desc 'Install rails for testing'
|
3
|
+
task :init do
|
4
|
+
require 'fileutils'
|
5
|
+
FileUtils.mkdir_p "test"
|
6
|
+
html=File.open "test/index.html", 'a'
|
7
|
+
%w(3 4).each do |ver|
|
8
|
+
html.puts "<li><a href='http://localhost:300#{ver}'>v#{ver}</a>"
|
9
|
+
FileUtils.mkdir_p app="test/v#{ver}"
|
10
|
+
next if File.exists? gemfile="#{app}/Gemfile"
|
11
|
+
system *%w(bundle init), chdir: app
|
12
|
+
File.open gemfile, 'a' do |f|
|
13
|
+
f.puts "gem 'rails', '~>#{ver}'"
|
14
|
+
end
|
15
|
+
system *%w(bundle install), chdir: app
|
16
|
+
system *%w(bundle exec rails new . --force --skip-bundle), chdir: app
|
17
|
+
gf=File.read(gemfile).each_line.reject{|s|/tzinfo-data/.match s}+
|
18
|
+
<<-EOG.each_line.map(&:lstrip)
|
19
|
+
gem 'byebug', group: :development
|
20
|
+
gem 'assets-watchify', path: '../..'
|
21
|
+
gem 'therubyracer' unless Gem.win_platform?
|
22
|
+
gem 'tzinfo-data' if #{'3'==ver ? 'false' : 'Gem.win_platform?'}
|
23
|
+
EOG
|
24
|
+
File.write gemfile, gf*""
|
25
|
+
system *%w(bundle install), chdir: app
|
26
|
+
system *%w(bundle exec rails g controller welcome index), chdir: app
|
27
|
+
File.unlink "#{app}/public/index.html" rescue nil
|
28
|
+
FileUtils.mkdir_p "#{app}/public/assets/w6y"
|
29
|
+
File.open "#{app}/config/initializers/w6y.rb", 'w' do |f|
|
30
|
+
f.puts <<-EOF.each_line.map(&:strip)
|
31
|
+
Assets::Watchify::Bundles['application.js']=nil if defined? Assets::Watchify::Bundles
|
32
|
+
EOF
|
33
|
+
end
|
34
|
+
File.open "#{app}/config/routes.rb", 'w' do |f|
|
35
|
+
f.puts <<-EOF
|
36
|
+
Rails.application.routes.draw do
|
37
|
+
root to: "welcome#index"
|
38
|
+
end
|
39
|
+
EOF
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :clear do
|
45
|
+
FileUtils.remove_dir 'test'
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assets-watchify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas Ukolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: openssl-win-root
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +137,11 @@ files:
|
|
123
137
|
- Rakefile
|
124
138
|
- assets-watchify.gemspec
|
125
139
|
- lib/assets/watchify.rb
|
140
|
+
- lib/assets/watchify/boot.rb
|
141
|
+
- lib/assets/watchify/main.rb
|
142
|
+
- lib/assets/watchify/sprockets.rb
|
126
143
|
- lib/assets/watchify/version.rb
|
144
|
+
- rakelib/apps.rake
|
127
145
|
homepage: https://github.com/ukoloff/assets-watchify
|
128
146
|
licenses:
|
129
147
|
- MIT
|