waggit 0.0.009 → 0.0.011

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32d0652e458a68d433a19dcbf7e0bcd86c9ceaa1
4
- data.tar.gz: 4e4a1c2b5eff37579bfed6f2d1d128fb2f8a4d7e
3
+ metadata.gz: fb6f12cca80872d6f3abf76d06d91e70e9f37b53
4
+ data.tar.gz: 6422510225fd24c204c13d58872a5e3aed54ce08
5
5
  SHA512:
6
- metadata.gz: d12ce726686cf38c08058b793c1ce41856142a56767cc5569b8834f7ba2fa5700a0c61689512f6177be0a2686cc64f7f56b11ea30f21ad72a40d8ff763087123
7
- data.tar.gz: 9d46e28deacea8a733a374779f7da3b6115db00d19837c99b8e5c3cac108905756a6798aa3365380ce8f63ff34953c6b3f9ae8f150531eaea38b34624f9d1c36
6
+ metadata.gz: ead58380a6ad904aa0aa36c5239345ea51f2e7ffdd0da5d9ced0ea9d24dd616c1b17f5aa5ae255c41b2815fa3001bc3d526e42e80a25db249a5e9d603d0e7c24
7
+ data.tar.gz: 7b4e59fe4bc7211233d0cb227f2d3c41c0156fb96188b507cb292905e6498d34e4dfd19fb54c257f961bd1d97cca9c635555ae1eaf1dfc67c45ef276bddc1f60
data/bin/waggit CHANGED
@@ -4,9 +4,9 @@ require 'waggit.rb'
4
4
 
5
5
  cmd = ARGV[0].downcase
6
6
 
7
- for arg in ARGV
8
- puts "arg: #{arg}"
9
- end
7
+ #for arg in ARGV
8
+ #puts "arg: #{arg}"
9
+ #end
10
10
 
11
11
  options = []
12
12
  if ARGV.length > 1
@@ -25,6 +25,8 @@ when "pull"
25
25
  Waggit.pull(options)
26
26
  when "c", "clean"
27
27
  Waggit.clean(options)
28
+ when "t", "test"
29
+ Waggit.test_dir(options)
28
30
  else
29
31
  puts "Invalid command!"
30
32
  end
@@ -3,11 +3,29 @@
3
3
  #
4
4
  module Command
5
5
 
6
- # Runs a command and returns the output
6
+ # Runs a command and passes output to standard out,
7
+ # and returns the result
7
8
  #
8
- def self.run(command)
9
- return `#{command}`
9
+ def self.run(command, output = true)
10
+ IO.popen "#{command}" do |fd|
11
+ if output
12
+ until fd.eof?
13
+ puts fd.readline
14
+ end
15
+ end
16
+ end
17
+ return $?.success?
10
18
  end
19
+ #Open3.capture3( "#{command}") do |stdin, stdout, status|
20
+ # if output
21
+ # until stdin.eof?
22
+ # stdout.puts stdin.readline
23
+ # end
24
+ # end
25
+ #return status.success?
26
+ #end
27
+ #return `#{command}`
28
+ #end
11
29
 
12
30
 
13
31
  end
data/lib/git.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'command.rb'
1
+ require 'command'
2
2
 
3
3
  module Git
4
4
 
@@ -104,4 +104,11 @@ module Git
104
104
  puts "This does nothin yet"
105
105
  end
106
106
 
107
+ # Return true if the provided directory is in a git repo, otherwise false. Can optionally provide wa
108
+ #
109
+ def self.is_git_dir?(dir = Dir.pwd)
110
+ return Dir.chdir dir do
111
+ return Command.run("git rev-parse", false)
112
+ end
113
+ end
107
114
  end
@@ -1,122 +1,176 @@
1
- require 'git.rb'
2
- require 'wagon.rb'
3
- require 'files.rb'
1
+ require 'git'
2
+ require 'wagon'
3
+ require 'files'
4
4
 
5
5
  module Waggit
6
6
 
7
7
  # Verifies that the current working directory is setup to work with both git and wagon
8
8
  #
