Module: Capistrano::NewArtrailsCapistrano::FrontHelpers

Defined in:
lib/capistrano/new_artrails_capistrano/front_helpers.rb

Instance Method Summary collapse

Instance Method Details

#front_branchObject



7
8
9
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 7

def front_branch
  fetch(:front_branch) || 'master'
end

#front_checkout_commandObject



81
82
83
84
85
86
87
88
89
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 81

def front_checkout_command
  fetch(:front_checkout_command) ||
  <<-CMD
    git clone #{fetch(:front_repo_url)} #{front_local_cache} &&
    cd #{front_local_cache} &&
    git checkout -b deploy/#{front_branch} #{front_revision} &&
    #{front_install_command}
  CMD
end

#front_commandObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 91

def front_command
  if (File.exists?(front_local_cache) && File.directory?(front_local_cache))
    puts "[FRONT] updating front local cache to revision #{front_revision}"
    cmd = front_sync_command
  end
  unless (File.exists?(front_local_cache) || File.directory?(front_local_cache))
    puts "[FRONT] creating front local cache with revision #{front_revision}"
    File.delete(front_local_cache) if File.exists?(front_local_cache)
    Dir.mkdir(File.dirname(front_local_cache)) unless File.directory?(File.dirname(front_local_cache))

    cmd = front_checkout_command
  end
  cmd.gsub("\n", '')
end

#front_copy_commandObject

do not delete Rails’ Apache served folders



42
43
44
45
46
47
48
49
50
51
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 42

def front_copy_command
  assets_prefix = fetch(:assets_prefix) || 'assets'
  keeps = fetch(:backend_dirs_or_files_to_keep_in_public) || ([assets_prefix] + %w[ images system upload download])
  if keeps.empty?
    keep_string = ''
  else
    keep_string = ' ' + keeps.map { |keep| "--exclude=\'#{keep}\'" }.join(' ').to_s
  end
  "rsync -a --no-p --no-g --delete#{keep_string}"
end

#front_dist_dir_nameObject



25
26
27
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 25

def front_dist_dir_name
  fetch(:front_dist_dir_name) || 'dist'
end

#front_install_commandObject



61
62
63
64
65
66
67
68
69
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 61

def front_install_command
  fetch(:front_install_command) ||
  <<-CMD
    npm install &&
    bower install &&
    gulp clean &&
    gulp build
  CMD
end

#front_local_cacheObject



15
16
17
18
19
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 15

def front_local_cache
  front_application = fetch(:front_application)
  # "-#{fetch(:stage)}"
  fetch(:front_local_cache) || "/tmp/.#{front_application}_rsync_cache"
end

#front_release_pathObject



57
58
59
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 57

def front_release_path
  File.join(release_path, 'public')
end

#front_remote_cacheObject



106
107
108
109
110
111
112
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 106

def front_remote_cache
  lambda do
    cache = front_rsync_remote_cache
    cache = deploy_to + '/' + cache if cache && cache !~ /^\//
    cache
  end
end

#front_revisionObject



53
54
55
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 53

def front_revision
  @front_revision ||= `git ls-remote #{fetch(:front_repo_url)} #{front_branch}`.split("\t").first
end

#front_rsync_credentialsObject



21
22
23
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 21

def front_rsync_credentials
  fetch(:local_user)
end

#front_rsync_excludeObject



37
38
39
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 37

def front_rsync_exclude
  fetch(:front_rsync_exclude) || fetch(:rsync_exclude)
end

#front_rsync_includeObject



33
34
35
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 33

def front_rsync_include
  fetch(:front_rsync_include) || fetch(:rsync_include)
end

#front_rsync_optionsObject



29
30
31
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 29

def front_rsync_options
  fetch(:front_rsync_options) || fetch(:rsync_options)
end

#front_rsync_remote_cacheObject



11
12
13
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 11

def front_rsync_remote_cache
  fetch(:front_remote_cache) || "shared/front-cached-copy-#{fetch(:local_user) || 'deploy'}"
end

#front_sync_commandObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/capistrano/new_artrails_capistrano/front_helpers.rb', line 70

def front_sync_command
  fetch(:front_sync_command) ||
  <<-CMD
    cd #{front_local_cache} &&
    git fetch #{fetch(:front_repo_url)} #{front_branch} &&
    git fetch --tags #{fetch(:front_repo_url)} #{front_branch} &&
    git reset --hard #{front_revision} &&
    #{front_install_command}
  CMD
end