thunder_punch 0.1.1 → 0.1.2
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.mdown +4 -0
- data/VERSION +1 -1
- data/files/assets/assets.rake +12 -0
- data/files/assets/assets_versions.rb +63 -0
- data/lib/thunder_punch/recipes/asset_pipeline/assets_version.rb +64 -0
- data/lib/thunder_punch/recipes/asset_pipeline/precompile.rb +22 -0
- data/lib/thunder_punch/recipes/assets.rb +3 -0
- data/thunder_punch.gemspec +1 -1
- metadata +6 -1
data/README.mdown
CHANGED
@@ -31,6 +31,10 @@ end
|
|
31
31
|
###Complex setup
|
32
32
|
*TODO*
|
33
33
|
|
34
|
+
#### Assets recipe
|
35
|
+
* In order to use the assets recipes you'll need to copy the two files in files/assets into their appropriate places. See the comments at the top of each file for where to place them.
|
36
|
+
* Once the files are copied you can use assets:precompile_if_needed for fast deploys that only precompile assets when it's neccessary.
|
37
|
+
|
34
38
|
##Reasoning
|
35
39
|
|
36
40
|
By creating a central and organized system for our tasks we can reduce the content in our deploy.rb files to be project specific and make the addition of new tasks easy and compatible.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# in lib/assets_version.rb
|
2
|
+
# https://gist.github.com/afcapel/7cf9f46fbc56be6f8512
|
3
|
+
require 'yaml'
|
4
|
+
require 'English'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
class AssetsVersion < OpenStruct
|
8
|
+
|
9
|
+
REVISIONS_FILE = "config/assets_version.yml"
|
10
|
+
|
11
|
+
ASSETS_DEPENDENCIES = {
|
12
|
+
'gemfile_lock' => 'Gemfile.lock',
|
13
|
+
'assets_dir' => 'app/assets',
|
14
|
+
'vendor_dir' => 'vendor',
|
15
|
+
}
|
16
|
+
|
17
|
+
def self.needs_precompile?
|
18
|
+
@last = last_version
|
19
|
+
@current = current
|
20
|
+
|
21
|
+
@last.incomplete? || @current.incomplete? || @current != @last
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.last_version
|
25
|
+
revisions = load_revisions_from_yaml_file
|
26
|
+
AssetsVersion.new(revisions)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.current
|
30
|
+
revisions = {}
|
31
|
+
|
32
|
+
ASSETS_DEPENDENCIES.each do |key, file|
|
33
|
+
revisions[key] = git_revision_for(file)
|
34
|
+
end
|
35
|
+
|
36
|
+
AssetsVersion.new(revisions)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.load_revisions_from_yaml_file
|
40
|
+
YAML.load_file(REVISIONS_FILE)
|
41
|
+
rescue
|
42
|
+
Hash.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.git_revision_for(file)
|
46
|
+
rev = `git log -n 1 --format="%H" #{file}`
|
47
|
+
|
48
|
+
$CHILD_STATUS.success? ? rev.strip : nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def save_to_yaml
|
52
|
+
File.open(REVISIONS_FILE, "w") { |f| f.write(to_json) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def incomplete?
|
56
|
+
revisions = ASSETS_DEPENDENCIES.keys.collect { |k| send(k) }
|
57
|
+
revisions.any?(&:nil?) || revisions.any?(&:empty?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_json
|
61
|
+
YAML.to_json(marshal_dump)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# lib/assets_version.rb
|
2
|
+
require 'yaml'
|
3
|
+
require 'english'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
class AssetsVersion < OpenStruct
|
7
|
+
|
8
|
+
# ensure this file is symlinked to your Capistrano shared folder
|
9
|
+
# and is kept between deployments
|
10
|
+
REVISIONS_FILE = "config/assets_version.yml"
|
11
|
+
|
12
|
+
ASSETS_DEPENDENCIES = {
|
13
|
+
'gemfile_lock' => 'Gemfile.lock',
|
14
|
+
'assets_dir' => 'app/assets',
|
15
|
+
'vendor_dir' => 'vendor',
|
16
|
+
}
|
17
|
+
|
18
|
+
def self.needs_precompile?
|
19
|
+
@last = last_version
|
20
|
+
@current = current
|
21
|
+
|
22
|
+
@last.incomplete? || @current.incomplete? || @current != @last
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.last_version
|
26
|
+
revisions = load_revisions_from_yaml_file
|
27
|
+
AssetsVersion.new(revisions)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.current
|
31
|
+
revisions = {}
|
32
|
+
|
33
|
+
ASSETS_DEPENDENCIES.each do |key, file|
|
34
|
+
revisions[key] = git_revision_for(file)
|
35
|
+
end
|
36
|
+
|
37
|
+
AssetsVersion.new(revisions)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.load_revisions_from_yaml_file
|
41
|
+
YAML.load_file(REVISIONS_FILE)
|
42
|
+
rescue
|
43
|
+
Hash.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.git_revision_for(file)
|
47
|
+
rev = `git log -n 1 --format="%H" #{file}`
|
48
|
+
|
49
|
+
$CHILD_STATUS.success? ? rev.strip : nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def save_to_yaml
|
53
|
+
File.open(REVISIONS_FILE, "w") { |f| f.write(to_json) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def incomplete?
|
57
|
+
revisions = ASSETS_DEPENDENCIES.keys.collect { |k| send(k) }
|
58
|
+
revisions.any?(&:nil?) || revisions.any?(&:empty?)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_json
|
62
|
+
YAML.to_json(marshal_dump)
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
_cset :asset_roles, [:app]
|
3
|
+
|
4
|
+
namespace :assets do
|
5
|
+
task :precompile_if_needed, :roles => asset_roles do
|
6
|
+
precompile_needed = capture "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} assets:precompile_needed"
|
7
|
+
|
8
|
+
if precompile_needed.strip == "true"
|
9
|
+
precompile
|
10
|
+
save_assets_versions
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
task :precompile, :roles => asset_roles do
|
15
|
+
run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} assets:precompile"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :save_assets_versions, :roles => asset_roles do
|
19
|
+
run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} assets:save_assets_versions"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/thunder_punch.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thunder_punch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -61,9 +61,14 @@ files:
|
|
61
61
|
- VERSION
|
62
62
|
- example/amazon.yml
|
63
63
|
- files/app/maintenance.html.erb
|
64
|
+
- files/assets/assets.rake
|
65
|
+
- files/assets/assets_versions.rb
|
64
66
|
- lib/thunder_punch.rb
|
65
67
|
- lib/thunder_punch/recipes.rb
|
66
68
|
- lib/thunder_punch/recipes/apache.rb
|
69
|
+
- lib/thunder_punch/recipes/asset_pipeline/assets_version.rb
|
70
|
+
- lib/thunder_punch/recipes/asset_pipeline/precompile.rb
|
71
|
+
- lib/thunder_punch/recipes/assets.rb
|
67
72
|
- lib/thunder_punch/recipes/bundler.rb
|
68
73
|
- lib/thunder_punch/recipes/database.rb
|
69
74
|
- lib/thunder_punch/recipes/deployment.rb
|