9
- def self.test()
10
- puts "test... doesn't work yet"
9
+ def self.test_dir(options={})
10
+ test = true
11
+ if !Git.is_git_dir?
12
+ # FIXME: Cannot find a way to capture the output of the above git method,
13
+ # so there is another error that is output: 'fatal: Not a git repository
14
+ # (or any of the parent directories): .git'
15
+
16
+ #puts "error: not in a git directory."
17
+ test = false
18
+ end
19
+ if !Wagon.is_wagon_dir?
20
+ puts "error: Not in a wagon directory."
21
+ test = false
22
+ end
23
+ if test
24
+ puts "Current directory is both a wagon and a git directory"
25
+ end
26
+ return test
27
+ end
28
+
29
+ # Waggit can only really work if it is in a directory that has both git and
30
+ # wagon setup. This finds an appropriate working directory with both waggit
31
+ # and git and return the path as a string or return nil.
32
+ #
33
+ def self.get_waggit_dir()
34
+ dir = Wagon.get_wagon_path
35
+ puts "error: Unable to find a Wagon directory in your current path." unless dir
36
+ if dir
37
+ dir = Git.is_git_dir?(dir) ? dir : nil
38
+ puts "error: Wagon directory is not setup with git: #{dir}" unless dir
39
+ end
40
+ return dir
11
41
  end
12
42
 
13
- def self.clean(options)
14
- Files.clean_css
43
+ def self.clean(options={})
44
+ dir = get_waggit_dir
45
+ if dir
46
+ Dir.chdir(dir) do
47
+ Files.clean_css
48
+ end
49
+ end
15
50
  end
16
51
 
17
52
  # Push local changes to wagon, ignoring git.
18
53
  #
19
54
  def self.forcepush(options)
20
- Files.clean_css
21
- puts Wagon.push(options)
55
+ dir = get_waggit_dir
56
+ if dir
57
+ Dir.chdir(dir) do
58
+ Files.clean_css
59
+ Wagon.push(options)
60
+ end
61
+ end
22
62
  end
23
63
 
24
64
  # Commit local changes and keep in sync with git, then push to wagon.
25
65
  #
26
66
  def self.push(options)
27
- puts Git.add_all
28
- puts Git.commit_prompt
29
- Files.clean_css
30
- if Git.has_changes?
31
- puts Git.add_all
32
- puts Git.commit "cleaned css"
67
+ dir = get_waggit_dir
68
+ if dir
69
+ Dir.chdir(dir) do
70
+ Git.add_all
71
+ Git.commit_prompt
72
+ Files.clean_css
73
+ if Git.has_changes?
74
+ Git.add_all
75
+ Git.commit "cleaned css"
76
+ end
77
+ Git.pull
78
+ Git.push
79
+ Wagon.push(options)
80
+ end
33
81
  end
34
- puts Git.pull
35
- puts Git.push
36
- puts Wagon.push(options)
37
82
  end
38
83
 
39
84
  def self.pull(options)
40
- begin
41
- puts Git.checkout_master
42
- puts Git.delete_wagon
43
- puts Git.delete_local
44
- puts Git.stash
45
-
46
- puts Git.checkout_new_wagon
47
- puts Wagon.pull(options)
48
- #TODO: Checkout: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
49
- if Git.has_changes?
50
- puts Git.add_all
51
- puts Git.commit "merge wagon pull"
85
+ dir = get_waggit_dir
86
+ if dir
87
+ Dir.chdir(dir) do
88
+ begin
89
+ Git.checkout_master
90
+ Git.delete_wagon
91
+ Git.delete_local
92
+ Git.stash
93
+
94
+ Git.checkout_new_wagon
95
+ Wagon.pull(options)
96
+ #TODO: Checkout: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
97
+ if Git.has_changes?
98
+ Git.add_all
99
+ Git.commit "merge wagon pull"
100
+ end
101
+
102
+ Git.checkout_master
103
+ Git.rebase_wagon
104
+ Git.checkout_master
105
+ Git.merge_wagon
106
+
107
+ Git.checkout_new_local
108
+ Git.stash_pop
109
+ Git.add_all
110
+ Git.commit_prompt
111
+ Git.rebase_local
112
+ Git.checkout_master
113
+ Git.merge_local
114
+ Git.delete_wagon
115
+ Git.delete_local
116
+ rescue Exception
117
+ "Pull aborted, switching back to master branch"
118
+ Git.checkout_master
119
+ raise
120
+ end
52
121
  end
53
-
54
- puts Git.checkout_master
55
- puts Git.rebase_wagon
56
- puts Git.checkout_master
57
- puts Git.merge_wagon
58
-
59
- puts Git.checkout_new_local
60
- puts Git.stash_pop
61
- puts Git.add_all
62
- puts Git.commit_prompt
63
- puts Git.rebase_local
64
- puts Git.checkout_master
65
- puts Git.merge_local
66
- puts Git.delete_wagon
67
- puts Git.delete_local
68
- rescue Exception
69
- puts "Pull aborted, switching back to master branch"
70
- puts Git.checkout_master
71
- raise
72
122
  end
73
-
74
123
  end
75
124
 
76
125
  def self.sync(options)
