capistrano-sync-assets 0.0.9

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 780bfedc1c03d7c14f34f79876aa6f54b305397e
4
+ data.tar.gz: a2dc1349f582a37c4691f830ad3aaecbb09e7a73
5
+ SHA512:
6
+ metadata.gz: cb188befeec3c59e523a6b20c0019c201d9d1ecfc2813a162ed4b7c135d0aae26a8125232260f139768c899a0b28e34872b3b1254c370d18dce9905a7f88a679
7
+ data.tar.gz: 5ede5094a071775295a834ca98abb4a44ab45d88f4bcda5b3cff1dd1e62ea8f7342a5caa0cfdac6b5a25a65d6d952ba4e1cb58e2a6fb17c0ade8aa23efc7e280
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ .ruby-gemset
4
+ pkg/
5
+ *.DS_Store
6
+ tmp
data/README.markdown ADDED
@@ -0,0 +1,5 @@
1
+ Capistrano Assets sync
2
+ ======================
3
+
4
+ Add assets tasks to capistrano to a Rails project.
5
+ It only works with capistrano 3.
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "capistrano/sync/assets/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "capistrano-sync-assets"
8
+ s.version = Capistrano::Sync::Asset::VERSION.dup
9
+ s.platform = Gem::Platform::RUBY
10
+ s.license = 'MIT'
11
+ s.authors = ['David Fu']
12
+ s.email = ['lexuszhi1990@gmail.com']
13
+ s.summary = %q{Capistrano 3 extensions for assets sync}
14
+ s.description = %q{A collection of capistrano tasks for syncing assets}
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ s.add_dependency 'capistrano', '~> 3.0', '>= 3.0.1'
20
+ end
21
+
@@ -0,0 +1,30 @@
1
+ module Capistrano
2
+ module Sync
3
+ class Asset
4
+ def initialize(cap)
5
+ @user_host = [cap.host.user, cap.host.hostname].compact.join('@')
6
+ @port = cap.host.port || 22
7
+ end
8
+
9
+ def pull(local_asset_dir, server_asset_dir)
10
+ system "rsync -avrt --recursive --times --compress --human-readable --progress --delete --rsh='ssh -p #{@port}' #{@user_host}:#{server_asset_dir} #{local_asset_dir}"
11
+ end
12
+
13
+ def push(server_asset_dir, local_asset_dir)
14
+ system "rsync -avrt --recursive --times --compress --human-readable --progress --delete --rsh='ssh -p #{@port}' #{local_asset_dir} #{@user_host}:#{server_asset_dir}"
15
+ end
16
+
17
+ def backup_local_asset(local_asset_dir)
18
+ local_backup_dir = "#{local_asset_dir}_bak"
19
+ system("rm -r #{local_backup_dir}") if Dir.exist?(local_backup_dir)
20
+ system("cp -r #{local_asset_dir} #{local_backup_dir}") if Dir.exist?(local_asset_dir)
21
+ end
22
+
23
+ def backup_server_asset(server_asset_dir)
24
+ delete_exist_backup = "if [ -e #{server_asset_dir}_bak ]; then rm -r #{server_asset_dir}_bak; fi"
25
+ backup_assets = "if [ -e #{server_asset_dir} ]; then cp -r #{server_asset_dir} #{server_asset_dir}_bak; fi"
26
+ execute [delete_exist_backup, backup_assets].join(";")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ module Utils
2
+ class << self
3
+ def assets_dir(dir="")
4
+ # Benchmark.ips do |x|
5
+ # x.report("dir[0, dir.length-1]") do
6
+ # string = "/Users/david/bs_repos/tmp_repo/eio/"
7
+ # string[0, string.length-1]
8
+ # end
9
+ #
10
+ # x.report("split('/').join") do
11
+ # "/Users/david/bs_repos/tmp_repo/eio/".split('/').join("/")
12
+ # end
13
+ #
14
+ # x.compare!
15
+ # end
16
+ #
17
+ # Comparison:
18
+ # dir[0, dir.length-1]: 1844071.9 i/s
19
+ # split('/').join: 406966.0 i/s - 4.53x slower
20
+ dir.end_with?('/') ? dir[0, dir.length-1] : dir
21
+ end
22
+
23
+ def yes_or_no?(msg, prompt = "(y)es, (n)o")
24
+ ask(:answer, "#{msg} #{prompt}")
25
+ (fetch(:answer) =~ /^y$|^yes$/i) == 0
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Capistrano
2
+ module Sync
3
+ module Asset
4
+ VERSION = "0.0.9"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/assets.rake', __FILE__)
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../../assets/asset.rb', __FILE__)
2
+ require File.expand_path('../../assets/utils.rb', __FILE__)
3
+
4
+ namespace :sync do
5
+ namespace :assets do
6
+ desc 'Synchronize your remote assets using local assets'
7
+ task :push do
8
+ on release_roles :all do
9
+ within shared_path do
10
+ sync_assets_dirs = fetch(:sync_assets_dirs)
11
+ info "the assets dirs as #{sync_assets_dirs.join(', ')}"
12
+ asset = Capistrano::Sync::Asset.new(self)
13
+ sync_assets_dirs.each do |dir|
14
+ server_asset_dir = Utils.assets_dir "#{shared_path}/#{dir}"
15
+ local_asset_dir = Utils.assets_dir "#{Dir.pwd}/#{dir}"
16
+ if Utils.yes_or_no?("Are you SURE to upload the local assets to remote?")
17
+ asset.backup_server_asset(dir)
18
+ asset.push(local_asset_dir, server_asset_dir)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc 'Synchronize your local assets using remote assets'
26
+ task :pull do
27
+ on roles(:app) do
28
+ within shared_path do
29
+ with rails_env: fetch(:rails_env) do
30
+ sync_assets_dirs = fetch(:sync_assets_dirs)
31
+ info "the assets dirs as #{sync_assets_dirs.join(', ')}"
32
+ asset = Capistrano::Sync::Asset.new(self)
33
+ sync_assets_dirs.each do |dir|
34
+ server_asset_dir = Utils.assets_dir "#{shared_path}/#{dir}"
35
+ local_asset_dir = Utils.assets_dir "#{Dir.pwd}/#{dir}"
36
+ info "backup: moving #{local_asset_dir} to #{local_asset_dir}_bak"
37
+ asset.backup_local_asset(local_asset_dir)
38
+ info "sync the #{local_asset_dir} from server #{server_asset_dir}"
39
+ asset.pull(local_asset_dir, server_asset_dir)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
File without changes
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-sync-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - David Fu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
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: 3.0.1
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: 3.0.1
33
+ description: A collection of capistrano tasks for syncing assets
34
+ email:
35
+ - lexuszhi1990@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".gitignore"
41
+ - README.markdown
42
+ - capistrano-sync-assets.gemspec
43
+ - lib/capistrano-sync-assets.rb
44
+ - lib/capistrano/sync/assets.rb
45
+ - lib/capistrano/sync/assets/asset.rb
46
+ - lib/capistrano/sync/assets/utils.rb
47
+ - lib/capistrano/sync/assets/version.rb
48
+ - lib/capistrano/sync/tasks/assets.rake
49
+ homepage:
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Capistrano 3 extensions for assets sync
73
+ test_files: []