lib/application.rb in docman-0.0.43 vs lib/application.rb in docman-0.0.44
- old
+ new
@@ -52,21 +52,23 @@
GitUtil.clone_repo(repo, 'config', 'branch', branch, true, 1)
#Dir.chdir File.join(name, 'config')
#`git checkout #{branch} & git branch -u origin #{branch}`
end
- def with_rescue
+ def with_rescue(write_to_file = true)
failed_filepath = File.join(@workspace_dir, 'failed')
if File.file?(failed_filepath)
log 'Last operation failed, forced rebuild mode'
FileUtils.rm_f failed_filepath
@force = true
end
yield
rescue Exception => e
log "Operation failed: #{e.message}", 'error'
- File.open(failed_filepath, 'w') {|f| f.write('Failed!') }
+ if write_to_file
+ File.open(failed_filepath, 'w') {|f| f.write(e.message) }
+ end
raise e
end
def build(deploy_target_name, state, options = false)
with_rescue do
@@ -94,10 +96,23 @@
end
end
result
end
+ def template(name, options = false)
+ with_rescue(false) do
+ @options = options
+ @docroot_config = DocrootConfig.new(@workspace_dir, nil)
+ project = @docroot_config.project(name)
+ unless project['template'].nil?
+ Dir.chdir project['full_build_path']
+ Exec.do "#{Application::bin}/project-template.sh #{project['template']}"
+ log "Project had been initialized with template: #{project['template']}"
+ end
+ end
+ end
+
def write_state state
filepath = File.join(@workspace_dir, 'state')
File.open(filepath, 'w') { |file| file.write(state) }
end
@@ -121,9 +136,13 @@
@force or @options[:force]
end
def self.root
Pathname(__FILE__).dirname.parent
+ end
+
+ def environment(name)
+ @config['environments'][name]
end
def self.bin
File.join root, 'bin'
end