middleman-deploy 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,15 +4,15 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem "rake", "~> 0.9.2"
8
- gem "rdoc", "~> 3.9"
9
- gem "yard", "~> 0.8.0"
7
+ gem "rake"
8
+ gem "rdoc"
9
+ gem "yard"
10
10
  end
11
11
 
12
12
  group :test do
13
- gem "cucumber", "~> 1.2.0"
13
+ gem "cucumber"
14
14
  gem "fivemat"
15
- gem "aruba", "~> 0.4.11"
16
- gem "rspec", "~> 2.7"
15
+ gem "aruba"
16
+ gem "rspec"
17
17
  gem "simplecov"
18
18
  end
data/README.md CHANGED
@@ -1,35 +1,30 @@
1
- Middleman Deploy - Deploy a [middleman](http://middlemanapp.com/) built site over rsync, git (e.g. gh-pages on github) or via ftp.
1
+ Middleman Deploy - Deploy a [middleman](http://middlemanapp.com/)
2
+ built site over rsync, ftp, sftp, or git (e.g. gh-pages on github).
2
3
 
3
4
  [![Build Status](https://secure.travis-ci.org/tvaughan/middleman-deploy.png)](http://travis-ci.org/tvaughan/middleman-deploy)
4
5
 
5
- ===
6
+ # QUICK START
6
7
 
7
- ## QUICK START
8
-
9
- ### Step 1
10
-
11
- gem install middleman-deploy
12
-
13
- ### Step 2
8
+ ## Step 1
14
9
 
15
10
  middleman init example-site
16
11
  cd example-site
17
12
 
18
- ### Step 3
13
+ ## Step 2
19
14
 
20
15
  Edit `Gemfile`, and add:
21
16
 
22
- gem "middleman-deploy", "~> 0.0.12"
17
+ gem "middleman-deploy", ">= 0.1.0"
23
18
 
24
19
  Then run:
25
20
 
26
21
  bundle install
27
22
 
28
- ### Step 4a - Rsync setup
23
+ ## Step 3a - Rsync setup
29
24
 
30
25
  First be sure that `rsync` is installed.
31
26
 
32
- #### These settings are required.
27
+ **These settings are required.**
33
28
 
34
29
  Edit `config.rb`, and add:
35
30
 
@@ -42,7 +37,7 @@ Edit `config.rb`, and add:
42
37
 
43
38
  Adjust these values accordingly.
44
39
 
45
- #### These settings are optional.
40
+ **These settings are optional.**
46
41
 
47
42
  To use a particular SSH port, add:
48
43
 
@@ -56,7 +51,11 @@ To remove orphaned files or directories on the remote host, add:
56
51
 
57
52
  Default is `false`.
58
53
 
59
- ### Step 4b - Git setup
54
+ ## Step 3b - Git setup
55
+
56
+ First be sure that `git` is installed.
57
+
58
+ **These settings are required.**
60
59
 
61
60
  Edit `config.rb`, and add:
62
61
 
@@ -67,7 +66,7 @@ Edit `config.rb`, and add:
67
66
  By default this will deploy to the `gh-pages` branch on the `origin`
68
67
  remote. The `build` directory will become a git repo.
69
68
 
70
- #### These settings are optional.
69
+ **These settings are optional.**
71
70
 
72
71
  To use a particular remote, add:
73
72
 
@@ -86,9 +85,9 @@ To use a particular branch, add:
86
85
  Default is `gh-pages`. This branch will be created on the remote if it
87
86
  doesn't already exist.
88
87
 
89
- ### Step 4c - FTP setup
88
+ ## Step 3c - FTP setup
90
89
 
91
- #### These settings are required.
90
+ **These settings are required.**
92
91
 
93
92
  Edit `config.rb`, and add:
94
93
 
@@ -102,21 +101,49 @@ Edit `config.rb`, and add:
102
101
 
103
102
  Adjust these values accordingly.
104
103
 
105
- ### Step 5
104
+ ## Step 3d - SFTP setup
105
+
106
+ **These settings are required.**
107
+
108
+ Edit `config.rb`, and add:
109
+
110
+ activate :deploy do |deploy|
111
+ deploy.method = :sftp
112
+ deploy.host = "sftp.example.com"
113
+ deploy.user = "tvaughan"
114
+ deploy.password = "secret"
115
+ deploy.path = "/srv/www/site"
116
+ end
117
+
118
+ Adjust these values accordingly.
119
+
120
+ ## Step 4
106
121
 
107
122
  middleman build [--clean]
108
- middleman deploy [--clean]
123
+ middleman deploy [--build-before]
109
124
 
110
- To automatically run middleman-deploy after `middleman build`, add:
125
+ To run `middleman build` before `middleman deploy`, add:
111
126
 
112
- deploy.after_build = true
127
+ deploy.build_before = true
113
128
 
114
129
  Default is `false`.
115
130
 
116
- Please note that if the `--clean` or `--no-clean` option is passed to
117
- `middleman build` it will not be passed to `middleman deploy`. For now
118
- only the value of `deploy.clean` in `config.rb` will be used.
131
+ ## BREAKING CHANGES
132
+
133
+ * v0.1.0
134
+
135
+ * Removed the `--clean` command-line option. This option only applied
136
+ to the rsync deploy method. The idea going forward is that
137
+ command-line options must apply to all deploy methods. Options that
138
+ are specific to a deploy method will only be available in
139
+ `config.rb`.
140
+
141
+ * Removed `deploy` from the `after_build` hook. This caused a
142
+ `deploy` to be run each time `build` was called. This workflow never
143
+ made sense. `deploy` was added to the `after_build` hook simply
144
+ because it was available.
119
145
 
120
- ### NOTES
146
+ ## NOTES
121
147
 
122
- Inspired by the rsync task in [Octopress](https://github.com/imathis/octopress).
148
+ Inspired by the rsync task in
149
+ [Octopress](https://github.com/imathis/octopress).
@@ -22,12 +22,23 @@ module Middleman
22
22
  true
23
23
  end
24
24
 
25
- desc "deploy", "Deploy build directory to a remote host via rsync or git"
26
- method_option "clean",
25
+ desc "deploy [options]", Middleman::Deploy::TAGLINE
26
+ method_option "build_before",
27
27
  :type => :boolean,
28
- :aliases => "-c",
29
- :desc => "Remove orphaned files or directories on the remote host"
28
+ :aliases => "-b",
29
+ :desc => "Run `middleman build` before the deploy step"
30
+
30
31
  def deploy
32
+ if options.has_key? "build_before"
33
+ build_before = options.build_before
34
+ else
35
+ build_before = self.deploy_options.build_before
36
+ end
37
+ if build_before
38
+ # http://forum.middlemanapp.com/t/problem-with-the-build-task-in-an-extension
39
+ builder = ::Middleman::Cli::Build.new(args=[], options={:instrument=>false})
40
+ builder.build
41
+ end
31
42
  send("deploy_#{self.deploy_options.method}")
32
43
  end
33
44
 
@@ -36,7 +47,7 @@ module Middleman
36
47
  def print_usage_and_die(message)
37
48
  raise Error, "ERROR: " + message + "\n" + <<EOF
38
49
 
39
- You should follow one of the three examples below to setup the deploy
50
+ You should follow one of the four examples below to setup the deploy
40
51
  extension in config.rb.
41
52
 
42
53
  # To deploy the build directory to a remote host via rsync:
@@ -70,6 +81,16 @@ activate :deploy do |deploy|
70
81
  deploy.password = "secret"
71
82
  deploy.path = "/srv/www/site"
72
83
  end
84
+
85
+ # To deploy the build directory to a remote host via sftp:
86
+ activate :deploy do |deploy|
87
+ deploy.method = :sftp
88
+ # host, user, passwword and path *must* be set
89
+ deploy.host = "sftp.example.com"
90
+ deploy.user = "tvaughan"
91
+ deploy.password = "secret"
92
+ deploy.path = "/srv/www/site"
93
+ end
73
94
  EOF
74
95
  end
75
96
 
@@ -90,15 +111,14 @@ EOF
90
111
  print_usage_and_die "The deploy extension requires you to set a method."
91
112
  end
92
113
 
93
- if (options.method == :rsync)
114
+ case options.method
115
+ when :rsync
94
116
  if (!options.host || !options.user || !options.path)
95
117
  print_usage_and_die "The rsync deploy method requires host, user, and path to be set."
96
118
  end
97
- end
98
-
99
- if (options.method == :ftp)
119
+ when :ftp, :sftp
100
120
  if (!options.host || !options.user || !options.password || !options.path)
101
- print_usage_and_die "The ftp deploy method requires host, user, password, and path to be set."
121
+ print_usage_and_die "The #{options.method} method requires host, user, password, and path to be set."
102
122
  end
103
123
  end
104
124
 
@@ -115,13 +135,7 @@ EOF
115
135
 
116
136
  command = "rsync -avze '" + "ssh -p #{port}" + "' #{self.inst.build_dir}/ #{user}@#{host}:#{path}"
117
137
 
118
- if options.has_key? "clean"
119
- clean = options.clean
120
- else
121
- clean = self.deploy_options.clean
122
- end
123
-
124
- if clean
138
+ if self.deploy_options.clean
125
139
  command += " --delete"
126
140
  end
127
141
 
@@ -158,7 +172,7 @@ EOF
158
172
  end
159
173
 
160
174
  #if there is a branch with that name, switch to it, otherwise create a new one and switch to it
161
- if `git branch`.split("\n").delete_if{ |r| r =~ Regexp.new(branch,true) }.count == 0
175
+ if `git branch`.split("\n").any? { |b| b =~ /#{branch}/i }
162
176
  `git checkout #{branch}`
163
177
  else
164
178
  `git checkout -b #{branch}`
@@ -220,6 +234,45 @@ EOF
220
234
  ftp.close
221
235
  end
222
236
 
237
+ def deploy_sftp
238
+ require 'net/sftp'
239
+ require 'ptools'
240
+
241
+ host = self.deploy_options.host
242
+ user = self.deploy_options.user
243
+ pass = self.deploy_options.password
244
+ path = self.deploy_options.path
245
+
246
+ puts "## Deploying via sftp to #{user}@#{host}:#{path}"
247
+
248
+ Net::SFTP.start(host, user, :password => pass) do |sftp|
249
+ sftp.mkdir(path)
250
+ Dir.chdir(self.inst.build_dir) do
251
+ files = Dir.glob('**/*', File::FNM_DOTMATCH)
252
+ files.reject { |a| a =~ Regexp.new('\.$') }.each do |f|
253
+ if File.directory?(f)
254
+ begin
255
+ sftp.mkdir("#{path}/#{f}")
256
+ puts "Created directory #{f}"
257
+ rescue
258
+ end
259
+ else
260
+ begin
261
+ sftp.upload(f, "#{path}/#{f}")
262
+ rescue Exception => e
263
+ reply = e.message
264
+ err_code = reply[0,3].to_i
265
+ if err_code == 550
266
+ sftp.upload(f, "#{path}/#{f}")
267
+ end
268
+ end
269
+ puts "Copied #{f}"
270
+ end
271
+ end
272
+ end
273
+ end
274
+ end
275
+
223
276
  end
224
277
 
225
278
  # Alias "d" to "deploy"
@@ -5,7 +5,7 @@ require "middleman-core"
5
5
  module Middleman
6
6
  module Deploy
7
7
 
8
- class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build); end
8
+ class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :build_before); end
9
9
 
10
10
  class << self
11
11
 
@@ -22,11 +22,7 @@ module Middleman
22
22
  options.remote ||= "origin"
23
23
  options.branch ||= "gh-pages"
24
24
 
25
- options.after_build ||= false
26
-
27
- app.after_build do |builder|
28
- ::Middleman::Cli::Deploy.new.deploy if options.after_build
29
- end
25
+ options.build_before ||= false
30
26
 
31
27
  @@options = options
32
28
 
@@ -1,6 +1,7 @@
1
1
  module Middleman
2
2
  module Deploy
3
3
  PACKAGE = "middleman-deploy"
4
- VERSION = "0.0.12"
4
+ VERSION = "0.1.0"
5
+ TAGLINE = "Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages on github)."
5
6
  end
6
7
  end
@@ -9,8 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Tom Vaughan"]
10
10
  s.email = ["thomas.david.vaughan@gmail.com"]
11
11
  s.homepage = "http://tvaughan.github.com/middleman-deploy/"
12
- s.summary = %q{Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).}
13
- s.description = %q{Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).}
12
+ s.summary = Middleman::Deploy::TAGLINE
13
+ s.description = Middleman::Deploy::TAGLINE
14
+ s.license = "MIT"
14
15
 
15
16
  s.files = `git ls-files`.split("\n")
16
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -22,4 +23,5 @@ Gem::Specification.new do |s|
22
23
 
23
24
  # Additional dependencies
24
25
  s.add_runtime_dependency("ptools")
26
+ s.add_runtime_dependency("net-sftp")
25
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -43,7 +43,23 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages
46
+ - !ruby/object:Gem::Dependency
47
+ name: net-sftp
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages
47
63
  on github).
48
64
  email:
49
65
  - thomas.david.vaughan@gmail.com
@@ -65,7 +81,8 @@ files:
65
81
  - lib/middleman_extension.rb
66
82
  - middleman-deploy.gemspec
67
83
  homepage: http://tvaughan.github.com/middleman-deploy/
68
- licenses: []
84
+ licenses:
85
+ - MIT
69
86
  post_install_message:
70
87
  rdoc_options: []
71
88
  require_paths:
@@ -87,6 +104,7 @@ rubyforge_project:
87
104
  rubygems_version: 1.8.23
88
105
  signing_key:
89
106
  specification_version: 3
90
- summary: Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).
107
+ summary: Deploy a middleman built site over rsync, ftp, sftp, or git (e.g. gh-pages
108
+ on github).
91
109
  test_files: []
92
110
  has_rdoc: