lightning_sites 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lightning_sites.rb +85 -80
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c9a1569774bfe05b1e01f959bd6f4d3b7b5c05c
4
- data.tar.gz: 446b60d2624050b0f5fee04f4ffd69c72f1f1651
3
+ metadata.gz: 5eb48e5d44bd72ee855567318c8be2bc02d0d6de
4
+ data.tar.gz: a9c29e9ecb2d496f8b54c63417e5cf544dfe22d6
5
5
  SHA512:
6
- metadata.gz: 6f520f1fb6820e5c9b4af36593a5161795eb99956b0be7218e9a1ee01977d3fdb61631273017e1935e6268197baab42e17efa486c8f20c231a383cf018ee0569
7
- data.tar.gz: b59b4879258829763ae9fbc6ace052da43a652451f954ca072e23aaca77f9f8db9521fa8b5f7e25905277965602d6fc2029eff204163f53aaab1f0c0573d3079
6
+ metadata.gz: 23303c02ecd83a909732985cafa913df1c3dd894e8c6b257d61b9935c3dffc68eb424a5555354f1c609eeaf756ce3e6eee8bac21728ac2673843016672aa5319
7
+ data.tar.gz: 91a2191df18eb191f0a22e53d93b2c74dce31ee46fb5c865cefc5d03c85a4f6875dd2318d89b5168d3bfd58061a4efc8e74fae060cc63f2d861dc52d10fb65a9
@@ -3,32 +3,32 @@ require 'colorize'
3
3
  # http://stackoverflow.com/a/11320444/300224
4
4
  Rake::TaskManager.record_task_metadata = true
5
5
 
6
- ##
7
- ## EVERY SITE MUST DEFINE THESE VARIABLES:
8
- ##
9
- @source_dir = 'source' # Editable source code
10
- @build_dir = 'build' # Built HTML code
11
- ##
12
- ##
13
- ## REQUIRED VARIABLES FOR DEPLOYMENT:
14
- ##
15
- ## @production_dir A local or remote directory (rsync format) to deploy to
16
- ## Good example: 'horseslov@172.16.11.23:/www'
17
- ## @production_backup_targets Hash of {name => what_should_backup_to_there}
18
- ## Good example: {'logs' => 'horseslov@172.16.11.23:/logs', ...}
19
- @production_backup_dir = 'production_backups'
20
-
21
- ##
22
- ## COLOR SCHEME
23
- ##
24
- ## ...
25
- ##
26
-
27
- module LightningSites
28
- # Your code goes here...
6
+ ################################################################################
7
+ ## Your Rakefile can override these variables
8
+ ################################################################################
9
+ @source_dir = 'source' # Editable source code, preferrably in git repo
10
+ @build_dir = 'BUILD' # Built HTML code
11
+ @backup_dir = 'BACKUPS' # Local home for backups of remote server
12
+ @remote_dir = '/dev/null' # Your remote server, use rsync format
13
+ @backup_targets = {} # Hash from local name to remote directory
14
+ # uses rsync naming format, example:
15
+ # {
16
+ # 'www' => 'horseslov@172.16.11.23:/www',
17
+ # 'logs' => 'horseslov@172.16.11.23:/logs'
18
+ # }
19
+ @build_excludes = [ # Files you do NOT want copied from SOURCE to BUILD
20
+ 'Gemfile', # use rsync format
21
+ 'Gemfile.lock',
22
+ '.bundle',
23
+ '.git',
24
+ '/tmp'
25
+ ]
26
+
27
+ def create_build_dir (build_dir=@build_dir)
28
+ FileUtils.mkdir_p build_dir
29
+ #TODO: output if directory did not exist and we created it
29
30
  end
30
31
 
31
- # Note: this stuff works even if only your SOURCE_DIR is checked into git
32
32
  namespace :git do
33
33
  def source_dir_is_git?
34
34
  return false if !File.directory?(@source_dir)
@@ -37,9 +37,13 @@ namespace :git do
37
37
 
38
38
  desc "Incorporate changes from the remote repository into the current branch"
39
39
  task :pull do
40
- puts 'Pulling git'.blue
40
+ if !source_dir_is_git?
41
+ puts "There is no git directory, skipping"
42
+ next
43
+ end
44
+ puts '⚡️ Pulling git'.blue
41
45
  sh "cd '#{@source_dir}'; git pull"
42
- puts 'Pulled'.green
46
+ puts 'Pulled'.green
43
47
  end
44
48
 
45
49
  desc "Displays paths that have differences between the index file and the current HEAD commit"
@@ -58,8 +62,10 @@ namespace :git do
58
62
  puts "There is no git directory, skipping"
