2016-02-22 19:59:49 -08:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require "json"
|
|
|
|
|
2016-03-03 16:34:45 -08:00
|
|
|
# pick a custom env file if set
|
|
|
|
if File.exists?("/tmp/envfile")
|
|
|
|
custom_env = true
|
|
|
|
file = File.read("/tmp/envfile").strip
|
2016-09-13 19:09:41 -07:00
|
|
|
else
|
|
|
|
custom_env = false
|
2016-11-08 12:52:27 -05:00
|
|
|
file = ".env"
|
2016-03-03 16:34:45 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "Reading env from #{file}"
|
|
|
|
|
2016-09-13 18:49:57 -07:00
|
|
|
dotenv = begin
|
|
|
|
# find that above node_modules/react-native-config/ios/
|
2016-11-08 12:52:27 -05:00
|
|
|
raw = File.read(File.join(Dir.pwd, "../../../#{file}"))
|
2016-09-13 18:49:57 -07:00
|
|
|
raw.split("\n").inject({}) do |h, line|
|
|
|
|
key, val = line.split("=", 2)
|
|
|
|
if line.strip.empty? or line.start_with?('#')
|
|
|
|
h
|
|
|
|
else
|
|
|
|
key, val = line.split("=", 2)
|
|
|
|
h.merge!(key => val)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
puts("**************************")
|
|
|
|
puts("*** Missing .env file ****")
|
|
|
|
puts("**************************")
|
|
|
|
{} # set dotenv as an empty hash
|
|
|
|
end
|
2016-02-22 19:59:49 -08:00
|
|
|
|
2016-02-23 15:50:03 -08:00
|
|
|
# create obj file that sets DOT_ENV as a NSDictionary
|
|
|
|
dotenv_objc = dotenv.map { |k, v| %Q(@"#{k}":@"#{v}") }.join(",")
|
|
|
|
template = <<EOF
|
|
|
|
#define DOT_ENV @{ #{dotenv_objc} };
|
|
|
|
EOF
|
2016-02-22 19:59:49 -08:00
|
|
|
|
2016-02-23 15:50:03 -08:00
|
|
|
# write it so that ReactNativeConfig.m can return it
|
|
|
|
path = File.join(ENV["SYMROOT"], "GeneratedDotEnv.m")
|
|
|
|
File.open(path, "w") { |f| f.puts template }
|
2016-02-22 19:59:49 -08:00
|
|
|
|
2016-03-03 16:34:45 -08:00
|
|
|
if custom_env
|
|
|
|
File.delete("/tmp/envfile")
|
|
|
|
end
|
|
|
|
|
2016-08-28 21:03:52 -04:00
|
|
|
puts "Wrote to #{path}"
|