bin/sf in salesforce-deploy-tool-1.2.0 vs bin/sf in salesforce-deploy-tool-1.3.0

- old
+ new

@@ -25,49 +25,47 @@ else FileUtils.touch file end end +# Read sandbox environment +begin + sandbox = File.open(File.expand_path(SANDBOX_CONFIG_FILE)).read +rescue + sandbox = nil +end + # Grab variables from env if not in the config files config[:git_dir] = ENV["SFDT_GIT_DIR"] || config[:git_dir] config[:tmp_dir] = ENV["SFDT_TMP_DIR"] || config[:tmp_dir] 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[:git_repo] = ENV["SFDT_GIT_REPO"] || config[:git_repo] 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[:deploy_ignore_files] = ENV["SFDT_DEPLOY_IGNORE_FILES"].nil? ? config[:deploy_ignore_files] : ENV["SFDT_DEPLOY_IGNORE_FILES"].split(',') -# The salesforce URL, first from environment varialbes, second from config file , thierd defaults: -config[:salesforce_url] = ENV["SFDT_SALESFORCE_URL"] || config[:salesforce_url] ||( @sandbox == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) - # Default values config[:buildxml_dir] = ENV["SFDT_BUILDXML_DIR"] || config[:buildxml_dir] || '' # Minimal config validation abort "Config error: git_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" if config[:git_dir].nil? abort "Config error: tmp_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_TMP_DIR" if config[:tmp_dir].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' # If the repository is not cloned then fail: -if !File.exists?(config[:git_dir]) && ARGV[0] != 'config' +if !File.exists?(config[:git_dir]) && ['pull','push'].include?(ARGV[0]) abort "ERROR: The environment is not properly configured, please run sf config to clone the repo and setup the credentials" end # Normalize file paths: config[:git_dir] = File.expand_path config[:git_dir] config[:tmp_dir] = File.expand_path config[:tmp_dir] -# Read sandbox environment -begin - sandbox = File.open(File.expand_path(SANDBOX_CONFIG_FILE)).read -rescue - sandbox = nil -end - require 'salesforcedeploytool' program :version, SalesforceDeployTool::VERSION program :description, 'A cli tool to help manage and deploy salesforce sandboxes with git' @@ -90,18 +88,26 @@ exit 1 end config[:sandbox] = options.sandbox || sandbox config[:debug] = options.debug.nil? ? false : true + # The salesforce URL + config[:salesforce_url] = + ENV["SFDT_SALESFORCE_URL"] || # First from environment variables + config[:salesforce_url] || # Second from the configuration files + ( config[:sandbox] == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) # If not defined anywhere, use defaults + # Initialize sfdt = SalesforceDeployTool::App.new config # Clean all files from repo sfdt.clean_git_dir unless options.append # Pull the changes - sfdt.pull "INFO: Pulling changes from #{config[:sandbox]} " + print "INFO: Pulling changes from #{config[:sandbox]} using url #{config[:salesforce_url]} " + print "\n\n" if options.debug + sfdt.pull sfdt.clean_version end end @@ -131,10 +137,16 @@ end config[:sandbox] = options.sandbox || sandbox config[:test] = options.test.nil? ? false : true config[:debug] = options.debug.nil? ? false : true + # The salesforce URL + config[:salesforce_url] = + ENV["SFDT_SALESFORCE_URL"] || # First from environment variables + config[:salesforce_url] || # Second from the configuration files + ( config[:sandbox] == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) # If not defined anywhere, use defaults + # Initialize sfdt = SalesforceDeployTool::App.new config.clone # Remove destructive change if there is one DESTRUCTIVE_CHANGE_FILE = File.join(config[:git_dir],config[:buildxml_dir],'src','destructiveChanges.xml') @@ -145,11 +157,12 @@ config_tmp = config.clone config_tmp[:git_dir] = config_tmp[:tmp_dir] FileUtils.rm_rf config_tmp[:git_dir] if File.exists? config_tmp[:git_dir] FileUtils.cp_r config[:git_dir],config_tmp[:git_dir] sfdt_tmp = SalesforceDeployTool::App.new config_tmp - sfdt_tmp.pull "INFO: Pulling changes from #{config[:sandbox]} to temporary directory #{config[:tmp_dir]} to generate destructiveChanges.xml " + print "INFO: Pulling changes from #{config[:sandbox]} using url #{config[:salesforce_url]} to temporary directory #{config[:tmp_dir]} to generate destructiveChanges.xml " + sfdt_tmp.pull # Create destructiveChanges.xml puts "INFO: Creating destructive changes xml" dc_gen = Dcgen::App.new dc_gen.master = File.join(config[:git_dir],config[:buildxml_dir],'src') @@ -169,9 +182,10 @@ # Enable test if option enabled sfdt.test = options.test.nil? ? false : true # Push + print(options.test.nil? ? "INFO: Deploying code to #{config[:sandbox]}: ": "INFO: Deploying and Testing code to #{config[:sandbox]}: \n\n") sfdt.push ensure sfdt.clean_version end