Last active
August 1, 2017 06:54
-
-
Save jkeam/1136185d2ce39649751c4fb10288773a to your computer and use it in GitHub Desktop.
Ruby script to update expo config files that need to be updated as you change networks. This script will update the urls expo is using to serve up the JS resources. This configs should be auto updated during the build process, but for some reason it sometimes does not work. Running this script will fix those urls.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'rexml/document' | |
include REXML | |
def fix_exshell_json(filename, url) | |
json_file = JSON.parse File.read(filename) | |
json_file['developmentUrl'] = url | |
File.open(filename, 'w') { |file| file.puts(json_file.to_json) } | |
end | |
def fix_exshell_xml(filename, url) | |
doc = Document.new File.read(filename) | |
elements = doc.root.elements[1].elements['string'] | |
elements.text = url | |
File.open(filename, 'w') { |file| doc.write(file) } | |
end | |
def fix_exshells(url) | |
fix_exshell_xml './ios/it-s-hospitality/Supporting/EXShell.plist', url | |
fix_exshell_xml './ios/it-s-hospitality/Supporting/EXShell.plist.bak', url | |
fix_exshell_json './ios/it-s-hospitality/Supporting/EXShell.json', url | |
end | |
# validate arg | |
new_url = ARGV[0] | |
unless new_url | |
puts "Missing Exp Url\nUsage: #{$0} [EXPO_URL]" | |
return | |
end | |
# main | |
fix_exshells new_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./replace_url.rb [EXPO SERVER URL]
Example Usage:
./replace_url.rb expMqNAvBkGAAgkAWARazDJsNL3dCK9Lrru://192.168.1.2:19000