Class: PlayerSDK::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/playersdk/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Compiler

Returns a new instance of Compiler.



5
6
7
8
9
# File 'lib/playersdk/compiler.rb', line 5

def initialize(config)
   self.config = config.clone
   
   self.compiler = PlayerSDK::Compilers::Flex.new(self.config);
end

Instance Attribute Details

#compilerObject

Returns the value of attribute compiler.



3
4
5
# File 'lib/playersdk/compiler.rb', line 3

def compiler
  @compiler
end

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/playersdk/compiler.rb', line 3

def config
  @config
end

#versionObject

Returns the value of attribute version.



3
4
5
# File 'lib/playersdk/compiler.rb', line 3

def version
  @version
end

Instance Method Details

#find_versionObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/playersdk/compiler.rb', line 44

def find_version
    if File.exists?("#{self.config['build_dir']}/version.properties")
      file = File.read("#{self.config['build_dir']}/version.properties")
    
      if (file == nil)
          puts "Something went wrong reading the file"
          return
      end
    
      version_s = ""
      file.scan(/version.([a-z]+) = ('?)([\w]+)('?)/i).each { |key, q1, value, q2|
          if value != ''
              if key == 'text'
                  version_s = version_s.slice(0, version_s.length - 1)
              end
            
              version_s += "#{value}."
          end
      }
    
      version_s = version_s.slice(0, version_s.length - 1)
    
      self.version = version_s
    
      puts "Using version #{self.version}"
     else
       puts "No version file found at #{self.config['build_dir']}/version.properties"
     end
end

#processObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/playersdk/compiler.rb', line 11

def process
    tasks = self.config['tasks']
    
    puts "Found #{tasks.length} task(s) to process"
    
    if tasks.length != 0
      # find the copy tasks
      tasks.each do |key,value|
          if value['type'] == 'copy'
              self.run_task(key, value)
          end
      end
    
      find_version
    
      if self.version != nil
        self.config['deployment_url'] = self.config['deployment_url'].gsub("%V", self.version)
    
        puts "Deployment url set to: #{self.config['deployment_url']}"
    
        tasks.each do |key,value|
            if value['type'] != 'copy'
               self.run_task(key, value)
           end
        end
      
        puts "\n\n"
     end
    
      puts "Completed #{tasks.length} tasks(s)"
    end
end

#run_task(key, value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/playersdk/compiler.rb', line 74

def run_task(key, value)
 if value['src'] != nil && value['src'] != ''
     puts "\nRunning task #{key} in #{value['src']}"
 else
     puts "\nRunning task #{key}"
 end
    
   case value['type']
       when "player"
           self.compiler.compile_mxmlc(value['src'], value['main'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
       when "engine"
           self.compiler.compile_compc(value['src'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
           
           puts "Optimizing engine swf .."
           
           optimize_target = value['optimize_target'] != '' ? value['optimize_target'] : value['target']
           
           self.compiler.optimize_swc(value['target'], optimize_target, self.config['build_dir'])
       when "addon"
           self.compiler.compile_mxmlc(value['src'], value['main'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
       when "framework"
           if value['target'] == nil || value['target'] == ""
               value['target'] = 'framework'
           end
       
           puts "Moving Flex framework RSLs to #{value['target']}"
           
           self.compiler.run_command("cp #{config['flex_sdk']}/frameworks/rsls/#{value['framework_rsl']}.swz #{config['build_dir']}/#{value['target']}.swz")
           self.compiler.run_command("cp #{config['flex_sdk']}/frameworks/rsls/#{value['framework_rsl']}.swf #{config['build_dir']}/#{value['target']}.swf")
           
           #self.compiler.run_command("chmod 644 #{config['build_dir']}/#{config['target']}.sw*")
       when "clean"
           puts "Cleaning directories ..."
           
           self.compiler.run_command("rm -rf #{config['build_dir']}/* #{config['tmp_dir']}/*")
       when "copy"
           puts "Copying over #{value['src']}"
           
           self.compiler.run_command("cp #{value['src']} #{config['build_dir']}/#{value['target']}")
       when ""
           puts "Unknown task type, skipping task ..\n"
           return
   end
   
   puts "\n"
   puts "Successfully compiled #{key} to target #{value['target']}.\n"      
end