yjncopycat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/yjncopycat +13 -0
- data/lib/yjncopycat/commandparser.rb +56 -0
- data/lib/yjncopycat/version.rb +3 -0
- data/lib/yjncopycat/xcodeprojectcloner.rb +123 -0
- data/yjncopycat.gemspec +17 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1b8a140ec7d9f616b196be9321c75c0e575084b781c57721bd6e5ab0f9739f29
|
4
|
+
data.tar.gz: 63b9fbb27da19b0dfdfd42340bb32ee41944ab08d26ad7e469036162ca8f04da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5d8383580fc211d0dc3a45745a70c2cefb47bdb34d0397850d4d93f1abc7e1f30342ee4765a07def8e30a1338731fc9e20894d1862090c6c5f222aef6f2a583
|
7
|
+
data.tar.gz: 0dc29642b711de09a35accb47690f6647341771370849bd3702e3650782a2c834e850d99fb8ed20d1538fa95ffd1aab7f98882d00a713ae36e18ffb0ec8423ad
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 F
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# YJNCOPYCAT
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yjncopycat`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'yjncopycat'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install yjncopycat
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yjncopycat.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yjncopycat"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/yjncopycat
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
require 'colored2'
|
5
|
+
require 'yjncopycat/commandparser.rb'
|
6
|
+
require 'yjncopycat/xcodeprojectcloner.rb'
|
7
|
+
require 'yjncopycat/version.rb'
|
8
|
+
|
9
|
+
options = YJNCopycat::CommandParser.parse(ARGV)
|
10
|
+
puts ''
|
11
|
+
YJNCopycat::XcodeProjectCloner.new(options).createClone
|
12
|
+
puts ''
|
13
|
+
puts "End.".yellow
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'colored2'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module YJNCopycat
|
6
|
+
class CommandParser
|
7
|
+
def self.parse(args)
|
8
|
+
options = {}
|
9
|
+
parser = OptionParser.new do |parser|
|
10
|
+
parser.banner = "Usage: yjncopycat [options]"
|
11
|
+
|
12
|
+
parser.on('--url URL', 'This is the git URL') do |url|
|
13
|
+
options[:url] = url
|
14
|
+
end
|
15
|
+
parser.on('--name NAME', 'This is the new name for the project') do |name|
|
16
|
+
options[:name] = name
|
17
|
+
end
|
18
|
+
parser.on_tail('-v', '--version', 'Shows version') do
|
19
|
+
puts YJNCopycat::VERSION
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
parser.parse!(args)
|
26
|
+
rescue SystemExit => e
|
27
|
+
exit 0
|
28
|
+
rescue Exception => e
|
29
|
+
puts "ERROR: #{e}!".red
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
unless options.key?(:url)
|
34
|
+
puts "ERROR: Missing --url option!".red
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
|
38
|
+
unless options[:url] =~ URI::regexp #.to_s.empty?
|
39
|
+
puts "ERROR: Invalid value for --url option. Please input a valid URL of your git repo.".red
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
unless options.key?(:name)
|
44
|
+
puts "ERROR: Missing --name options!".red
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
if options[:name].length < 3
|
49
|
+
puts "ERROR: Invalid value for --name option. Make sure string is at least 3 characters.".red
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
options
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'colored2'
|
2
|
+
require 'cocoapods-downloader'
|
3
|
+
require 'xcodeproj'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'find'
|
6
|
+
|
7
|
+
module YJNCopycat
|
8
|
+
class XcodeProjectCloner
|
9
|
+
attr_reader :url, :new_name, :target_path, :xcodeproj_path, :old_name
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@url = options[:url]
|
13
|
+
@new_name = options[:name]
|
14
|
+
@target_path = "./#{@new_name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def createClone
|
18
|
+
createDirectory
|
19
|
+
downloadRepo
|
20
|
+
removePods
|
21
|
+
replaceOccurencesOfOldProjectNameWithNewNameInFiles
|
22
|
+
renameDirectories
|
23
|
+
renameFiles
|
24
|
+
reinstallPods
|
25
|
+
reinitializeGit
|
26
|
+
openProject
|
27
|
+
end
|
28
|
+
|
29
|
+
def createDirectory
|
30
|
+
system 'mkdir', '-p', target_path
|
31
|
+
puts "New folder created at: #{target_path}.".yellow
|
32
|
+
end
|
33
|
+
|
34
|
+
def downloadRepo
|
35
|
+
downloadOptions = Pod::Downloader.preprocess_options({ :git => @url })
|
36
|
+
downloader = Pod::Downloader.for_target(@target_path, downloadOptions)
|
37
|
+
puts ''
|
38
|
+
puts "Will start downloading project. This may take a while. Please wait.".yellow
|
39
|
+
downloader.download
|
40
|
+
puts "Download complete.".yellow
|
41
|
+
puts ''
|
42
|
+
end
|
43
|
+
|
44
|
+
def removePods
|
45
|
+
Dir.glob("#{@target_path}/**/Podfile.lock") do |lock_file|
|
46
|
+
`rm -rf #{lock_file}`
|
47
|
+
end
|
48
|
+
Dir.glob("#{@target_path}/**/*.xcworkspace") do |xcworkspace_file|
|
49
|
+
`rm -rf #{xcworkspace_file}`
|
50
|
+
end
|
51
|
+
Dir.glob("#{@target_path}/**/Pods/") do |pods_dir|
|
52
|
+
`rm -rf #{pods_dir}`
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def replaceOccurencesOfOldProjectNameWithNewNameInFiles
|
57
|
+
@xcodeproj_path = Find.find(target_path).select { |p| /.*\.xcodeproj$/ =~ p }.first
|
58
|
+
if @xcodeproj_path.nil?
|
59
|
+
puts "ERROR: Unable to locate xcodeproj file.".red
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
@old_name = File.basename(@xcodeproj_path, ".xcodeproj")
|
63
|
+
|
64
|
+
Dir.glob(@target_path + "/**/**/**/**").each do |filename|
|
65
|
+
next if Dir.exists? filename
|
66
|
+
text = File.read(filename)
|
67
|
+
for search, replace in { @old_name => @new_name }
|
68
|
+
text = text.gsub(search, replace)
|
69
|
+
end
|
70
|
+
File.open(filename, "w") { |file| file.puts text }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def renameDirectories
|
75
|
+
Dir.glob("#{@target_path}/**/#{@old_name}*").select { |file| File.directory? file }.reverse.each do |filename|
|
76
|
+
file = File.new(filename)
|
77
|
+
pattern = /(.*)#{@old_name}/
|
78
|
+
new_name = filename.gsub(pattern, "\\1#{@new_name}")
|
79
|
+
File.rename filename, new_name
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def renameFiles
|
84
|
+
Dir.glob("#{@target_path}/**/*#{@old_name}*").reverse.each do |filename|
|
85
|
+
file = File.new(filename)
|
86
|
+
pattern = /(.*)#{@old_name}/
|
87
|
+
new_name = filename.gsub(pattern, "\\1#{@new_name}")
|
88
|
+
File.rename filename, new_name
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def reinstallPods
|
93
|
+
Dir.glob("#{@target_path}/**/Podfile") do |podfile|
|
94
|
+
file = File.new(podfile)
|
95
|
+
podfile_dir = File.dirname(file)
|
96
|
+
Dir.chdir(podfile_dir) do
|
97
|
+
puts "Installing CocoaPods dependencies...".yellow
|
98
|
+
system "pod install"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def reinitializeGit
|
104
|
+
Dir.chdir(target_path) do
|
105
|
+
`rm -rf .git`
|
106
|
+
`git init`
|
107
|
+
`git add -A`
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def openProject
|
112
|
+
new_xcodeproj_file_path = Find.find(@target_path).select { |p| /.*\.xcodeproj$/ =~ p }.first
|
113
|
+
new_xcworkspace_file_path = Find.find(@target_path).select { |p| /.*\.xcworkspace$/ =~ p }.first
|
114
|
+
if new_xcworkspace_file_path.nil?
|
115
|
+
puts "Will open xcproj file at: " + new_xcodeproj_file_path
|
116
|
+
system "open '#{new_xcodeproj_file_path}'"
|
117
|
+
else
|
118
|
+
puts "Will open xcworkspace file at: " + new_xcworkspace_file_path
|
119
|
+
system "open '#{new_xcworkspace_file_path}'"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/yjncopycat.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/yjncopycat/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["Feb Dela Cruz"]
|
7
|
+
gem.email = ["fdelacruz.mail@gmail.com"]
|
8
|
+
gem.description = %q{Clones an Xcode project and renames it.}
|
9
|
+
gem.summary = %q{Clones an Xcode project and renames it.}
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = ["yjncopycat"]
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "yjncopycat"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = YJNCopycat::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yjncopycat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Feb Dela Cruz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Clones an Xcode project and renames it.
|
14
|
+
email:
|
15
|
+
- fdelacruz.mail@gmail.com
|
16
|
+
executables:
|
17
|
+
- yjncopycat
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/console
|
28
|
+
- bin/setup
|
29
|
+
- bin/yjncopycat
|
30
|
+
- lib/yjncopycat/commandparser.rb
|
31
|
+
- lib/yjncopycat/version.rb
|
32
|
+
- lib/yjncopycat/xcodeprojectcloner.rb
|
33
|
+
- yjncopycat.gemspec
|
34
|
+
homepage:
|
35
|
+
licenses: []
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.7.7
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Clones an Xcode project and renames it.
|
57
|
+
test_files: []
|