59
63
  next
60
64
  end
65
+ puts '📋 Here is the modification date for each file'.blue
66
+ sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}", noop: true
61
67
  puts 'Modified File'.blue
62
- sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}"
68
+ sh "cd #{@source_dir} && git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --date=short --format='%ad {}' {}", verbose: false
63
69
  end
64
70
 
65
71
  desc "Save the commit hash to VERSION in the build directory"
@@ -70,7 +76,7 @@ namespace :git do
70
76
  end
71
77
  hash = `cd #{@source_dir} && git rev-parse HEAD`.chomp
72
78
  local_changes = `git diff --shortstat`.chomp.length
73
- File.write("#{@build_dir}/VERSION", local_changes ? "#{hash}*\n" : "#{hash}*")
79
+ File.write(@build_dir + '/VERSION', local_changes ? "#{hash}*\n" : "#{hash}*")
74
80
  puts 'Saved git version to VERSION file'.green
75
81
  end
76
82
  end
@@ -79,6 +85,7 @@ end
79
85
  namespace :jekyll do
80
86
  desc "Build Jekyll site"
81
87
  task :build do
88
+ create_build_dir
82
89
  puts 'Building Jekyll'.blue
83
90
  sh "jekyll build --incremental --source '#{@source_dir}' --destination '#{@build_dir}'"
84
91
  puts 'Built'.green
@@ -86,6 +93,7 @@ namespace :jekyll do
86
93
 
87
94
  desc "Run a Jekyll test server"
88
95
  task :test do
96
+ create_build_dir
89
97
  puts 'Running test server'.blue
90
98
  sh "jekyll serve --source '#{@source_dir}' --destination '#{@build_dir}'"
91
99
  end
@@ -93,51 +101,51 @@ end
93
101
 
94
102
  # Interact with a production environment
95
103
  namespace :rsync do
96
- desc "Copy the source directory to the build directory"
104
+ desc "Copy the source directory to the build directory, excluding some files"
97
105
  task :copy_build do
98
106
  puts 'Copying source directory to build directory'.blue
99
- rsync_opts = '--archive --delete --exclude .git'
100
- from = "#{@source_dir}/"
101
- to = "#{@build_dir}/"
102
- sh "rsync #{rsync_opts} '#{from}' '#{to}'"
107
+ rsync_opts = %w[--archive --delete]
108
+ from = @source_dir + '/'
109
+ to = @build_dir + '/'
110
+ @build_excludes.each do |exclude|
111
+ rsync_opts << '--exclude'
112
+ rsync_opts << exclude
113
+ end
114
+ sh 'rsync', *rsync_opts, from, to
103
115
  puts 'Copied'.green
104
116
  end
105
117
 
106
- desc "Bring deployed web server files local"
107
- task :pull do
108
- raise '@production_dir is not defined' unless defined? @production_dir
109
- raise '@build_dir is not defined' unless defined? @build_dir
110
- puts 'Pulling website'.blue
111
- rsync_opts = '-vr --delete --exclude .git --exclude cache'
112
- remote = "#{@production_dir}/"
113
- local = "#{@build_dir}/"
114
- sh "rsync #{rsync_opts} '#{remote}' '#{local}'"
118
+ desc "Bring remote files to build directory (use rsync-style paths)"
119
+ task :pull, [:remote] do |t, args|
120
+ args.with_defaults(:remote => @remote_dir)
121
+ puts 'Pulling website from remote'.blue
122
+ rsync_opts = %w[-vr --delete]
123
+ from = args.remote + '/'
124
+ to = @build_dir + '/'
125
+ sh 'rsync', *rsync_opts, from, to
115
126
  puts 'Pulled'.green
116
127
  end
117
128
 
118
- desc "Push local files to production web server"
119
- task :push do
120
- raise '@production_dir is not defined' unless defined? @production_dir
121
- raise '@build_dir is not defined' unless defined? @build_dir
122
- puts 'Pushing website'.blue
123
- rsync_opts = '-r -c -v --ignore-times --chmod=ugo=rwX --delete --exclude .git --exclude cache'
124
- remote = "#{@production_dir}/"
125
- local = "#{@build_dir}/"
126
- sh "rsync #{rsync_opts} '#{local}' '#{remote}'"
129
+ desc "Send build directory to remote server (use rsync-style paths)"
130
+ task :push, [:remote] do |t, args|
131
+ args.with_defaults(:remote => @remote_dir)
132
+ puts 'Pushing website to remote'.blue
133
+ rsync_opts = %w[-r -c -v --ignore-times --chmod=ugo=rwX --delete]
134
+ from = @build_dir + '/'
135
+ to = args.remote + '/'
136
+ sh 'rsync', *rsync_opts, from, to
127
137
  puts 'Pushed'.green