77
- begin
78
- puts Git.checkout_master
79
- puts Git.delete_wagon
80
- puts Git.delete_local
81
- puts Git.stash
82
-
83
- puts Git.checkout_new_wagon
84
- puts Wagon.pull(options)
85
- #TODO: Checkout: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
86
- if Git.has_changes?
87
- puts Git.add_all
88
- puts Git.commit "merge wagon pull"
126
+ dir = get_waggit_dir
127
+ if dir
128
+ Dir.chdir(dir) do
129
+ begin
130
+ Git.checkout_master
131
+ Git.delete_wagon
132
+ Git.delete_local
133
+ Git.stash
134
+
135
+ Git.checkout_new_wagon
136
+ Wagon.pull(options)
137
+ #TODO: Checkout: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
138
+ if Git.has_changes?
139
+ Git.add_all
140
+ Git.commit "merge wagon pull"
141
+ end
142
+
143
+ Git.checkout_master
144
+ Git.rebase_wagon
145
+ Git.checkout_master
146
+ Git.merge_wagon
147
+
148
+ Git.checkout_new_local
149
+ Git.stash_pop
150
+ Git.add_all
151
+ Git.commit_prompt
152
+ Git.rebase_local
153
+ Git.checkout_master
154
+ Git.merge_local
155
+ Git.delete_wagon
156
+ Git.delete_local
157
+
158
+ Files.clean_css
159
+ if Git.has_changes?
160
+ Git.add_all
161
+ Git.commit "cleaned css"
162
+ end
163
+
164
+ Git.pull
165
+ Git.push
166
+
167
+ Wagon.push(options)
168
+ rescue Exception
169
+ "Sync aborted, switching back to master branch"
170
+ Git.checkout_master
171
+ raise
172
+ end
89
173
  end
90
-
91
- puts Git.checkout_master
92
- puts Git.rebase_wagon
93
- puts Git.checkout_master
94
- puts Git.merge_wagon
95
-
96
- puts Git.checkout_new_local
97
- puts Git.stash_pop
98
- puts Git.add_all
99
- puts Git.commit_prompt
100
- puts Git.rebase_local
101
- puts Git.checkout_master
102
- puts Git.merge_local
103
- puts Git.delete_wagon
104
- puts Git.delete_local
105
-
106
- Files.clean_css
107
- if Git.has_changes?
108
- puts Git.add_all
109
- puts Git.commit "cleaned css"
110
- end
111
-
112
- puts Git.pull
113
- puts Git.push
114
-
115
- puts Wagon.push(options)
116
- rescue Exception
117
- puts "Sync aborted, switching back to master branch"
118
- puts Git.checkout_master
119
- raise
120
174
  end
121
175
  end
122
176
 
@@ -52,8 +52,6 @@ module Wagon
52
52
  else
53
53
  return ''
54
54
  end
55
-
56
-
57
55
  end
58
56
 
59
57
  def self.pull(options)
@@ -64,4 +62,37 @@ module Wagon
64
62
  Command.run("bundle exec wagon push production#{self.process_options(options)}")
65
63
  end
66
64
 
65
+
66
+ # FROM : https://github.com/locomotivecms/wagon/blob/master/lib/locomotive/wagon/cli.rb#L8-L31
67
+ # This method is heavily tweaked and may require more modifications to be acurate.
68
+ # Check if the path given in option ('.' by default) points to a LocomotiveCMS
69
+ # site. It is also possible to pass a path other than the one from the options.
70
+ #
71
+ # @param [ String ] path The optional path of the site instead of options['path']
72
+ #
73
+ # @return [ String ] The fullpath to the LocomotiveCMS site or nil if it is not a valid site.
74
+ #
75
+ def self.is_wagon_dir?(path = '.')
76
+ path = path == '.' ? Dir.pwd : File.expand_path(path)
77
+ return File.exists?(File.join(path, 'config', 'site.yml'))
78
+ end
79
+
80
+ # Determines if there is a wagon path in the immediate directory or the directory above it.
81
+ # If so, the path will be returned, otherwise nill. This does not search sub directories.
82
+ def self.get_wagon_path()
83
+ dir = nil
84
+ if is_wagon_dir? Dir.pwd
85
+ dir = Dir.pwd
86
+ else
87
+ require 'pathname'
88
+ Pathname.new(Dir.pwd).ascend do |parent|
89
+ if is_wagon_dir? parent
90
+ dir = parent.to_s
91
+ break
92
+ end
93
+ end
94
+ end
95
+ return dir
96
+ end
97
+
67
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waggit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.009
4
+ version: 0.0.011
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mere Agency