#!/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 config[:sandbox] = nil 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] # 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(',') # Minimal config validation abort "Config error: src_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_SRC_DIR" if config[:src_dir].nil? abort "Config error: git_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" if config[:git_dir].nil? abort "Config error: git_repo not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" if config[:git_repo].nil? abort "Config error: username not found in #{GLOBAL_CONFIG_FILE} or through SFDT_USERNAME" if config[:username].nil? && ARGV[0] != 'config' abort "Config error: password not found in #{GLOBAL_CONFIG_FILE} or through SFDT_PASSWORD" if config[:password].nil? && ARGV[0] != 'config' # Create a temporary directory config[: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] end