#!/usr/bin/env ruby require 'salesforcedeploytool' # Disable stdout buffer STDOUT.sync = true # Static files CONFIG_DIR = File.expand_path '~/.sf' CONFIG_FILE = File.expand_path '~/.sf/credentials.yaml' GLOBAL_CONFIG_FILE = File.expand_path '~/.sf/salesforce.yaml' SANDBOX_CONFIG_FILE = File.expand_path '~/.sf/salesforce.sbox' # Create .sf dir if doesn't exists FileUtils.mkdir CONFIG_DIR if not Dir.exists? CONFIG_DIR # Load configurations config = {} [CONFIG_FILE,GLOBAL_CONFIG_FILE].each do |file| file = File.expand_path file if File.exists? file config_content = YAML::load(File.open(file).read) config.merge! config_content if config_content else FileUtils.touch file end end # Read sandbox environment begin config[:sandbox] = File.open(File.expand_path(SANDBOX_CONFIG_FILE)).read rescue end # Configuration variables firrst from ENV , if not config file # Git configs: config[:git_repo] = ENV["SFDT_GIT_REPO"] || config[:git_repo] config[:git_dir] = ENV["SFDT_GIT_DIR"] || config[:git_dir] config[:src_dir] = ENV["SFDT_SRC_DIR"] || config[:src_dir] # Salesforce credential configs config[:username] = ENV["SFDT_USERNAME"] || config[:username] config[:password] = ENV["SFDT_PASSWORD"] || config[:password] config[:salesforce_url] = ENV["SFDT_SALESFORCE_URL"] || config[:salesforce_url] config[:sandbox] = ENV['SFDT_SANDBOX'] || config[:sandbox] # Project configs config[:version_file] = ENV["SFDT_VERSION_FILE"] || config[:version_file] config[:build_number_pattern] = ENV["SFDT_BUILD_NUMBER_PATTERN"] || config[:build_number_pattern] config[:commit_hash_pattern] = ENV["SFDT_COMMIT_HASH_PATTERN"] || config[:commit_hash_pattern] config[:deploy_ignore_files] = ENV["SFDT_DEPLOY_IGNORE_FILES"].nil? ? config[:deploy_ignore_files] : ENV["SFDT_DEPLOY_IGNORE_FILES"].split(',') # Ant options config[:libant] = ENV["SFDT_ANT_LIB"] || config[:libant] # Minimal config validation abort "Config error: src_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_SRC_DIR" \ if config[:src_dir].nil? && !['-v'].include?(ARGV.first) abort "Config error: git_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" \ if config[:git_dir].nil? && !['-v'].include?(ARGV.first) abort "Config error: git_repo not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" \ if config[:git_repo].nil? && !['-v'].include?(ARGV.first) abort "Config error: username not found in #{GLOBAL_CONFIG_FILE} or through SFDT_USERNAME" \ if config[:username].nil? && !['config','-v'].include?(ARGV.first) abort "Config error: password not found in #{GLOBAL_CONFIG_FILE} or through SFDT_PASSWORD" \ if config[:password].nil? && !['config','-v'].include?(ARGV.first) # Create a temporary directory if SFDT_TMP_DIR is set, use that and don't delete it # This is to facilitate testinig and inspecting build.xml file if !ENV['SFDT_TMP_DIR'].nil? FileUtils.rm_rf ENV['SFDT_TMP_DIR'] FileUtils.mkdir ENV['SFDT_TMP_DIR'] end config[:tmp_dir] = ENV['SFDT_TMP_DIR'] || Dir.mktmpdir('sfdt-') begin SalesforceDeployTool::CLI.new.run config rescue => e puts "ERROR: #{e}" exit 1 ensure FileUtils.rm_rf config[:tmp_dir] if Dir.exists? config[:tmp_dir] unless ENV['SFDT_TMP_DIR'] end