Crafter - setup your cocoa projects with ease

How do you setup your Cocoa projects?
Do you always set same warnings, clone configurations and do bunch of other stuff?

I made a tool that might help.

We all know that Xcode templating system is far from perfect, beside we often use different templates, but same level of warnings, scripts etc.

What if you could define your project setup once (even with optional stuff) then just apply that to all your projects?

Enter crafter

That's why I've created crafter, a ruby gem that you can install, setup your configuration once and enjoy hours of time saved.

So how does it work?

Install it by calling:

gem install crafter
crafter reset

this will create your personal configuration file at ~/.crafter.rb

now open that file with your favourite editor and you will see default configuration, along with description of different parts:

load "#{Crafter::ROOT}/config/default_scripts.rb"

# All your configuration should happen inside configure block
Crafter.configure do

  # This are projects wide instructions
  add_platform({:platform => :ios, :deployment => 6.0})
  add_git_ignore
  duplicate_configurations({:adhoc => :debug, :profiling => :debug})

  # set of options, warnings, static analyser and anything else normal xcode treats as build options
  set_options %w(
    GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED
    GCC_WARN_MISSING_PARENTHESES
    GCC_WARN_ABOUT_RETURN_TYPE
    GCC_WARN_SIGN_COMPARE
    GCC_WARN_CHECK_SWITCH_STATEMENTS
    GCC_WARN_UNUSED_FUNCTION
    GCC_WARN_UNUSED_LABEL
    GCC_WARN_UNUSED_VALUE
    GCC_WARN_UNUSED_VARIABLE
    GCC_WARN_SHADOW
    GCC_WARN_64_TO_32_BIT_CONVERSION
    GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS
    GCC_WARN_UNDECLARED_SELECTOR
    GCC_WARN_TYPECHECK_CALLS_TO_PRINTF

    RUN_CLANG_STATIC_ANALYZER
    GCC_TREAT_WARNINGS_AS_ERRORS
  )

  # target specific options, :default is just a name for you, feel free to call it whatever you like
  with :default do

    # each target have set of pods
    pods << %w(NSLogger-CocoaLumberjack-connector TestFlightSDK)

    # each target can have optional blocks, eg. crafter will ask you if you want to include networking with a project
    add_option :networking do
      pods << 'AFNetworking'
    end

    add_option :coredata do
      pods << 'MagicalRecord'
    end

    # each target can have shell scripts added, in this example we are adding my icon versioning script as in http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/
    scripts << {:name => 'icon versioning', :script => Crafter.icon_versioning_script}

    # we can also execute arbitrary ruby code when configuring our projects, here we rename all our standard icon* to icon_base for versioning script
    icon_rename = proc do |file|
      extension = File.extname(file)
      file_name = File.basename(file, extension)
      File.rename(file, "#{File.dirname(file)}/#{file_name}_base#{extension}")
    end

    Dir['**/Icon.png'].each(&icon_rename)
    Dir['**/Icon@2x.png'].each(&icon_rename)
    Dir['**/Icon-72.png'].each(&icon_rename)
    Dir['**/Icon-72@2x.png'].each(&icon_rename)
  end

  # more targets setup
  with :tests do
    add_option :kiwi do
      pods << 'Kiwi'
      scripts << {:name => 'command line unit tests', :script => Crafter.command_line_test_script}
    end
  end
end

As you can see the configuration files is quite easy, yet is pretty flexible.
Once you set it up as you see fit, go to your project folder (the one with xcodeproj, workspace etc.) and call:

crafter

it will guide you through project setup, with default configuration it would look like this:

1. sample
2. sampleTests
Which target should I use for default?
1
1. sample
2. sampleTests
Which target should I use for tests?
2
do you want to add networking? [Yn]
n
do you want to add coredata? [Yn]
y
do you want to add testing? [Yn]
n
duplicating configurations
setting up variety of options
preparing git ignore
preparing pod file
adding scripts
Finished.

Now your project should have all options applied, generated Podfile (call pod install or set it up in your configuration).

I'm learning Ruby, so I'm looking forward to pull requests on GitHub

Send me your thoughts, I'm merowing_ on twitter

Conclusion:

The library was inspired by liftoff

I'd like to thank @alloy, @orta, @romainbriche for taking some of their valuable time and sharing their thoughts about beta version.

You've successfully subscribed to Krzysztof Zabłocki
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.