Max Komarychev 1eb6ac0199 Introduce new approach for ios integration
* ruby scripts were refactored
* environment values are now exposed to Info.plist via xcconfig file
* environment values became available in Build Settings
* cocoapods integration fixed - no need to add custom code to Podfile!
(as suggested in this PR: https://github.com/luggit/react-native-config/pull/329)
2019-05-17 03:06:31 +03:00

31 lines
850 B
Ruby
Executable File

#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'ReadDotEnv'
envs_root = ARGV[0]
m_output_path = ARGV[1]
puts "reading env file from #{envs_root} and writing .m to #{m_output_path}"
# Allow utf-8 charactor in config value
# For example, APP_NAME=中文字符
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
dotenv, custom_env = read_dot_env(envs_root)
puts "read dotenv #{dotenv}"
# create obj file that sets DOT_ENV as a NSDictionary
dotenv_objc = dotenv.map { |k, v| %(@"#{k}":@"#{v.chomp}") }.join(',')
template = <<EOF
#define DOT_ENV @{ #{dotenv_objc} };
EOF
# write it so that ReactNativeConfig.m can return it
path = File.join(m_output_path, 'GeneratedDotEnv.m')
File.open(path, 'w') { |f| f.puts template }
File.delete('/tmp/envfile') if custom_env
puts "Wrote to #{path}"