-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #329)
- Loading branch information
1 parent
7390b74
commit 1eb6ac0
Showing
10 changed files
with
164 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/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}" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative 'ReadDotEnv' | ||
|
||
envs_root = ARGV[0] | ||
config_output = ARGV[1] | ||
puts "reading env file from #{envs_root} and writing .config to #{config_output}" | ||
|
||
dotenv, custom_env = read_dot_env(envs_root) | ||
|
||
dotenv_xcconfig = dotenv.map { |k, v| %(#{k}=#{v}) }.join("\n") | ||
File.open(config_output, 'w') { |f| f.puts dotenv_xcconfig } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# Allow utf-8 charactor in config value | ||
# For example, APP_NAME=中文字符 | ||
Encoding.default_external = Encoding::UTF_8 | ||
Encoding.default_internal = Encoding::UTF_8 | ||
|
||
# TODO: introduce a parameter which controls how to build relative path | ||
def read_dot_env(envs_root) | ||
defaultEnvFile = '.env' | ||
puts "going to read env file from root folder #{envs_root}" | ||
|
||
# pick a custom env file if set | ||
if File.exist?('/tmp/envfile') | ||
custom_env = true | ||
file = File.read('/tmp/envfile').strip | ||
else | ||
custom_env = false | ||
file = ENV['ENVFILE'] || defaultEnvFile | ||
end | ||
|
||
dotenv = begin | ||
# https://regex101.com/r/cbm5Tp/1 | ||
dotenv_pattern = /^(?:export\s+|)(?<key>[[:alnum:]_]+)=((?<quote>["'])?(?<val>.*?[^\\])\k<quote>?|)$/ | ||
|
||
path = File.expand_path(File.join(envs_root, file.to_s)) | ||
if File.exist?(path) | ||
raw = File.read(path) | ||
elsif File.exist?(file) | ||
raw = File.read(file) | ||
else | ||
defaultEnvPath = File.expand_path(File.join(envs_root, "../#{defaultEnvFile}")) | ||
unless File.exist?(defaultEnvPath) | ||
# try as absolute path | ||
defaultEnvPath = defaultEnvFile | ||
end | ||
defaultRaw = File.read(defaultEnvPath) | ||
raw = defaultRaw + "\n" + raw if defaultRaw | ||
end | ||
|
||
raw.split("\n").inject({}) do |h, line| | ||
m = line.match(dotenv_pattern) | ||
next h if m.nil? | ||
|
||
key = m[:key] | ||
# Ensure string (in case of empty value) and escape any quotes present in the value. | ||
val = m[:val].to_s.gsub('"', '\"') | ||
h.merge(key => val) | ||
end | ||
rescue Errno::ENOENT | ||
puts('**************************') | ||
puts('*** Missing .env file ****') | ||
puts('**************************') | ||
return [{}, false] # set dotenv as an empty hash | ||
end | ||
[dotenv, custom_env] | ||
end |
Oops, something went wrong.