sprockets-derailleur 0.0.6 → 0.0.7
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.
- data/README.md +68 -4
- data/lib/sprockets-derailleur/manifest.rb +32 -2
- data/lib/sprockets-derailleur/version.rb +1 -1
- metadata +32 -49
data/README.md
CHANGED
@@ -22,14 +22,78 @@ Require `sprockets-derailleur` in environment file:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
To install to an existing rails 3.2 project, first create a new file, 'sprockets_derailleur.rb' in config/initializers.
|
26
26
|
|
27
|
-
|
27
|
+
Here we need to override some core parts of the sprockets module.
|
28
28
|
|
29
|
-
|
29
|
+
```ruby
|
30
|
+
module Sprockets
|
31
|
+
class StaticCompiler
|
30
32
|
|
31
|
-
|
33
|
+
alias_method :compile_without_manifest, :compile
|
34
|
+
def compile
|
35
|
+
|
36
|
+
# Determine how many workers you want to use first. Determine the number of physical CPUs this way
|
37
|
+
processes = SprocketsDerailleur::number_of_processors rescue 1
|
38
|
+
|
39
|
+
puts "Multithreading on " + processes.to_s + " processors"
|
40
|
+
puts "Starting Asset Compile: " + Time.now.getutc.to_s
|
41
|
+
|
42
|
+
# Then initialize the manifest with the workers you just determined
|
43
|
+
manifest = Sprockets::Manifest.new(env, target, processes)
|
44
|
+
manifest.compile paths
|
45
|
+
|
46
|
+
puts "Finished Asset Compile: " + Time.now.getutc.to_s
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Railtie < ::Rails::Railtie
|
52
|
+
config.after_initialize do |app|
|
53
|
+
|
54
|
+
config = app.config
|
55
|
+
next unless config.assets.enabled
|
56
|
+
|
57
|
+
if config.assets.manifest
|
58
|
+
path = File.join(config.assets.manifest, "manifest.json")
|
59
|
+
else
|
60
|
+
path = File.join(Rails.public_path, config.assets.prefix, "manifest.json")
|
61
|
+
end
|
62
|
+
|
63
|
+
if File.exist?(path)
|
64
|
+
manifest = Sprockets::Manifest.new(app, path)
|
65
|
+
config.assets.digests = manifest.assets
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
The first block that overrides compile method starts sprockets derailleur with the chosen number of worker threads.
|
75
|
+
For maximum performance this should be the same number of processor cores on your compile machine.
|
76
|
+
|
77
|
+
The second block that is called after rails initializes is there because newer versions of sprockets are writing your
|
78
|
+
digested assets to manifest.json (Rails 4), instead of manifest.yml (Rails 3.2).
|
79
|
+
|
80
|
+
We therefore load in manifest.json using the Rails 4 method, as your asset compile will write this file. To avoid a duplicate
|
81
|
+
load, remember to delete the old manifest.yml from your public/assets folder.
|
82
|
+
|
83
|
+
A word of caution however, some gems that work with the asset pipeline still expect manifest.yml to exist.
|
84
|
+
|
85
|
+
Sprockets derailleur is known to work with (and possibly others):
|
86
|
+
|
87
|
+
- turbo-sprockets-rails3
|
88
|
+
- asset-sync
|
89
|
+
|
90
|
+
If you only intent to use digest assets, for example in production environments, you can also speed up your compile by using
|
91
|
+
|
92
|
+
```
|
93
|
+
rake assets:precompile:primary RAILS_ENV=production
|
94
|
+
```
|
32
95
|
|
96
|
+
This skips the non-digest compile, hence doubling speed (especially useful if syncing assets with a remote server).
|
33
97
|
|
34
98
|
## Contributing
|
35
99
|
|
@@ -12,10 +12,24 @@ module Sprockets
|
|
12
12
|
|
13
13
|
alias_method :compile_with_workers, :compile
|
14
14
|
def compile(*args)
|
15
|
+
paths_with_errors = {}
|
16
|
+
|
15
17
|
time = Benchmark.measure do
|
16
18
|
paths = environment.each_logical_path(*args).to_a +
|
17
19
|
args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)}
|
18
20
|
|
21
|
+
# Skip all files without extensions, see
|
22
|
+
# https://github.com/sstephenson/sprockets/issues/347 for more info
|
23
|
+
paths = paths.select do |path|
|
24
|
+
|
25
|
+
if File.extname(path) == ""
|
26
|
+
logger.info "Skipping #{path} since it has no extension"
|
27
|
+
false
|
28
|
+
else
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
19
33
|
logger.warn "Initializing #{@workers} workers"
|
20
34
|
|
21
35
|
workers = []
|
@@ -33,10 +47,13 @@ module Sprockets
|
|
33
47
|
break if finished >= paths.size
|
34
48
|
|
35
49
|
ready = IO.select(reads, writes)
|
50
|
+
|
36
51
|
ready[0].each do |readable|
|
37
52
|
data = Marshal.load(readable)
|
38
53
|
assets.merge! data["assets"]
|
39
54
|
files.merge! data["files"]
|
55
|
+
paths_with_errors.merge! data["errors"]
|
56
|
+
|
40
57
|
finished += 1
|
41
58
|
end
|
42
59
|
|
@@ -63,6 +80,14 @@ module Sprockets
|
|
63
80
|
end
|
64
81
|
|
65
82
|
logger.warn "Completed compiling assets (#{(time.real * 100).round / 100.0}s)"
|
83
|
+
|
84
|
+
unless paths_with_errors.empty?
|
85
|
+
logger.warn "Asset paths with errors:"
|
86
|
+
|
87
|
+
paths_with_errors.each do |path, message|
|
88
|
+
logger.warn "\t#{path}: #{message}"
|
89
|
+
end
|
90
|
+
end
|
66
91
|
end
|
67
92
|
|
68
93
|
def worker(paths)
|
@@ -78,8 +103,9 @@ module Sprockets
|
|
78
103
|
path = paths[Marshal.load(child_read)]
|
79
104
|
|
80
105
|
time = Benchmark.measure do
|
106
|
+
data = {'assets' => {}, 'files' => {}, 'errors' => {}}
|
107
|
+
|
81
108
|
if asset = find_asset(path)
|
82
|
-
data = {'assets' => {}, 'files' => {}}
|
83
109
|
|
84
110
|
data['files'][asset.digest_path] = {
|
85
111
|
'logical_path' => asset.logical_path,
|
@@ -98,10 +124,14 @@ module Sprockets
|
|
98
124
|
asset.write_to target
|
99
125
|
end
|
100
126
|
|
127
|
+
Marshal.dump(data, child_write)
|
128
|
+
else
|
129
|
+
data['errors'][path] = "Not found"
|
101
130
|
Marshal.dump(data, child_write)
|
102
131
|
end
|
103
132
|
end
|
104
|
-
|
133
|
+
|
134
|
+
logger.warn "Compiled #{path} (#{(time.real * 1000).round}ms, pid #{Process.pid})"
|
105
135
|
end
|
106
136
|
ensure
|
107
137
|
child_read.close
|
metadata
CHANGED
@@ -1,46 +1,39 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-derailleur
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Steel Fu
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: sprockets
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
version: "2"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2'
|
32
22
|
type: :runtime
|
33
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2'
|
34
30
|
description: Speed up sprockets compiling by forking processes
|
35
|
-
email:
|
31
|
+
email:
|
36
32
|
- steelfu@gmail.com
|
37
33
|
executables: []
|
38
|
-
|
39
34
|
extensions: []
|
40
|
-
|
41
35
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
36
|
+
files:
|
44
37
|
- .gitignore
|
45
38
|
- Gemfile
|
46
39
|
- LICENSE.txt
|
@@ -52,36 +45,26 @@ files:
|
|
52
45
|
- sprockets-derailleur.gemspec
|
53
46
|
homepage: https://github.com/steel/sprockets-derailleur
|
54
47
|
licenses: []
|
55
|
-
|
56
48
|
post_install_message:
|
57
49
|
rdoc_options: []
|
58
|
-
|
59
|
-
require_paths:
|
50
|
+
require_paths:
|
60
51
|
- lib
|
61
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
53
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
|
67
|
-
|
68
|
-
- 0
|
69
|
-
version: "0"
|
70
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
59
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
version: "0"
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
79
64
|
requirements: []
|
80
|
-
|
81
65
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
66
|
+
rubygems_version: 1.8.23
|
83
67
|
signing_key:
|
84
68
|
specification_version: 3
|
85
69
|
summary: Multi process sprockets compiling
|
86
70
|
test_files: []
|
87
|
-
|