128
138
  end
129
139
 
130
- desc "Backup production"
140
+ desc "Backup items from remote server"
131
141
  task :backup do
132
- raise '@production_backup_dir is not defined' unless defined? @production_backup_dir
133
- raise '@production_backup_targets is not defined' unless defined? @production_backup_targets
134
- puts "Backing up production".blue
135
- rsync_opts = '-vaL --delete --exclude .git'
136
- @production_backup_targets.each do |local_dir, remote_dir|
137
- remote = "#{remote_dir}"
138
- local = "#{@production_backup_dir}/#{local_dir}/"
139
- sh 'mkdir', '-p', local
140
- sh "rsync #{rsync_opts} '#{remote}' '#{local}'"
142
+ puts "Backing up remote server".blue
143
+ rsync_opts = %w[-vaL --delete --exclude .git]
144
+ @backup_targets.each do |local_dir, remote_dir|
145
+ from = remote_dir
146
+ to = @backup_dir + '/' + local_dir
147
+ FileUtils.mkdir_p to
148
+ sh 'rsync', *rsync_opts, from, to
141
149
  end
142
150
  puts "Backup complete".green
143
151
  end
@@ -148,7 +156,7 @@ namespace :seo do
148
156
  desc "Find 404s"
149
157
  task :find_404 do
150
158
  puts "Finding 404 errors".blue
151
- sh 'zgrep', '-r', ' 404 ', "#{@production_backup_dir}/logs"
159
+ sh 'zgrep', '-r', ' 404 ', "#{@backup_dir}/logs"
152
160
  # sh "zgrep -r ' 404 ' '#{@production_backup_dir}/logs'"
153
161
  puts "Found".green
154
162
  end
@@ -156,24 +164,30 @@ namespace :seo do
156
164
  desc "Find 301s"
157
165
  task :find_301 do
158
166
  puts "Finding 301 errors".blue
159
- sh "zgrep -r ' 301 ' '#{@production_backup_dir}/logs'"
167
+ sh "zgrep -r ' 301 ' '#{@backup_dir}/logs'"
160
168
  puts "Found".green
161
169
  end
162
170
  end
163
171
 
164
172
  # testing stuff for built html folder
165
173
  namespace :html do
166
- desc "Checks HTML with htmlproofer, excludes offsite broken link checking"
167
- task :check_onsite do
174
+ desc "Checks everything with htmlproofer that is reasonable to check"
175
+ task :check do
168
176
  puts "⚡️ Checking HTML".blue
169
- sh "bundle exec htmlproofer --disable-external --check-html --checks-to-ignore ScriptCheck,LinkCheck,HtmlCheck #{@build_dir} > /dev/null || true"
177
+ sh "bundle exec htmlproofer --check-sri --check-external-hash --check-html --check-img-http --check-opengraph --enforce-https --timeframe 6w #{@build_dir}" do
178
+ puts 'Errors found'
179
+ exit(1)
180
+ end
170
181
  puts "☀️ Checked HTML".green
171
182
  end
172
183
 
173
- desc "Checks links with htmlproofer"
174
- task :check_links do
175
- puts "⚡️ Checking links".blue
176
- sh "bundle exec htmlproofer --checks-to-ignore ScriptCheck,ImageCheck #{@build_dir} || true"
184
+ desc "Checks HTML with htmlproofer, skip external links"
185
+ task :check_onsite do
186
+ puts "⚡️ Checking HTML, skipping external links".blue
187
+ sh "bundle exec htmlproofer --disable-external --check-sri --check-html --check-opengraph --enforce-https #{@build_dir}" do
188
+ puts 'Errors found'
189
+ exit(1)
190
+ end
177
191
  puts "☀️ Checked HTML".green
178
192
  end
179
193
 
@@ -188,16 +202,7 @@ desc "Delete all built code"
188
202
  task :clean do
189
203
  puts "Deleting all built code".red
190
204
  FileUtils.rm_rf(@build_dir)
191
- FileUtils.rm_rf(@production_backup_dir)
192
- puts "Deleting complete".green
193
- end
194
-
195
- desc "Delete everything that can be regenerated"
196
- task :distclean do
197
- puts "Deleting all built code".red
198
- FileUtils.rm_rf(@build_dir)
199
- puts "Deleting all productions backups".red
200
- FileUtils.rm_rf(@production_backup_dir)
205
+ FileUtils.rm_rf(@backup_dir)
201
206
  puts "Deleting complete".green
202
207
  end
203
208
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightning_sites
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Entriken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize