squarespace-sync 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 838bce92e3947380a1d4d6dd6bce462d44045411
4
+ data.tar.gz: cb6553212cf083cc00a2f429f3a0a3bf841226bc
5
+ SHA512:
6
+ metadata.gz: 1a3a966314f615054ba75ddb49da18afb0cec9102de10896ce2f05bceb18659bd4c969417b186a448666ecf36c6e0c476621ea1e8c274a17105efd9cdb2f29e8
7
+ data.tar.gz: 48f38a1f0e91108fb6244d55871294de834ed64fb6e1eaee3f72894a71c3fd4a42abf19ba358d8d4b0a0dc617f934d9f7c57c6963abc3fcd92b0f43c3383d375
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1 @@
1
+ squarespace-sync
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 jordanandree
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Squarespace::Sync
2
+
3
+ Sync files to and from a [Squarespace Developer](http://developers.squarespace.com) site over SFTP.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'squarespace-sync'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install squarespace-sync
18
+
19
+ ## Usage
20
+
21
+ Setup the configuration YAML file for your Squarespace Developer account SFTP settings:
22
+
23
+ ```
24
+ $ squarespace setup
25
+ ```
26
+
27
+ Update `squarespace.yaml` with your account settings, and then you can run either of these commands:
28
+
29
+ Pull files from Squarespace. Warns if there are conflicts
30
+
31
+ ```
32
+ $ squarespace pull
33
+ ```
34
+
35
+ Push files to Squarespace, overwriting existing
36
+
37
+ ```
38
+ $ squarespace push
39
+ ```
40
+
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'squarespace/sync'
5
+ Squarespace::Sync::Cli.start
@@ -0,0 +1,30 @@
1
+ require "thor"
2
+ require "thor/group"
3
+ require "thor/actions"
4
+ require "yaml"
5
+ require "fileutils"
6
+ require "squarespace/sync/version"
7
+ require "squarespace/sync/connection"
8
+ require "squarespace/sync/cli"
9
+
10
+ module Squarespace
11
+ module Sync
12
+ def self.local_path
13
+ Dir.pwd
14
+ end
15
+
16
+ def self.config
17
+ File.join(local_path, "squarespace.yaml")
18
+ end
19
+
20
+ def self.options
21
+ if File.exists? config
22
+ options = YAML.load_file( config )
23
+ options["ignore"] << "squarespace.yaml"
24
+ Thor::CoreExt::HashWithIndifferentAccess.new( options )
25
+ else
26
+ abort "No config exists. Run `squarespace setup` to create it."
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ module Squarespace
2
+ module Sync
3
+ class Cli < Thor
4
+ include Thor::Actions
5
+
6
+ desc "version", "Show the version"
7
+ def version
8
+ say Squarespace::Sync::VERSION
9
+ end
10
+
11
+ desc "setup", "Sets up squarespace.yaml for configuring your account"
12
+ def setup
13
+ output_file = File.join(Squarespace::Sync.local_path, "squarespace.yaml")
14
+ template_file = "squarespace.tt"
15
+ options = {
16
+ host: "dev.squarespace.com",
17
+ username: "you@example.com",
18
+ password: "\"\"",
19
+ directory: "your-site",
20
+ port: 2030,
21
+ ignore: %w{.gitignore Gemfile Gemfile.lock}
22
+ }
23
+ template( template_file, output_file, options )
24
+ end
25
+
26
+ desc "push", "Push files to Squarespace"
27
+ def push
28
+ Connection.new do |sftp, options, connection|
29
+ connection.push_tree( sftp, options[:directory] )
30
+ end
31
+ end
32
+
33
+ desc "pull", "Pull files from Squarespace"
34
+ def pull
35
+ Connection.new do |sftp, options, connection|
36
+ connection.pull_tree( sftp, options[:directory] )
37
+ end
38
+ end
39
+
40
+ def self.source_root
41
+ File.dirname(__FILE__)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,64 @@
1
+ require "net/sftp"
2
+
3
+ module Squarespace
4
+ module Sync
5
+ class Connection < Thor
6
+
7
+ def initialize(&block)
8
+ options = Squarespace::Sync.options
9
+
10
+ Net::SFTP.start(options[:host], options[:username], password: options[:password], port: options[:port]) do |sftp|
11
+ block.call( sftp, options, self )
12
+ end
13
+ end
14
+
15
+ no_commands do
16
+
17
+ def pull_tree( sftp, directory )
18
+ sftp.dir[directory, "**/*"].each do |entry|
19
+ remote_file = File.join(directory, entry.name)
20
+ local_file = File.join(Squarespace::Sync.local_path, entry.name)
21
+
22
+ if sftp.file.directory?( remote_file )
23
+ FileUtils.mkdir_p( local_file )
24
+ else
25
+ if File.exists?( local_file )
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
34
+ end
35
+ end
36
+ end
37
+
38
+ def push_tree( sftp, directory )
39
+ Dir[File.join(Squarespace::Sync.local_path, "**/*")].each do |file|
40
+ remote_file = file.gsub(Squarespace::Sync.local_path + "/", "")
41
+ real_path = File.join(directory, remote_file)
42
+ next if Squarespace::Sync.options[:ignore].include?( remote_file.split("/").first )
43
+
44
+ if File.directory?( file )
45
+ sftp.mkdir!( real_path ) unless sftp.file.directory?( real_path )
46
+ else
47
+ say("Uploading #{remote_file}", :green)
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
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ host: <%= config[:host] %>
2
+ port: <%= config[:port] %>
3
+ username: <%= config[:username] %>
4
+ password: <%= config[:password] %>
5
+ directory: <%= config[:directory] %>
6
+ ignore:<% config[:ignore].each do |i| %>
7
+ <%= " - #{i}" %><% end %>
@@ -0,0 +1,5 @@
1
+ module Squarespace
2
+ module Sync
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Squarespace::Sync::Cli do
4
+
5
+ describe "#version" do
6
+ it "should return the version number" do
7
+ expect( shell("version") ).to eq "#{Squarespace::Sync::VERSION}\n"
8
+ end
9
+ end
10
+
11
+ describe "#setup" do
12
+ it "shoud create the file" do
13
+ expect( shell("setup", clean: false) ).to match %r{[create squarespace\.yaml]}
14
+ expect( File.exists?("tmp/squarespace.yaml") ).to eq true
15
+ end
16
+
17
+ it "should have default contents" do
18
+ contents = YAML.load_file("tmp/squarespace.yaml")
19
+ expect( contents.size ).to eq 6
20
+ end
21
+ end
22
+
23
+ describe "#push" do
24
+ it "is implemented but waiting" do
25
+ pending "needs a mock sftp connection"
26
+ end
27
+ end
28
+
29
+ describe "#pull" do
30
+ it "is implemented but waiting" do
31
+ pending "needs a mock sftp connection"
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,33 @@
1
+ require "rspec"
2
+ require File.expand_path("lib/squarespace/sync.rb", File.dirname(File.dirname(__FILE__)))
3
+
4
+ $:.unshift File.expand_path("bin", File.dirname(File.dirname(__FILE__)))
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+
9
+ # reject should matchers, keep our specs consistent
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+
14
+ module Helpers
15
+ def default_options
16
+ {
17
+ clean: true,
18
+ args: []
19
+ }
20
+ end
21
+
22
+ def shell(command, options={})
23
+ options = default_options.merge(options)
24
+ `cd #{File.join(Dir.pwd, "tmp")} && ../bin/squarespace #{command} #{options[:args].join}`
25
+ ensure
26
+ Dir[File.join(Dir.pwd, "tmp", "*")].each do |file|
27
+ FileUtils.rm_f(file)
28
+ end if options[:clean]
29
+ end
30
+ end
31
+
32
+ config.include Helpers
33
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'squarespace/sync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "squarespace-sync"
8
+ spec.version = Squarespace::Sync::VERSION
9
+ spec.authors = ["jordanandree"]
10
+ spec.email = ["jordanandree@gmail.com"]
11
+ spec.description = %q{Sync files to and from a Squarespace Developer site over SFTP}
12
+ spec.summary = %q{Sync files to and from a Squarespace Developer site}
13
+ spec.homepage = "http://github.com/jordanandree/squarespace-sync"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor", "~> 0.18.1"
22
+ spec.add_dependency "net-sftp", "~> 2.1.2"
23
+
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: squarespace-sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jordanandree
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-sftp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Sync files to and from a Squarespace Developer site over SFTP
70
+ email:
71
+ - jordanandree@gmail.com
72
+ executables:
73
+ - squarespace
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - .ruby-gemset
80
+ - .ruby-version
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/squarespace
86
+ - lib/squarespace/sync.rb
87
+ - lib/squarespace/sync/cli.rb
88
+ - lib/squarespace/sync/connection.rb
89
+ - lib/squarespace/sync/squarespace.tt
90
+ - lib/squarespace/sync/version.rb
91
+ - spec/cli_spec.rb
92
+ - spec/spec_helper.rb
93
+ - squarespace-sync.gemspec
94
+ homepage: http://github.com/jordanandree/squarespace-sync
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.7
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Sync files to and from a Squarespace Developer site
118
+ test_files:
119
+ - spec/cli_spec.rb
120
+ - spec/spec_helper.rb