xcmv 0.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/xcmv +4 -6
- data/lib/xcmv/file.rb +30 -3
- data/lib/xcmv/version.rb +1 -1
- data/lib/xcmv.rb +45 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 456870dbe3e27ce5b5a643e968015b80d9e4db00
|
4
|
+
data.tar.gz: 3afa9566039e0b74f5bf2781540e6012aedd8963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d8ca18f07edebe74a993404eb291c07cfd0c34d56290f0f0a4b153f11d748fcb072be3a84f3687b235de352d8e6b05d614dc47513f2042d88d8868130178d6
|
7
|
+
data.tar.gz: 7725808f9f589869d8d262db3d7ec6d17e843a7a98f3819932e71448ba9c1322b7fa1c1d41f2fae1e9c26d773872984222950c2136ca090b9c89867b5b9088bb
|
data/bin/xcmv
CHANGED
@@ -50,14 +50,12 @@ ARGV.map!{ |a| Pathname.new(a) }
|
|
50
50
|
dst = ARGV.pop
|
51
51
|
if dst.directory?
|
52
52
|
ARGV.each do |src|
|
53
|
-
|
54
|
-
XcodeMove.mv(XcodeMove::File.new(src), XcodeMove::File.new(dst_file), options)
|
53
|
+
XcodeMove.mv(src, dst, options)
|
55
54
|
end
|
56
55
|
else
|
57
|
-
if ARGV.count > 2
|
56
|
+
if ARGV.count > 2 || ARGV[0].directory?
|
58
57
|
abort "Error: moving more than one file to #{dst}\n" + parser.help
|
59
58
|
end
|
60
59
|
src = ARGV[0]
|
61
|
-
XcodeMove.mv(
|
62
|
-
end
|
63
|
-
|
60
|
+
XcodeMove.mv(src, dst, options)
|
61
|
+
end
|
data/lib/xcmv/file.rb
CHANGED
@@ -5,7 +5,7 @@ module XcodeMove
|
|
5
5
|
|
6
6
|
def initialize(path)
|
7
7
|
path = Pathname.new path
|
8
|
-
@path = path.
|
8
|
+
@path = path.expand_path
|
9
9
|
end
|
10
10
|
|
11
11
|
def project
|
@@ -19,11 +19,15 @@ module XcodeMove
|
|
19
19
|
def header?
|
20
20
|
path.extname == '.h'
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
def with_dirname(root_path)
|
24
|
+
new_path = root_path + path.basename
|
25
|
+
self.class.new(new_path) # want to return the same kind of object
|
26
|
+
end
|
23
27
|
|
24
28
|
# Traverses up from the `path` to enumerate over xcodeproj directories
|
25
29
|
def reachable_projects
|
26
|
-
path.ascend.find_all{ |p| p.directory? }.flat_map do |dir|
|
30
|
+
path.ascend.find_all{ |p| p.exist? and p.directory? }.flat_map do |dir|
|
27
31
|
dir.children.select{ |p| p.extname == '.xcodeproj' }
|
28
32
|
end
|
29
33
|
end
|
@@ -95,4 +99,27 @@ module XcodeMove
|
|
95
99
|
@pbx_file = project.files.find{ |f| f.real_path == path }
|
96
100
|
end
|
97
101
|
end
|
102
|
+
|
103
|
+
class Group < File
|
104
|
+
def initialize(path)
|
105
|
+
path = Pathname.new path
|
106
|
+
@path = path.expand_path
|
107
|
+
end
|
108
|
+
|
109
|
+
def remove_from_project
|
110
|
+
if not pbx_file.nil?
|
111
|
+
pbx_file.children.each do | c |
|
112
|
+
c.remove_from_project
|
113
|
+
end
|
114
|
+
pbx_file.remove_from_project
|
115
|
+
@pbx_file = nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def pbx_load
|
122
|
+
@pbx_file = project.main_group.recursive_children.find { |g| g.respond_to?(:real_path) and g.real_path == path }
|
123
|
+
end
|
124
|
+
end
|
98
125
|
end
|
data/lib/xcmv/version.rb
CHANGED
data/lib/xcmv.rb
CHANGED
@@ -7,35 +7,58 @@ require_relative 'xcmv/version'
|
|
7
7
|
|
8
8
|
module XcodeMove
|
9
9
|
|
10
|
-
# Moves from one `
|
10
|
+
# Moves from one `Pathname` to another
|
11
11
|
def self.mv(src, dst, options)
|
12
|
-
|
12
|
+
src_file = src.directory? ? Group.new(src) : File.new(src)
|
13
|
+
dst_file = src_file.with_dirname(dst)
|
13
14
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
15
|
+
puts("#{src_file.path} => #{dst_file.path}")
|
16
|
+
|
17
|
+
project_mv(src_file, dst_file, options)
|
18
|
+
disk_mv(src_file, dst_file, options)
|
19
|
+
save(src_file, dst_file)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Prepare the project file(s) for the move
|
25
|
+
def self.project_mv(src_file, dst_file, options)
|
26
|
+
if src_file.path.directory?
|
27
|
+
# Process all children first
|
28
|
+
children = src_file.path.children.map { |c| c.directory? ? Group.new(c) : File.new(c) }
|
29
|
+
children.each do | src_child |
|
30
|
+
dst_child = src_child.with_dirname(dst_file.path)
|
31
|
+
project_mv(src_child, dst_child, options)
|
32
|
+
end
|
17
33
|
else
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
34
|
+
# Remove old destination file reference if it exists
|
35
|
+
if dst_file.pbx_file
|
36
|
+
dst_file.remove_from_project
|
37
|
+
end
|
23
38
|
|
24
|
-
|
25
|
-
|
26
|
-
|
39
|
+
# Add new destination file reference to the new xcodeproj
|
40
|
+
dst_file.create_file_reference
|
41
|
+
dst_file.add_to_targets(options[:targets], options[:headers])
|
42
|
+
end
|
27
43
|
|
28
|
-
#
|
29
|
-
if
|
30
|
-
|
31
|
-
else
|
32
|
-
|
44
|
+
# Remove original directory/file from xcodeproj
|
45
|
+
if src_file.pbx_file
|
46
|
+
src_file.remove_from_project
|
47
|
+
else
|
48
|
+
warn("warning: #{src_file.path.realdirpath} not found in #{src_file.project.path.basename}. moving anyway...")
|
33
49
|
end
|
34
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
# Move the src_file to the dst_file on disk
|
53
|
+
def self.disk_mv(src_file, dst_file, options)
|
54
|
+
mover = options[:git] ? "git mv" : "mv"
|
55
|
+
command = "#{mover} '#{src_file.path}' '#{dst_file.path}'"
|
35
56
|
system(command) || abort
|
57
|
+
end
|
36
58
|
|
37
|
-
|
38
|
-
|
39
|
-
|
59
|
+
# Save the src_file and dst_file project files to disk
|
60
|
+
def self.save(src_file, dst_file)
|
61
|
+
src_file.save_and_close
|
62
|
+
dst_file.save_and_close
|
40
63
|
end
|
41
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcmv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliott Williams
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.
|
61
|
+
rubygems_version: 2.5.2.3
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Xcode Move
|