2015-03-20 15:43:51 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
def cp(src, dest, app_name)
|
|
|
|
if File.directory?(src)
|
|
|
|
Dir.mkdir(dest) unless Dir.exists?(dest)
|
|
|
|
else
|
|
|
|
content = File.read(src)
|
|
|
|
.gsub("SampleApp", app_name)
|
|
|
|
.gsub("Examples/#{app_name}/", "")
|
|
|
|
.gsub("../../Libraries/", "node_modules/react-native/Libraries/")
|
2015-03-26 15:10:59 +00:00
|
|
|
.gsub("../../React/", "node_modules/react-native/React/")
|
2015-03-20 15:43:51 +00:00
|
|
|
File.write(dest, content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def main(dest, app_name)
|
2015-03-22 21:04:55 +00:00
|
|
|
source = File.expand_path("../Examples/SampleApp", __FILE__)
|
2015-03-20 15:43:51 +00:00
|
|
|
files = Dir.chdir(source) { Dir["**/*"] }
|
|
|
|
.reject { |file| file["project.xcworkspace"] || file["xcuserdata"] }
|
|
|
|
.each { |file|
|
2015-04-14 18:36:13 +00:00
|
|
|
new_file = file
|
|
|
|
.gsub("SampleApp", app_name)
|
|
|
|
.gsub(/^_/, ".")
|
2015-03-20 15:43:51 +00:00
|
|
|
cp File.join(source, file), File.join(dest, new_file), app_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if ARGV.count == 0
|
|
|
|
puts "Usage: #{__FILE__} <ProjectNameInCamelCase>"
|
|
|
|
puts ""
|
|
|
|
puts "This script will bootstrap new React Native app in current folder"
|
|
|
|
else
|
|
|
|
app_name = ARGV.first
|
|
|
|
dest = Dir.pwd
|
|
|
|
puts "Setting up new React Native app in #{dest}"
|
|
|
|
puts ""
|
|
|
|
|
|
|
|
main(dest, app_name)
|
|
|
|
|
|
|
|
puts "Next steps:"
|
|
|
|
puts ""
|
2015-03-26 01:23:53 +00:00
|
|
|
puts " Open #{File.join(dest, app_name)}.xcodeproj in Xcode"
|
2015-03-20 15:43:51 +00:00
|
|
|
puts " Hit Run button"
|
|
|
|
puts ""
|
|
|
|
end
|
|
|
|
|