Skip to content

Instantly share code, notes, and snippets.

@jkeam
Last active August 1, 2017 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkeam/1136185d2ce39649751c4fb10288773a to your computer and use it in GitHub Desktop.
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.
#!/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
@jkeam
Copy link
Author

jkeam commented Aug 1, 2017

Usage:
./replace_url.rb [EXPO SERVER URL]

Example Usage:
./replace_url.rb expMqNAvBkGAAgkAWARazDJsNL3dCK9Lrru://192.168.1.2:19000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment