squarespace-sync 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/squarespace/sync/cli.rb +18 -8
- data/lib/squarespace/sync/connection.rb +37 -28
- data/lib/squarespace/sync/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 249d5912232d3b6c400770ea2eadfd1025c5b504
|
4
|
+
data.tar.gz: a97829f5a14af20723c33f8ee52c6d6a7dc4cc5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1005d5a7542cc92cceea81f3fa1b11adedfdb59f1411190cd96306c1a698192ab5e80507998ec5887b4ada97a6258fdeac0c40bb63fa137d6a30564c5d0db3a
|
7
|
+
data.tar.gz: 45b87d2cb0ed9dceb2cc95b43b813a0f8aa5380eb6f5e98f27cd03c48e5f60290387f38dd118735d7637c21bbd56ace956f27b93c49fa5be217505d4a30b2d34
|
data/README.md
CHANGED
@@ -26,16 +26,18 @@ $ squarespace setup
|
|
26
26
|
|
27
27
|
Update `squarespace.yaml` with your account settings, and then you can run either of these commands:
|
28
28
|
|
29
|
-
Pull files from Squarespace. Warns if there are conflicts
|
29
|
+
Pull all files or a single file from Squarespace. Warns if there are conflicts
|
30
30
|
|
31
31
|
```
|
32
32
|
$ squarespace pull
|
33
|
+
$ squarespace pull template.conf
|
33
34
|
```
|
34
35
|
|
35
|
-
Push files to Squarespace, overwriting existing
|
36
|
+
Push all files or a single file to Squarespace, overwriting existing
|
36
37
|
|
37
38
|
```
|
38
39
|
$ squarespace push
|
40
|
+
$ squarespace push template.conf
|
39
41
|
```
|
40
42
|
|
41
43
|
|
data/lib/squarespace/sync/cli.rb
CHANGED
@@ -23,17 +23,27 @@ module Squarespace
|
|
23
23
|
template( template_file, output_file, options )
|
24
24
|
end
|
25
25
|
|
26
|
-
desc "push", "Push files to Squarespace"
|
27
|
-
def push
|
28
|
-
Connection.new do |sftp, options,
|
29
|
-
|
26
|
+
desc "push FILE", "Push files to Squarespace"
|
27
|
+
def push(file=nil)
|
28
|
+
Connection.new do |sftp, options, instance|
|
29
|
+
if file
|
30
|
+
local_file = File.join(Squarespace::Sync.local_path, file)
|
31
|
+
instance.push_file( sftp, file, File.join(options[:directory], local_file) )
|
32
|
+
else
|
33
|
+
instance.push_tree( sftp, options[:directory] )
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
|
-
desc "pull", "Pull files from Squarespace"
|
34
|
-
def pull
|
35
|
-
Connection.new do |sftp, options,
|
36
|
-
|
38
|
+
desc "pull FILE", "Pull files from Squarespace"
|
39
|
+
def pull(file=nil)
|
40
|
+
Connection.new do |sftp, options, instance|
|
41
|
+
if file
|
42
|
+
local_file = File.join(Squarespace::Sync.local_path, file)
|
43
|
+
instance.pull_file( sftp, File.join(options[:directory], file), local_file )
|
44
|
+
else
|
45
|
+
instance.pull_tree( sftp, options[:directory] )
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
39
49
|
|
@@ -16,47 +16,56 @@ module Squarespace
|
|
16
16
|
|
17
17
|
def pull_tree( sftp, directory )
|
18
18
|
sftp.dir[directory, "**/*"].each do |entry|
|
19
|
-
|
20
|
-
|
19
|
+
remote = File.join(directory, entry.name)
|
20
|
+
local = File.join(Squarespace::Sync.local_path, entry.name)
|
21
21
|
|
22
|
-
if sftp.file.directory?(
|
23
|
-
FileUtils.mkdir_p(
|
22
|
+
if sftp.file.directory?( remote )
|
23
|
+
FileUtils.mkdir_p( local )
|
24
24
|
else
|
25
|
-
|
26
|
-
overwrite = ask("#{entry.name} already exists. Overwrite it?", :yellow, limited_to: %w{y n})
|
27
|
-
if overwrite == "y"
|
28
|
-
sftp.download!(remote_file, local_file)
|
29
|
-
end
|
30
|
-
else
|
31
|
-
say("Downloading #{entry.name}", :green)
|
32
|
-
sftp.download!(remote_file, local_file)
|
33
|
-
end
|
25
|
+
pull_file( sftp, remote, local )
|
34
26
|
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
|
30
|
+
def pull_file( sftp, remote, local )
|
31
|
+
if File.exists?( local )
|
32
|
+
overwrite = ask("#{local} already exists. Overwrite it?", :yellow, limited_to: %w{y n})
|
33
|
+
if overwrite == "y"
|
34
|
+
say("Downloading #{remote}", :green)
|
35
|
+
sftp.download!(remote, local)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
say("Downloading #{remote}", :green)
|
39
|
+
sftp.download!(remote, local)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
38
43
|
def push_tree( sftp, directory )
|
39
|
-
Dir[File.join(Squarespace::Sync.local_path, "**/*")].each do |
|
40
|
-
|
41
|
-
|
42
|
-
next if Squarespace::Sync.options[:ignore].include?(
|
44
|
+
Dir[File.join(Squarespace::Sync.local_path, "**/*")].each do |local|
|
45
|
+
remote = local.gsub(Squarespace::Sync.local_path + "/", "")
|
46
|
+
absolute_remote = File.join(directory, remote)
|
47
|
+
next if Squarespace::Sync.options[:ignore].include?( remote.split("/").first )
|
43
48
|
|
44
|
-
if File.directory?(
|
45
|
-
sftp.mkdir!(
|
49
|
+
if File.directory?( local )
|
50
|
+
sftp.mkdir!( absolute_remote ) unless sftp.file.directory?( absolute_remote )
|
46
51
|
else
|
47
|
-
|
48
|
-
|
49
|
-
begin
|
50
|
-
sftp.upload!( file, real_path )
|
51
|
-
rescue Net::SFTP::StatusException => code
|
52
|
-
sftp.remove!( real_path ) do
|
53
|
-
sftp.upload!( file, real_path )
|
54
|
-
end if code == 11
|
55
|
-
end
|
52
|
+
push_file( sftp, local, absolute_remote)
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
57
|
+
def push_file( sftp, local, remote )
|
58
|
+
say("Uploading #{remote}", :green)
|
59
|
+
|
60
|
+
begin
|
61
|
+
sftp.upload!( local, remote )
|
62
|
+
rescue Net::SFTP::StatusException => code
|
63
|
+
sftp.remove!( remote ) do
|
64
|
+
sftp.upload!( local, remote )
|
65
|
+
end if code == 11
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
60
69
|
end
|
61
70
|
|
62
71
|
end
|