Sha256: b74acd04bd3e30fdcf48185a28ff03bb5061da7f8f519dadf0a8aa87e7576baf

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 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 :env_set 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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mobile_workflow-0.6.30 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.29 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.28 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.27 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.26 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.25 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.24 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.23 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.22 lib/mobile_workflow/tasks/env_set.rake
mobile_workflow-0.6.21 lib/mobile_workflow/tasks/env_set.rake