-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 331f884
Showing
12 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in flatter.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Gregory Berngardt | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# flatter | ||
|
||
Faced with similar problem? | ||
|
||
> 🚨 `error: unable to spawn process (Argument list too long)` | ||
Until [Apple not fix it](http://www.openradar.me/35879960) I made some solution for workaround this problem - flatter! | ||
|
||
Flatter is a gem which move all swift files in xCode project to root group. That's all :) | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'flatter' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install flatter | ||
|
||
## Usage | ||
|
||
Simple | ||
|
||
$ flatter "/path/to/your/project.xcodeproj" | ||
|
||
Specific group | ||
|
||
$ flatter "/path/to/your/project.xcodeproj" -g "SpecificGroup" | ||
|
||
Advanced | ||
|
||
$ flatter "/path/to/your/project.xcodeproj" -g "SpecificGroup" -e ".xib" | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/gregoryvit/flatter. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "bundler/gem_tasks" | ||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "bundler/setup" | ||
require "flatter" | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
# (If you use this, don't forget to add pry to your Gemfile!) | ||
# require "pry" | ||
# Pry.start | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'flatter/cli' | ||
Flatter::CLI.new.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
lib = File.expand_path("../lib", __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require "flatter/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "flatter" | ||
spec.version = Flatter::VERSION | ||
spec.authors = ["Gregory Berngardt"] | ||
spec.email = ["[email protected]"] | ||
|
||
spec.summary = %q{Flatter is a gem which move all files with specific extension in xCode project to root group.} | ||
spec.description = %q{Flatter is a gem which move all files with specific extension in xCode project to root group.} | ||
spec.homepage = "https://github.com/gregoryvit/flatter" | ||
spec.license = "MIT" | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git. | ||
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do | ||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
end | ||
spec.bindir = "bin" | ||
spec.executables = ["flatter"] | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.17" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_dependency "xcodeproj", "~> 1.0" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "flatter/version" | ||
require 'xcodeproj' | ||
require 'fileutils' | ||
|
||
module Flatter | ||
class Error < StandardError; end | ||
|
||
class FileMover | ||
|
||
# Move all files with specific extenstion from subfolders to root group | ||
def move_all_files_with_ext_to_root_group(project_path, dest_file_ext, root_group_path) | ||
project = Xcodeproj::Project.open(project_path) | ||
|
||
# Get root group | ||
if root_group_path.nil? | ||
root_group = project.main_group | ||
else | ||
root_group = project[root_group_path] | ||
end | ||
|
||
# Move files in FS | ||
base_dir_path = root_group.real_path.to_s | ||
|
||
# For each project file move to root group | ||
project.files.each do |file| | ||
file_ext = File.extname(file.path) | ||
if dest_file_ext == file_ext | ||
# Move files in FS hierarchy | ||
initial_path = file.real_path | ||
result_path = base_dir_path + '/' + File.basename(file.path) | ||
if result_path != initial_path | ||
FileUtils.mv(initial_path, result_path) | ||
end | ||
|
||
# Fix and move files in Xcode hierarchy | ||
file.set_source_tree("<group>") | ||
file.set_path(File.basename(file.path)) | ||
file.move(root_group) | ||
end | ||
end | ||
|
||
project.save() | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'optparse' | ||
require 'flatter' | ||
|
||
module Flatter | ||
class CLI | ||
|
||
def start | ||
options = {} | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: flatter PATH_TO_XCODEPROJ [options]" | ||
|
||
opts.on("-g String", String, "Path to root group") do |group_path| | ||
options[:group_path] = group_path | ||
end | ||
|
||
options[:files_ext] = ".swift" | ||
opts.on("-e String", String, "File extension. Default: .swift") do |files_ext| | ||
prefix = files_ext.start_with?(".") ? "" : "." | ||
options[:files_ext] = prefix + files_ext | ||
end | ||
end.parse! | ||
|
||
if ARGV.any? | ||
project_path = ARGV.first | ||
dest_file_ext = options[:files_ext] | ||
root_group_path = options[:group_path] | ||
Flatter::FileMover.new.move_all_files_with_ext_to_root_group(project_path, dest_file_ext, root_group_path) | ||
else | ||
puts "🛑 Error: Not arguments passed" | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Flatter | ||
VERSION = "1.0.0" | ||
end |