From 46b7f9401c35d0aec27ff4def53bbfa1aefd2536 Mon Sep 17 00:00:00 2001 From: Ben Yorke Date: Wed, 21 Jun 2017 01:14:38 +0100 Subject: [PATCH] Allow exported variables in .env (#116) --- android/dotenv.gradle | 2 +- ios/ReactNativeConfig/BuildDotenvConfig.ruby | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/dotenv.gradle b/android/dotenv.gradle index 78d72403..ed48b556 100644 --- a/android/dotenv.gradle +++ b/android/dotenv.gradle @@ -46,7 +46,7 @@ def readDotEnv = { println("Reading env from: $envFile") try { new File("$project.rootDir/../$envFile").eachLine { line -> - def matcher = (line =~ /^\s*([\w\d\.\-_]+)\s*=\s*(.*)?\s*$/) + def matcher = (line =~ /^\s*(?:export\s+|)([\w\d\.\-_]+)\s*=\s*['"]?(.*)?['"]?\s*$/) if (matcher.getCount() == 1 && matcher[0].size() == 3){ env.put(matcher[0][1], matcher[0][2]) } diff --git a/ios/ReactNativeConfig/BuildDotenvConfig.ruby b/ios/ReactNativeConfig/BuildDotenvConfig.ruby index f443bfd9..c7438743 100755 --- a/ios/ReactNativeConfig/BuildDotenvConfig.ruby +++ b/ios/ReactNativeConfig/BuildDotenvConfig.ruby @@ -14,8 +14,8 @@ end puts "Reading env from #{file}" dotenv = begin - # https://regex101.com/r/SLdbes/1 - dotenv_pattern = /^(?[[:alnum:]_]+)=((?["'])?(?.*?[^\\])\k?|)$/ + # https://regex101.com/r/aFZMSB + dotenv_pattern = /^(?:export\s+|)(?[[:alnum:]_]+)=((?["'])?(?.*?[^\\])\k?|)$/ # find that above node_modules/react-native-config/ios/ raw = File.read(File.join(Dir.pwd, "../../../#{file}")) raw.split("\n").inject({}) do |h, line|