-
Notifications
You must be signed in to change notification settings - Fork 24.3k
/
init.sh
executable file
·46 lines (40 loc) · 1.2 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/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/")
.gsub("../../React/", "node_modules/react-native/React/")
File.write(dest, content)
end
end
def main(dest, app_name)
source = File.expand_path("../Examples/SampleApp", __FILE__)
files = Dir.chdir(source) { Dir["**/*"] }
.reject { |file| file["project.xcworkspace"] || file["xcuserdata"] }
.each { |file|
new_file = file
.gsub("SampleApp", app_name)
.gsub(/^_/, ".")
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 ""
puts " Open #{File.join(dest, app_name)}.xcodeproj in Xcode"
puts " Hit Run button"
puts ""
end