lib/docman/docroot_config.rb in docman-0.0.81 vs lib/docman/docroot_config.rb in docman-0.0.82

- old
+ new

@@ -1,13 +1,14 @@ +require 'application' require 'fileutils' require 'docman/info' module Docman class DocrootConfig - attr_reader :structure, :deploy_target, :docroot_dir, :root, :raw_infos + attr_reader :structure, :deploy_target, :docroot_dir, :docroot_config_dir, :config_dir, :root, :raw_infos def initialize(docroot_dir, deploy_target_name = nil, options = nil) @override = {} if options && options['config'] @override = JSON.parse(options['config']) @@ -15,15 +16,23 @@ @docroot_dir = docroot_dir #@deploy_target = deploy_target @docroot_config_dir = File.join(docroot_dir, 'config') Dir.chdir @docroot_config_dir - update(' origin master') - if File.file? File.join(@docroot_config_dir, 'config.yaml') - Docman::Application.instance.config.merge_config_from_file(@docroot_config_dir, 'config.yaml', options) - end + update('origin') + config_files = Docman::Application.instance.config_dirs(options).collect{|item| + File.join(@docroot_config_dir, item, 'config.{yaml,yml}') + } + config_file_path = Dir.glob(config_files).first + raise "Configuration file config.{yaml,yml} not found." if config_file_path.nil? + + @config_dir = File.dirname(config_file_path) + @config_file = File.basename(config_file_path) + + Docman::Application.instance.config.merge_config_from_file(docroot_dir, @config_dir, @config_file, options) + if deploy_target_name @deploy_target = Application.instance.config['deploy_targets'][deploy_target_name] raise "Wrong deploy target: #{deploy_target_name}" if @deploy_target.nil? @deploy_target['name'] = deploy_target_name end @@ -37,12 +46,14 @@ @structure = structure_build_from_config_file(File.join(@docroot_config_dir, 'master')) end end def update(options = '') + Dir.chdir @docroot_config_dir GitUtil.exec("reset --hard", false) - GitUtil.update @docroot_config_dir, options + branch = GitUtil.branch + GitUtil.update @docroot_config_dir, "#{options} #{branch.strip}" end def structure_build_from_config_file(path, prefix = '', parent = nil, parent_key = 'master') config = Docman::Application.instance.config return if config['components'][parent_key].nil? @@ -58,13 +69,13 @@ name = parent_key prefix = prefix.size > 0 ? File.join(prefix, name) : name info['full_path'] = path info['docroot_config'] = self info['build_path'] = prefix - info['full_build_path'] = File.join(@docroot_dir, prefix) - info['temp_path'] = File.join(@docroot_dir, 'tmp', info['build_path']) - info['states_path'] = File.join(@docroot_dir, 'states', info['build_path']) + info['full_build_path'] = File.join(@docroot_dir, '.docman', prefix) + info['temp_path'] = File.join(@docroot_dir, '.docman/tmp', info['build_path']) + info['states_path'] = File.join(@docroot_dir, '.docman/states', info['build_path']) info['name'] = name info['parent'] = parent info['order'] = info.has_key?('order') ? info['order'] : 10 info['children'] = children @@ -103,13 +114,13 @@ name = File.basename path prefix = prefix.size > 0 ? File.join(prefix, name) : name info['full_path'] = path info['docroot_config'] = self info['build_path'] = prefix - info['full_build_path'] = File.join(@docroot_dir, prefix) - info['temp_path'] = File.join(@docroot_dir, 'tmp', info['build_path']) - info['states_path'] = File.join(@docroot_dir, 'states', info['build_path']) + info['full_build_path'] = File.join(@docroot_dir, '.docman', prefix) + info['temp_path'] = File.join(@docroot_dir, '.docman/tmp', info['build_path']) + info['states_path'] = File.join(@docroot_dir, '.docman/states', info['build_path']) info['name'] = name info['parent'] = parent info['order'] = info.has_key?('order') ? info['order'] : 10 info['children'] = children @@ -170,6 +181,6 @@ def deploy_target_name @deploy_target.name end end -end \ No newline at end of file +end