#require 'dev_environment' #require_relative 'projects.rb' #require_relative 'project.rb' #class DevProjects #end require 'json' #require 'dev_commands' class Project < Hash attr_accessor :filename def initialize value='' @filename='' self[:url]='' self[:url] = value if value.is_a?(String) if(value.is_a?(Hash)) value.each{|k,v|self[k]=v} end end def name self[:name] end def get_latest_unique_id '51ed9c9d45ba3979c808740d75ba1831c85aff5d' end def wrk_dir "#{Environment.dev_root}/wrk/#{self.name}" end def pull if(File.exists?(wrk_dir) && File.exists?("#{wrk_dir}/.git")) Dir.chdir(wrk_dir) do puts "git pull (#{wrk_dir})" puts `git pull` end end end def clone if(!File.exists?(wrk_dir) && self[:url].include?('.git')) puts "cloning #{self[:url]} to #{self.wrk_dir}" puts `git clone #{self[:url]} #{self.wrk_dir}` end end def checkout if(!File.exists?(wrk_dir) && self[:url].include?('svn')) puts "checkout #{self.url} to #{self.wrk_dir}" puts `svn checkout #{self.url} #{self.wrk_dir}` end end def rake if(!File.exists?(self.wrk_dir)) clone checkout end if(File.exists?(self.wrk_dir)) Dir.chdir(self.wrk_dir) do rake = Command.new({ :input => 'rake', :timeout => 300, :ignore_failure => true }) rake.execute puts rake.summary end end end end require 'json' require 'rake' #require 'dev_git' #require 'dev_svn' #require 'dev_msbuild' #require 'dev_environment' class Projects < Hash attr_accessor :filename def initialize @filename='' end def update self.each{|k,v| self[k]=Project.new(v) if(v.is_a?(String)) self[k]=Project.new(v) if(!v.is_a?(Project) && v.is_a?(Hash)) self[k][:name]=k #self[k].update if self[k].respond_to?("update".to_sym) } end def save filename='' @filename=filename if !filename.nil? && filename.length > 0 File.open(@filename,'w'){|f|f.write(JSON.pretty_generate(self))} if @filename.length > 0 end def open filename='' @filename=filename if filename.length > 0 JSON.parse(IO.read(@filename)).each{|k,v| self[k]=v} update end def self.user_projects_filename FileUtils.mkdir("#{Environment.dev_root}/data") if(!File.exists?("#{Environment.dev_root}/data")) "#{Environment.dev_root}/data/PROJECTS.json" end def self.current project=nil url=Git.remote_origin url=Svn.url if url.length==0 if(Rake.application.original_dir.include?('/wrk/') && url.length > 0) project=Project.new(url) name=Rake.application.original_dir.gsub("#{Environment.dev_root}/wrk/",'') project[:name] = name if(name.length>0 && !name.include?(Environment.dev_root)) if(defined?(PROJECTS)) PROJECTS[name]=project if(!PROJECTS.has_key?(name)) project.each{|k,v|PROJECTS[name][k]=v} PROJECTS.save else project[:name]=name end end project end def pull self.each{|k,v| v.pull if v.respond_to?("pull".to_sym)} end def rake self.each{|k,v| v.rake if v.respond_to?("rake".to_sym)} end end PROJECTS=Projects.new PROJECTS.open Projects.user_projects_filename if File.exists? Projects.user_projects_filename PROJECTS.save Projects.user_projects_filename if !File.exists? Projects.user_projects_filename