hyde-ftp 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/hyde +124 -2
- data/hyde-ftp.gemspec +2 -3
- data/lib/hyde.rb +46 -1
- metadata +4 -5
- data/lib/hyde/ftp-transfer.rb +0 -43
data/bin/hyde
CHANGED
@@ -1,7 +1,129 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
|
3
5
|
require 'rubygems'
|
4
6
|
require 'net/ftp'
|
5
7
|
require 'yaml'
|
6
|
-
require 'hyde/ftp-transfer.rb'
|
7
|
-
|
8
|
+
require 'lib/hyde/ftp-transfer.rb'
|
9
|
+
|
10
|
+
def mirror(path, ftp, initial_path = nil)
|
11
|
+
initial_path ||= path
|
12
|
+
Dir.entries(path).each do |file|
|
13
|
+
next if ['.', '..'].include? file
|
14
|
+
|
15
|
+
file_path = path + '/' + file
|
16
|
+
short_file_path = file_path[initial_path.length, file_path.length]
|
17
|
+
if File.directory?(file_path)
|
18
|
+
ftp.mkdir(file) unless ftp.nlst.index(file)
|
19
|
+
ftp.chdir(file)
|
20
|
+
mirror(file_path, ftp, initial_path)
|
21
|
+
ftp.chdir('..')
|
22
|
+
else
|
23
|
+
puts "Deploying: " + short_file_path
|
24
|
+
puts " To: " + ftp.pwd + '/' + file
|
25
|
+
ftp.putbinaryfile(path + '/' + file, file)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def ftp_directory?(ftp, file_name)
|
31
|
+
ftp.chdir(file_name)
|
32
|
+
ftp.chdir('..')
|
33
|
+
true
|
34
|
+
rescue
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
def clean_ftp(ftp)
|
39
|
+
ftp.nlst.each do |file|
|
40
|
+
next if ['.', '..', 'bup', 'backup'].include? file
|
41
|
+
if ftp_directory? ftp, file
|
42
|
+
ftp.chdir file
|
43
|
+
clean_ftp(ftp)
|
44
|
+
ftp.chdir '..'
|
45
|
+
puts "Deleting directory: " + ftp.pwd + "/" + file
|
46
|
+
ftp.rmdir(file)
|
47
|
+
else
|
48
|
+
puts "Deleting: " + ftp.pwd + "/" + file
|
49
|
+
ftp.delete file
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Jekyll
|
55
|
+
$jekyll = Jekyll.new()
|
56
|
+
|
57
|
+
def initialize()
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def exists()
|
62
|
+
@jekyll_version = %x( jekyll -version )
|
63
|
+
|
64
|
+
if @jekyll_version[1] = "j"
|
65
|
+
nil
|
66
|
+
else
|
67
|
+
%x( gem install jekyll )
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def new_site(name)
|
72
|
+
exists()
|
73
|
+
%x( jekyll new #{name} )
|
74
|
+
puts "Site created."
|
75
|
+
end
|
76
|
+
|
77
|
+
def deploy()
|
78
|
+
|
79
|
+
# Declare Instance Variables
|
80
|
+
config = YAML.load(File.read(ARGV[1]))
|
81
|
+
|
82
|
+
@ftp_server = config['server']
|
83
|
+
@username = config['username']
|
84
|
+
@password = config['password']
|
85
|
+
@remote_dir = config['remote_dir']
|
86
|
+
@local_dir = config['local_dir']
|
87
|
+
|
88
|
+
# Initialize FTP
|
89
|
+
ftp = Net::FTP.new(@ftp_server);
|
90
|
+
ftp.login(@username, @password)
|
91
|
+
ftp.chdir(@remote_dir)
|
92
|
+
|
93
|
+
clean_ftp(ftp)
|
94
|
+
|
95
|
+
mirror @local_dir, ftp
|
96
|
+
|
97
|
+
ftp.quit
|
98
|
+
end
|
99
|
+
|
100
|
+
def help()
|
101
|
+
command2 = ARGV[1]
|
102
|
+
case command2
|
103
|
+
when "deploy"
|
104
|
+
puts "Build Jekyll site and deploy via FTP."
|
105
|
+
puts "Usage: hyde deploy _config.yml"
|
106
|
+
when "new_site"
|
107
|
+
puts "Create a new Jekyll site."
|
108
|
+
puts "Usage: hyde new site_name"
|
109
|
+
else
|
110
|
+
puts "Commands:"
|
111
|
+
puts " deploy\n new_site"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
command1 = ARGV[0]
|
117
|
+
case command1
|
118
|
+
when "deploy"
|
119
|
+
$jekyll.deploy
|
120
|
+
when "new_site"
|
121
|
+
$jekyll.new_site
|
122
|
+
when "help"
|
123
|
+
$jekyll.help
|
124
|
+
when "list"
|
125
|
+
%x( hyde help )
|
126
|
+
else
|
127
|
+
puts "You didn't give me a command.\nRun 'hyde help' to see a command list."
|
128
|
+
end
|
129
|
+
|
data/hyde-ftp.gemspec
CHANGED
@@ -4,9 +4,9 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.rubygems_version = '1.3.5'
|
5
5
|
|
6
6
|
s.name = 'hyde-ftp'
|
7
|
-
s.version = '0.1.
|
7
|
+
s.version = '0.1.2'
|
8
8
|
s.license = 'MIT'
|
9
|
-
s.date = '2013-
|
9
|
+
s.date = '2013-06-11'
|
10
10
|
|
11
11
|
s.summary = "Jekyll deployment using FTP."
|
12
12
|
s.description = "Hyde is an addon to the amazing Jekyll that makes deploying with FTP easier."
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.files = %w[
|
26
26
|
bin/hyde
|
27
27
|
lib/hyde.rb
|
28
|
-
lib/hyde/ftp-transfer.rb
|
29
28
|
CHANGELOG
|
30
29
|
LICENSE
|
31
30
|
README.md
|
data/lib/hyde.rb
CHANGED
@@ -5,6 +5,50 @@ require 'net/ftp'
|
|
5
5
|
require 'yaml'
|
6
6
|
require 'lib/hyde/ftp-transfer.rb'
|
7
7
|
|
8
|
+
def mirror(path, ftp, initial_path = nil)
|
9
|
+
initial_path ||= path
|
10
|
+
Dir.entries(path).each do |file|
|
11
|
+
next if ['.', '..'].include? file
|
12
|
+
|
13
|
+
file_path = path + '/' + file
|
14
|
+
short_file_path = file_path[initial_path.length, file_path.length]
|
15
|
+
if File.directory?(file_path)
|
16
|
+
ftp.mkdir(file) unless ftp.nlst.index(file)
|
17
|
+
ftp.chdir(file)
|
18
|
+
mirror(file_path, ftp, initial_path)
|
19
|
+
ftp.chdir('..')
|
20
|
+
else
|
21
|
+
puts "Deploying: " + short_file_path
|
22
|
+
puts " To: " + ftp.pwd + '/' + file
|
23
|
+
ftp.putbinaryfile(path + '/' + file, file)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def ftp_directory?(ftp, file_name)
|
29
|
+
ftp.chdir(file_name)
|
30
|
+
ftp.chdir('..')
|
31
|
+
true
|
32
|
+
rescue
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def clean_ftp(ftp)
|
37
|
+
ftp.nlst.each do |file|
|
38
|
+
next if ['.', '..', 'bup', 'backup'].include? file
|
39
|
+
if ftp_directory? ftp, file
|
40
|
+
ftp.chdir file
|
41
|
+
clean_ftp(ftp)
|
42
|
+
ftp.chdir '..'
|
43
|
+
puts "Deleting directory: " + ftp.pwd + "/" + file
|
44
|
+
ftp.rmdir(file)
|
45
|
+
else
|
46
|
+
puts "Deleting: " + ftp.pwd + "/" + file
|
47
|
+
ftp.delete file
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
8
52
|
class Jekyll
|
9
53
|
$jekyll = Jekyll.new()
|
10
54
|
|
@@ -79,4 +123,5 @@ when "list"
|
|
79
123
|
%x( hyde help )
|
80
124
|
else
|
81
125
|
puts "You didn't give me a command.\nRun 'hyde help' to see a command list."
|
82
|
-
end
|
126
|
+
end
|
127
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyde-ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jesse Herrick
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-06-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: jekyll
|
@@ -43,7 +43,6 @@ extra_rdoc_files: []
|
|
43
43
|
files:
|
44
44
|
- bin/hyde
|
45
45
|
- lib/hyde.rb
|
46
|
-
- lib/hyde/ftp-transfer.rb
|
47
46
|
- CHANGELOG
|
48
47
|
- LICENSE
|
49
48
|
- README.md
|
data/lib/hyde/ftp-transfer.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
def mirror(path, ftp, initial_path = nil)
|
2
|
-
initial_path ||= path
|
3
|
-
Dir.entries(path).each do |file|
|
4
|
-
next if ['.', '..'].include? file
|
5
|
-
|
6
|
-
file_path = path + '/' + file
|
7
|
-
short_file_path = file_path[initial_path.length, file_path.length]
|
8
|
-
if File.directory?(file_path)
|
9
|
-
ftp.mkdir(file) unless ftp.nlst.index(file)
|
10
|
-
ftp.chdir(file)
|
11
|
-
mirror(file_path, ftp, initial_path)
|
12
|
-
ftp.chdir('..')
|
13
|
-
else
|
14
|
-
puts "Deploying: " + short_file_path
|
15
|
-
puts " To: " + ftp.pwd + '/' + file
|
16
|
-
ftp.putbinaryfile(path + '/' + file, file)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def ftp_directory?(ftp, file_name)
|
22
|
-
ftp.chdir(file_name)
|
23
|
-
ftp.chdir('..')
|
24
|
-
true
|
25
|
-
rescue
|
26
|
-
false
|
27
|
-
end
|
28
|
-
|
29
|
-
def clean_ftp(ftp)
|
30
|
-
ftp.nlst.each do |file|
|
31
|
-
next if ['.', '..', 'bup', 'backup'].include? file
|
32
|
-
if ftp_directory? ftp, file
|
33
|
-
ftp.chdir file
|
34
|
-
clean_ftp(ftp)
|
35
|
-
ftp.chdir '..'
|
36
|
-
puts "Deleting directory: " + ftp.pwd + "/" + file
|
37
|
-
ftp.rmdir(file)
|
38
|
-
else
|
39
|
-
puts "Deleting: " + ftp.pwd + "/" + file
|
40
|
-
ftp.delete file
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|