class Object
Constants
- MD5_COMMMAND
Public Instance Methods
bundle()
click to toggle source
# File lib/bundle.rb, line 5 def bundle # bundlePath = ARGV[0] # output_dir = ARGV[1] options = {} opts = OptionParser.new do |opts| opts.banner ="Usage: " opts.on( "-c", "--config CONFIG", "Path to your config file" ) do |path| options[:bundle_config_path] = path end opts.on("-o", "--output BUNDLE_DIR", "Directory you would like bundle to go to") do |path| options[:bundle_dir] = path end opts.on("-m", "--manifest MANIFEST_DIR", "Directory you would like the manifest to go to") do |path| options[:manifest_output_dir] = path end opts.on("--no-manifest" "Do not generate a manifest or fuller_asset_list") do |value| options[:no_manifest] = true end end opts.parse! bundle_config_path = options[:bundle_config_path] || spaceport_options[:bundle_config_path] bundle_dir = options[:bundle_dir] || spaceport_options[:bundle_dir] manifest_output_dir = options[:manifest_output_dir] || spaceport_options[:manifest_output_dir] if ( !bundle_dir || !manifest_output_dir || !bundle_config_path) bundle_config_path = ARGV[0] manifest_output_dir = ARGV[1] bundle_dir = ARGV[2] puts "You are using this in the deprecated way! Please do not" exit end current_dir = File.expand_path(File.dirname(__FILE__)) built_client_dir = File.join(bundle_dir, "built_client", "assets") manifest_generating_script_path = File.join(current_dir, "generate_manifest.rb") full_asset_list_path = File.join(manifest_output_dir, "full_asset_list.txt") manifest_path = File.join(manifest_output_dir, "manifest.xml") if ( !options[:no_manifest] ) puts `spaceport generate_manifest --config #{bundle_config_path} --output #{manifest_output_dir}` end `rm -rf #{built_client_dir}` `mkdir -p #{built_client_dir}` `rsync -rvmL --exclude='#{built_client_dir}/*' --include-from=#{full_asset_list_path} --include='*/' --exclude='*' #{manifest_output_dir}/ #{built_client_dir}` `cp #{manifest_path} #{built_client_dir}` # TODO: # Zip stuff up for Android #( cd built_client && zip -r built_client.zip *.js content *.html manifest.xml ) #cp built_client/built_client.zip $DESTINATION #echo "copying built_client.zip to $DESTINATION" end
generate_manifest()
click to toggle source
# File lib/generate_manifest.rb, line 10 def generate_manifest # bundlePath = ARGV[0] # output_dir = ARGV[1] options = {} opts = OptionParser.new do |opts| opts.banner ="Usage: This will create two output files; a manifest.xml, and a full_asset_list.txt" opts.on( "-c", "--config CONFIG", "Path to your config file" ) do |path| options[:bundle_config_path] = path end opts.on("-o", "--output OUTPUT", "Directory you would like the two output files to go to") do |path| options[:manifest_output_dir] = path end end opts.parse! bundlePath = options[:bundle_config_path] || spaceport_options[:bundle_config_path] output_dir = options[:manifest_output_dir] || spaceport_options[:manifest_output_dir] app_root_dir = output_dir if ( !bundlePath || !output_dir ) puts opts exit end wants = [] doNotWants = [] completeFileList = {} File.open(bundlePath, "r") do |f| while !f.eof? line = f.readline matchData = /^\s#(.*)$/.match(line) if matchData next end matchData = /^\s*$/.match(line) if( matchData ) next end matchData = /^-([^\s]*)/.match(line) if matchData doNotWants.push( {:path => matchData[1]}) next; end matchData = /^([^\s]*)[\s]*([^\s]*)/.match(line) if( matchData ) wants.push( {:path => matchData[1], :version => matchData[2]}) end end end original_dir = Dir.pwd Dir.chdir( app_root_dir ) wants.each do |w| Dir.glob( w[:path] ) do |filename| next if File.directory?(filename) completeFileList[filename] = w[:version] end end doNotWants.each do |d| Dir.glob( d[:path] ) do |filename| next if File.directory?(filename) completeFileList.delete( filename ) end end file_list=completeFileList.keys.sort def get_cksum( filename ) if MD5_COMMMAND=="md5" `#{MD5_COMMMAND} #{filename} | awk '-F= ' '{ print $2 }'`.strip elsif MD5_COMMMAND=="md5sum" `#{MD5_COMMMAND} #{filename}`.split(" ")[0].strip end end def get_svn_revision( filename ) `svn info -- '#{filename}' | grep "Last Changed Rev" | awk '-F: ' '{ print $2 }'`.strip end def get_git_revision( filename ) `git log --format=%h -1 -- #{filename}`.strip end def get_version(filename, version_type) if ( version_type == 'svn') get_svn_revision( filename ) elsif ( version_type == 'git') get_git_revision( filename ) elsif( version_type=='md5') get_cksum( filename ) else raise "version scheme: \"#{version_type}\" specified for filename: \"#{filename}\" is invalid." end end file_list = file_list.map do |filename| version = get_version( filename, completeFileList[filename] ) if !version || version == "" puts "#{filename} is unversioned" nil else {:version => version, :name => filename, :filesize => File.size( filename ) } end end.compact def get_total_size( file_list ) total_size = file_list.inject(0){|sum,x| sum + x[:filesize].to_i} puts (total_size / 1024).to_s + " KB" puts (total_size / (1024*1024)).to_s + " MB" total_size end def print_size_information( file_list ) file_extensions ={} file_list.each do |a| ext = File.extname( a[:name] ) file_extensions[ ext ] = file_extensions[ ext ] || [] file_extensions[ext].push(a) end file_extensions.keys.each do |ext| puts ext get_total_size( file_extensions[ ext] ) puts "" end puts "Total" total_file_size = get_total_size( file_list )/( 1024 * 1024 ); puts "" file_sizes_hsh = {} file_extensions.keys.each do |ext| file_size = get_total_size( file_extensions[ ext] )/(1024*1024) file_sizes_hsh[ ext + "(" + file_size.to_s + "MB)"] = file_size end puts "http://chart.apis.google.com/chart?chs=800x225&cht=p&chd=t:#{file_sizes_hsh.values.join(',')}&chdl=#{file_sizes_hsh.keys.join('|')}&chl=#{file_sizes_hsh.keys.join('|')}&chtt=Disk+Usage(#{total_file_size}+MB)" end def generate_manifest_3_3( file_list ) prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="THIS_DOES_NOTHING" platform="3.3"> eos plugins = <<-eos <plugins> <entry id="io.spaceport.plugins.chartboost" version="3.3.0"/> <entry id="io.spaceport.plugins.facebook" version="3.3.0"/> <entry id="io.spaceport.plugins.flurry" version="3.3.0"/> <entry id="io.spaceport.plugins.localnotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.mail" version="3.3.0"/> <entry id="io.spaceport.plugins.market" version="3.3.0"/> <entry id="io.spaceport.plugins.remotenotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.sms" version="3.3.0"/> <entry id="io.spaceport.plugins.tapjoy" version="3.3.0"/> <entry id="io.spaceport.plugins.twitter" version="3.3.0"/> <entry id="io.spaceport.plugins.particle" version="3.3.0"/> </plugins> eos xml_file_list = file_list.map do |_value| value = _value.dup value[:id] = value[:name] value.delete(:name) "\t<entry " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end startup = <<-eos <startup> #{xml_file_list.join("\n")} </startup> eos suffix = <<-eos <code></code> <assets></assets> </manifest> eos output = prefix + plugins + startup + suffix end def generate_manifest_3_02( file_list ) xml_file_list = file_list.map do |value| "\t<file " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="3.02"> <files> eos suffix = <<-eos </files> </manifest> eos output = prefix + xml_file_list.join("\n") + suffix output end print_size_information( file_list ) output = generate_manifest_3_3( file_list ) Dir.chdir( original_dir ) File.open( File.join(output_dir, "manifest.xml"), 'w' ) do |file| file.write( output ) end asset_file_name = File.join( output_dir, "full_asset_list.txt" ) File.open( asset_file_name , 'w' ) do |file| file.write( file_list.map{|k| k[:name] }.map do |k| if k[0,2] == "./" k[2, k.length - 1] else k end end.join("\n") ) end end
generate_manifest_3_02( file_list )
click to toggle source
# File lib/generate_manifest.rb, line 218 def generate_manifest_3_02( file_list ) xml_file_list = file_list.map do |value| "\t<file " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="3.02"> <files> eos suffix = <<-eos </files> </manifest> eos output = prefix + xml_file_list.join("\n") + suffix output end
generate_manifest_3_3( file_list )
click to toggle source
# File lib/generate_manifest.rb, line 174 def generate_manifest_3_3( file_list ) prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="THIS_DOES_NOTHING" platform="3.3"> eos plugins = <<-eos <plugins> <entry id="io.spaceport.plugins.chartboost" version="3.3.0"/> <entry id="io.spaceport.plugins.facebook" version="3.3.0"/> <entry id="io.spaceport.plugins.flurry" version="3.3.0"/> <entry id="io.spaceport.plugins.localnotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.mail" version="3.3.0"/> <entry id="io.spaceport.plugins.market" version="3.3.0"/> <entry id="io.spaceport.plugins.remotenotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.sms" version="3.3.0"/> <entry id="io.spaceport.plugins.tapjoy" version="3.3.0"/> <entry id="io.spaceport.plugins.twitter" version="3.3.0"/> <entry id="io.spaceport.plugins.particle" version="3.3.0"/> </plugins> eos xml_file_list = file_list.map do |_value| value = _value.dup value[:id] = value[:name] value.delete(:name) "\t<entry " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end startup = <<-eos <startup> #{xml_file_list.join("\n")} </startup> eos suffix = <<-eos <code></code> <assets></assets> </manifest> eos output = prefix + plugins + startup + suffix end
get_cksum( filename )
click to toggle source
# File lib/generate_manifest.rb, line 94 def get_cksum( filename ) if MD5_COMMMAND=="md5" `#{MD5_COMMMAND} #{filename} | awk '-F= ' '{ print $2 }'`.strip elsif MD5_COMMMAND=="md5sum" `#{MD5_COMMMAND} #{filename}`.split(" ")[0].strip end end
get_git_revision( filename )
click to toggle source
# File lib/generate_manifest.rb, line 106 def get_git_revision( filename ) `git log --format=%h -1 -- #{filename}`.strip end
get_spaceport_options()
click to toggle source
# File lib/lib.rb, line 3 def get_spaceport_options if File.exists?(".spaceport") opts = JSON.parse( File.open( ".spaceport", "r" ).read ) out = {} opts.each do |k,v| out[k] = v out[k.intern] = v end return out else return {} end end
get_svn_revision( filename )
click to toggle source
# File lib/generate_manifest.rb, line 102 def get_svn_revision( filename ) `svn info -- '#{filename}' | grep "Last Changed Rev" | awk '-F: ' '{ print $2 }'`.strip end
get_total_size( file_list )
click to toggle source
# File lib/generate_manifest.rb, line 135 def get_total_size( file_list ) total_size = file_list.inject(0){|sum,x| sum + x[:filesize].to_i} puts (total_size / 1024).to_s + " KB" puts (total_size / (1024*1024)).to_s + " MB" total_size end
get_version(filename, version_type)
click to toggle source
# File lib/generate_manifest.rb, line 111 def get_version(filename, version_type) if ( version_type == 'svn') get_svn_revision( filename ) elsif ( version_type == 'git') get_git_revision( filename ) elsif( version_type=='md5') get_cksum( filename ) else raise "version scheme: \"#{version_type}\" specified for filename: \"#{filename}\" is invalid." end end
print_size_information( file_list )
click to toggle source
# File lib/generate_manifest.rb, line 143 def print_size_information( file_list ) file_extensions ={} file_list.each do |a| ext = File.extname( a[:name] ) file_extensions[ ext ] = file_extensions[ ext ] || [] file_extensions[ext].push(a) end file_extensions.keys.each do |ext| puts ext get_total_size( file_extensions[ ext] ) puts "" end puts "Total" total_file_size = get_total_size( file_list )/( 1024 * 1024 ); puts "" file_sizes_hsh = {} file_extensions.keys.each do |ext| file_size = get_total_size( file_extensions[ ext] )/(1024*1024) file_sizes_hsh[ ext + "(" + file_size.to_s + "MB)"] = file_size end puts "http://chart.apis.google.com/chart?chs=800x225&cht=p&chd=t:#{file_sizes_hsh.values.join(',')}&chdl=#{file_sizes_hsh.keys.join('|')}&chl=#{file_sizes_hsh.keys.join('|')}&chtt=Disk+Usage(#{total_file_size}+MB)" end
spaceport_options()
click to toggle source
# File lib/lib.rb, line 18 def spaceport_options() get_spaceport_options() end