Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoryvit committed Aug 22, 2019
0 parents commit 331f884
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
4 changes: 4 additions & 0 deletions Gemfile
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
21 changes: 21 additions & 0 deletions LICENSE.txt
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.
47 changes: 47 additions & 0 deletions README.md
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).
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"
task :default => :spec
14 changes: 14 additions & 0 deletions bin/console
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__)
4 changes: 4 additions & 0 deletions bin/flatter
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
8 changes: 8 additions & 0 deletions bin/setup
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
30 changes: 30 additions & 0 deletions flatter.gemspec
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
46 changes: 46 additions & 0 deletions lib/flatter.rb
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
34 changes: 34 additions & 0 deletions lib/flatter/cli.rb
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
3 changes: 3 additions & 0 deletions lib/flatter/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Flatter
VERSION = "1.0.0"
end

0 comments on commit 331f884

Please sign in to comment.