Permalink
Browse files

transenders first time

  • Loading branch information...
0 parents commit 23957c2c948285f08f00f0f4ec586de87debddc6 @mihael committed Mar 10, 2009
Showing with 399 additions and 0 deletions.
  1. +1 −0 .gitattributes
  2. +14 −0 .gitignore
  3. +4 −0 History.txt
  4. +58 −0 README.txt
  5. +30 −0 Rakefile
  6. +30 −0 bin/transender
  7. +176 −0 lib/transender.rb
  8. +16 −0 spec/spec_helper.rb
  9. +53 −0 spec/transender_spec.rb
  10. +12 −0 test/test_transender.rb
  11. +5 −0 test/test_transender.sh
@@ -0,0 +1 @@
+*.pbxproj -crlf -diff -merge
@@ -0,0 +1,14 @@
+# xcode noise
+build/*
+*.pbxuser
+*.mode1v3
+
+# old skool
+.svn
+
+# osx noise
+.DS_Store
+profile
+
+#
+tmp/*
@@ -0,0 +1,4 @@
+== 1.0.0 / 2009-03-06
+
+* 1 major enhancement
+ * Birthday!
@@ -0,0 +1,58 @@
+transender
+ by Mihael (Miha Plohl)
+ http://kitschmaster.com/kiches/246
+
+== DESCRIPTION:
+
+This program is very simple. Use it whenever you need to rename XCode iPhone SDK projects.
+
+== FEATURES/NO-PROBLEMS:
+
+* can clone XCode projects (on git) and rename them successfully (tested only on iPhone/iPod Touch projects)
+* use from command line or ruby program
+
+== SYNOPSIS:
+
+You could use it in a Rails app maybe like this:
+Transender::Ji.transform_and_zip({:app_title=>"myClonedProject", :transform=>"git://github.com/mihael/iproject.git", :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp]) }) do |zip|
+ render :text => zip
+end
+
+Or on the command line, like this:
+transender git://github.com/mihael/iproject.git myFreshProject /projects/
+
+== REQUIREMENTS:
+
+* sed
+* tar
+* git
+* ruby
+
+== INSTALL:
+
+* sudo gem install transender
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 FIXME (different license?)
+
+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.
@@ -0,0 +1,30 @@
+# Look in the tasks/setup.rb file for the various options that can be
+# configured in this Rakefile. The .rake files in the tasks directory
+# are where the options are used.
+
+begin
+ require 'bones'
+ Bones.setup
+rescue LoadError
+ begin
+ load 'tasks/setup.rb'
+ rescue LoadError
+ raise RuntimeError, '### please install the "bones" gem ###'
+ end
+end
+
+ensure_in_path 'lib'
+require 'transender'
+
+task :default => 'spec:run'
+
+PROJ.name = 'transender'
+PROJ.authors = 'Mihael'
+PROJ.email = 'kitschmaster@gmail.com'
+PROJ.url = 'http://kitschmaster.com/kiches/246'
+PROJ.version = Transender::VERSION
+PROJ.rubyforge.name = 'transender'
+PROJ.spec.opts << '--color'
+PROJ.ignore_file = '.gitignore'
+
+# EOF
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib transender]))
+
+$:.unshift File.join(File.dirname(__FILE__))
+
+#arguments
+transform = ARGV[0]
+app_title = ARGV[1]
+out_dir = ARGV[2]
+
+def usage
+ puts "Usage:\n"
+ puts "~>transender git://github.com/somebodyatgithub/someiphoneipodproject.git myCoolProject /myCool/Path/To/Projects/Path/"
+ puts "transform - a git repository \n"
+ puts "app_title - a fresh app / cloned from transform, renamed and replaced\n"
+ puts "out_dir - where to put fresh app's files\n"
+end
+
+unless transform&&app_title&&out_dir
+ usage
+ exit
+end
+
+require 'benchmark'
+
+time = Benchmark.realtime {Transender::Ji.transform_and_zip({:transform => transform, :app_title => app_title, :ji_path => out_dir})}
+puts "Realtime used : #{time}sec"
+
+# EOF
@@ -0,0 +1,176 @@
+require 'fileutils'
+require 'ftools'
+
+module Transender
+
+ # :stopdoc:
+ VERSION = '0.1.0'
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
+ # :startdoc:
+
+ # Returns the version string for the library.
+ #
+ def self.version
+ VERSION
+ end
+
+ # Returns the library path for the module. If any arguments are given,
+ # they will be joined to the end of the libray path using
+ # <tt>File.join</tt>.
+ #
+ def self.libpath( *args )
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
+ end
+
+ # Returns the lpath for the module. If any arguments are given,
+ # they will be joined to the end of the path using
+ # <tt>File.join</tt>.
+ #
+ def self.path( *args )
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
+ end
+
+ # Utility method used to require all files ending in .rb that lie in the
+ # directory below this file that has the same name as the filename passed
+ # in. Optionally, a specific _directory_ name can be passed in such that
+ # the _filename_ does not have to be equivalent to the directory.
+ #
+ def self.require_all_libs_relative_to( fname, dir = nil )
+ dir ||= ::File.basename(fname, '.*')
+ search_me = ::File.expand_path(
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
+
+ Dir.glob(search_me).sort.each {|rb| require rb}
+ end
+
+ #replaces all 'old' strings with 'fresh' strings
+ def self.replace_in_file( in_file, old, fresh, out_file)
+ `sed 's/#{old}/#{fresh}/g' <'#{in_file}' >'#{out_file}'`
+ end
+
+ def self.replace_strings_in_file(old, fresh, filename)
+ temp = "#{filename}.temp"
+ FileUtils.mv filename, temp
+ Transender.replace_in_file(temp, old, fresh, filename)
+ FileUtils.rm temp
+ end
+
+ def self.zip_dir(dir, out_file)
+ `tar cvfz '#{out_file}' '#{dir}'`
+ out_file
+ end
+
+ def self.extract_app_title(giturl)
+ giturl.split('/').last.split('.').first
+ end
+
+ #Transender - Ji
+ class Ji
+ attr_accessor :options, :app_title, :app_path, :transform, :transform_title, :ji_path, :id
+
+ # Supply a Hash of options containing:
+ # :app_title - your fresh apps title
+ # :transform - git repository of the base project - app_title becomes a clone of it
+ # :ji_path - output dir
+ def initialize(options)
+ raise ArgumentError unless options.class == Hash && options[:app_title] && options[:transform] && options[:ji_path]
+ @options = options
+ @app_title = @options[:app_title]
+ @transform = @options[:transform]
+ @transform_title = Transender.extract_app_title(@transform)
+ @ji_path = @options[:ji_path]
+ @app_path = File.join(@ji_path, @app_title)
+ @id = Time.now.strftime("%Y-%m-%d-%s")
+ end
+
+ #clones from transform then removes git
+ def clone_and_remove_git
+ #prepare destination without any warning
+ `rm -rf #{@app_path}`
+ #clone that git repo and rename at the same time
+ `git clone #{@transform} #{@app_path}`
+ #remove any past life remains from the fresh project
+ `rm -rf #{File.join(@app_path, 'build')}`
+ `rm -rf #{File.join(@app_path, '.git')}`
+ puts "Cloned from #{@transform} into #{@app_path}."
+ end
+
+ #renames within project app_title
+ def rename
+ todo = ""
+ if rename_files
+ if replace_strings_in_files
+ else
+ todo << 'TODO: You need to replace some strings in some files manually. Thanks.\n'
+ end
+ else
+ todo << 'TODO: You need to rename some files manually. Thanks.\n'
+ end
+ todo = todo.empty? ? "Renamed/replaced occurences of #{transform_title} to #{app_title}." : todo
+ puts todo
+ end
+
+ def zip
+ z = File.join(ji_path, "#{app_title}.zip")
+ `rm -rf #{z}` #remove any previous zips without any warnings
+ Transender.zip_dir(File.join(ji_path, app_title), z)
+ puts "Zipped #{app_title} into #{z}" if File.exists?(z)
+ z
+ end
+
+ def transform
+ clone_and_remove_git
+ rename
+ zip
+ end
+
+ #Use maybe like this: Transender::Ji.transform_and_zip(ahash) {|zip| render :text => zip}
+ def self.transform_and_zip(t={}, &block)
+ zip = Ji.new(t).transform
+ yield zip if block
+ end
+
+ private
+
+ def rename_files
+ FileUtils.mv "#{app_path}/#{transform_title}.xcodeproj", "#{app_path}/#{app_title}.xcodeproj"
+ Dir["#{app_path}/*.{m,h,pch}"].each do |filename|
+ if filename =~ /#{transform_title}/
+ FileUtils.mv filename, filename.gsub(/#{transform_title}/, app_title)
+ end
+ end
+ Dir["#{app_path}/Classes/*.{m,h}"].each do |filename|
+ if filename =~ /#{transform_title}/
+ FileUtils.mv filename, filename.gsub(/#{transform_title}/, app_title)
+ end
+ end
+ true
+ rescue
+ puts $!
+ false
+ end
+
+ def replace_strings_in_files
+ Dir["#{app_path}/*.{m,h,pch,xib}"].each do |filename|
+ Transender.replace_strings_in_file(transform_title, app_title, filename)
+ end
+ Dir["#{app_path}/Classes/*.{m,h}"].each do |filename|
+ Transender.replace_strings_in_file(transform_title, app_title, filename)
+ end
+ Dir["#{app_path}/#{app_title}.xcodeproj/*.*"].each do |filename|
+ Transender.replace_strings_in_file(transform_title, app_title, filename)
+ end
+ true
+ rescue
+ puts $!
+ false
+ end
+
+ end # class Ji
+
+end # module Transender
+
+Transender.require_all_libs_relative_to(__FILE__)
+
+# EOF
@@ -0,0 +1,16 @@
+
+require File.expand_path(
+ File.join(File.dirname(__FILE__), %w[.. lib transender]))
+
+Spec::Runner.configure do |config|
+ # == Mock Framework
+ #
+ # RSpec uses it's own mocking framework by default. If you prefer to
+ # use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+end
+
+# EOF
@@ -0,0 +1,53 @@
+
+require File.join(File.dirname(__FILE__), %w[spec_helper])
+include Transender
+
+describe Transender do
+
+ it "should not be instantiated without cool arguments" do
+ lambda { Ji.new( ) }.should raise_error
+ lambda { Ji.new( "not Hash" ) }.should raise_error(ArgumentError)
+ end
+
+ it "should be instantiated with fine hashish" do
+ lambda { Ji.new( {:app_title=>"xyzproject", :transform=>"iproject", :ji_path=>""} ) }.should_not raise_error
+ end
+
+ it "should clone and remove git" do
+ ji = Ji.new({:app_title=>"xyzproject", :transform=>File.join(File.dirname(__FILE__), %w[.. iproject]), :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp]) })
+ ji.clone_and_remove_git
+ File.exists?(ji.app_path).should be(true)
+ File.exists?(File.join(ji.app_path, '.git')).should be(false)
+ File.exists?(File.join(ji.app_path, 'build')).should be(false)
+ end
+
+ it "should clone and remove git and rename" do
+ ji = Ji.new({:app_title=>"xyzproject", :transform=>File.join(File.dirname(__FILE__), %w[.. iproject]), :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp]) })
+ ji.clone_and_remove_git
+ ji.rename
+ puts File.exists?(File.join(ji.app_path, ji.app_title)).should be(true)
+ end
+
+
+ it "should transform and zip" do
+ proc do
+ Ji.transform_and_zip({:app_title=>"xyzproject", :transform=>File.join(File.dirname(__FILE__), %w[.. iproject]), :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp]) }) do |zip|
+ zip.should == File.join(File.dirname(__FILE__), %w[.. tmp xyzproject.zip])
+ File.exists?(zip).should == true
+ end
+ end.should_not raise_error
+ end
+
+ it "should transform and zip a remote git project" do
+ proc do
+ Ji.transform_and_zip({:app_title=>"freshproject", :transform=>" git://github.com/mihael/iproject.git", :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp]) }) do |zip|
+ zip.should == File.join(File.dirname(__FILE__), %w[.. tmp freshproject.zip])
+ File.exists?(zip).should == true
+ end
+ end.should_not raise_error
+ end
+
+
+end
+
+# EOF
Oops, something went wrong.

0 comments on commit 23957c2

Please sign in to comment.