Sha256: 37be2c24b01ee5a78ebd53a1019847db680e75e8caf837a080027e657edc720d

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

require 'json'

def each_step(json, type)
  json['workflows'].map{|w| w["steps"].select {|s| s["type"] == type.to_s}}.flatten.each do |step|
    yield(step)
  end
end

def replace_oauth(app_json)
  client_id = ENV["CLIENT_ID"]
  client_secret = ENV["CLIENT_SECRET"]
  redirect_scheme = ENV["SCHEME"]
  
  each_step(app_json, :networkOAuth2) do |step|
    step["items"].each do |item|
      if item["oAuth2ClientId"]
        item["oAuth2ClientId"] = client_id
        item["oAuth2ClientSecret"] = client_secret
        item["oAuth2RedirectScheme"] = redirect_scheme
      end      
    end
  end  
end

def replace_servers(app_json)
  server_url = ENV["SERVER_URL"]
  base_url = ENV["PREVIOUS_SERVER_URL"]
  
  app_json["servers"].each do |server|
    server["url"] = server_url
  end

  each_step(app_json, :display) do |step|
    step["items"].each do |item|
      ["appleSystemURL", "androidDeepLink"].each{|key| item[key] = item[key].gsub(base_url, server_url) }
    end
  end
end

def env_set(path)
  app_json = JSON.parse(File.read(app_json_path))
  replace_oauth(app_json)
  replace_servers(app_json)
  File.write(app_json_path, app_json.to_json)  
end

namespace :mw do
  namespace :set_env do
    desc 'Update Android app.json to use new env'
    task :android do
      env_set(File.join('app', 'src', 'main', 'res', 'raw', 'app.json'))
    end
  
    desc 'Update iOS app.json to use new env'
    task :ios do
      project_name = ENV["PROJECT_NAME"]
      env_set(File.join(project_name, project_name, "Resources", "app.json"))
    end
  end  
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mobile_workflow-0.10.2 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.10.1 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.10.0 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.9.0 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.8.9 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.9 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.8 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.7 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.6 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.5 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.4 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.3 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.2 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.1 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.7.0 lib/mobile_workflow/tasks/set_env.rake
mobile_workflow-0.6.31 lib/mobile_workflow/tasks/set_env.rake