bin/sf in salesforce-deploy-tool-0.8.2 vs bin/sf in salesforce-deploy-tool-0.9.0
- old
+ new
@@ -1,15 +1,17 @@
#!/usr/bin/env ruby
-require 'yaml'
-require 'fileutils'
require 'pp'
+require 'yaml'
CONFIG_DIR = '~/.sf'
CONFIG_FILE = '~/.sf/credentials.yaml'
GLOBAL_CONFIG_FILE = '~/.sf/salesforce.yaml'
SANDBOX_CONFIG_FILE = '~/.sf/salesforce.sbox'
+# Load configurations, if directories and files don't
+# exists, create them empty
+
FileUtils.mkdir File.expand_path CONFIG_DIR if not Dir.exists? File.expand_path CONFIG_DIR
config = {}
[CONFIG_FILE,GLOBAL_CONFIG_FILE].each do |file|
file = File.expand_path file
@@ -19,10 +21,23 @@
else
FileUtils.touch file
end
end
+# Grab variables from env if not in the config files
+config[:git_dir] = ENV["GIT_DIR"] || config[:git_dir]
+config[:tmp_dir] = ENV["TMP_DIR"] || config[:tmp_dir]
+config[:version_file] = ENV["VERSION_FILE"] || config[:version_file]
+config[:build_number_pattern] = ENV["BUILD_NUMBER_PATTERN"] || config[:build_number_pattern]
+config[:commit_hash_pattern] = ENV["COMMIT_HASH_PATTERN"] || config[:commit_hash_pattern]
+config[:git_repo] = ENV["GIT_REPO"] || config[:git_repo]
+config[:deploy_ignore_files] = ENV["DEPLOY_IGNORE_FILES"].split(',') || config[:deploy_ignore_files]
+config[:username] = ENV["USERNAME"] || config[:username]
+config[:password] = ENV["PASSWORD"] || config[:password]
+
+# Read sandbox environment
+
begin
sandbox = File.open(File.expand_path(SANDBOX_CONFIG_FILE)).read
rescue
sandbox = nil
end
@@ -118,13 +133,23 @@
end
config[:sandbox] = options.sandbox || sandbox
config[:debug] = options.debug.nil? ? false : true
config[:test] = options.test.nil? ? false : true
+ # Parameter Normalization
+ config[:git_dir] = File.expand_path config[:git_dir]
+ config[:tmp_dir] = File.expand_path config[:tmp_dir]
+ config[:version_file] = File.expand_path config[:version_file]
+ config[:deploy_ignore_files].map! {|f| File.expand_path File.join(config[:git_dir],f)}
+
# Initialize
sfdt = SalesforceDeployTool::App.new config
+ # Remove destructive change if there is one
+ DESTRUCTIVE_CHANGE_FILE = File.join(config[:git_dir],'src','destructiveChanges.xml')
+ FileUtils.rm DESTRUCTIVE_CHANGE_FILE if File.exists? DESTRUCTIVE_CHANGE_FILE
+
# Push the code without destructiveChanges.xml. This step is allways necessary
# even when it is a destructive change. This is because if a class is referencing
# a field to be deleted, then we first need to push the class to remove that
# reference and only then SF will allow us to remove the field on the second
# push
@@ -144,10 +169,10 @@
# Create destructiveChanges.xml
puts "INFO: Creating destructive changes xml"
dc_gen = Dcgen::App.new
dc_gen.master = File.join(config[:git_dir],'src')
dc_gen.destination = File.join(config[:tmp_dir],'src')
- dc_gen.output = File.join(config[:git_dir],'src','destructiveChanges.xml')
+ dc_gen.output = DESTRUCTIVE_CHANGE_FILE
dc_gen.exclude = options.exclude.split(',') unless options.exclude.nil?
# Capture stdout when running generate_destructive_Changes, TODO: fix dcgen
stringio = StringIO.new
stdout_tmp = $stdout