Class: PlayerSDK::Compilers::Flex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Flex

Returns a new instance of Flex.



6
7
8
# File 'lib/playersdk/compilers/flex.rb', line 6

def initialize(config)
   self.config = config.clone
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/playersdk/compilers/flex.rb', line 4

def config
  @config
end

Instance Method Details

#compile_compc(source_path, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/playersdk/compilers/flex.rb', line 49

def compile_compc(source_path, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url)
    command = "#{executable('compc')} -source-path #{source_path} -include-sources #{source_path}"

    if include_sdk
        command += " -runtime-shared-library-path=#{config['flex_sdk']}/#{config['flex_framework_swc']},#{deployment_url}/framework.swz,#{config['crossdomain_url']}/crossdomain.xml,#{deployment_url}/framework.swf"
    end

    if include_engine
       command += " -runtime-shared-library-path=#{include_engine}.swc,#{deployment_url}/vj-player-engine.swf" 
    end

    if include_libs
       command += " -compiler.include-libraries #{include_libs}" 
    end

    command += " -use-network -benchmark -compiler.strict --show-actionscript-warnings=true -compiler.optimize -compiler.as3"
    command += " -output #{output_dir}/#{output_file}"

    run_command(command)
end

#compile_mxmlc(source_path, main_file, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/playersdk/compilers/flex.rb', line 28

def compile_mxmlc(source_path, main_file, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url)
   command ="#{executable('mxmlc')} -compiler.source-path #{source_path} -file-specs #{source_path}/#{main_file} -static-link-runtime-shared-libraries=false"
          
    if include_sdk
        command += " -runtime-shared-library-path=#{config['flex_sdk']}/frameworks/libs/framework.swc,#{deployment_url}/framework.swz,#{config['crossdomain_url']}/crossdomain.xml,#{deployment_url}/framework.swf"
    end

    if include_engine
       command += " -runtime-shared-library-path=#{include_engine}.swc,#{deployment_url}/vj-player-engine.swf"
    end
    
    if include_libs
       command += " -compiler.include-libraries #{include_libs}" 
    end

    command += " -use-network -benchmark -compiler.strict --show-actionscript-warnings=true -compiler.optimize -compiler.as3"
    command += " -output #{output_dir}/#{output_file}"

    run_command(command)
end

#executable(name) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/playersdk/compilers/flex.rb', line 10

def executable(name)
   excutable = "#{config['flex_sdk']}/bin/#{name}"
   
   if false
      excutable += ".exe" 
   end
   
   excutable
end

#optimize_swc(input_swc, output_file, output_dir) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/playersdk/compilers/flex.rb', line 70

def optimize_swc(input_swc, output_file, output_dir)
	# extract
 self.unzip("#{output_dir}/#{input_swc}", "#{config['temp_dir']}")
 
 # optimize
 command = "#{executable('optimizer')} -input #{config['temp_dir']}/library.swf -output #{output_dir}/#{output_file} --keep-as3-metadata='Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient'"
 
 run_command(command)
 
 # update digest information
 command = "#{executable('digest')} --digest.swc-path #{output_dir}/#{input_swc} --digest.rsl-file #{output_dir}/#{output_file}"
 
 run_command(command)
end

#run_command(command) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/playersdk/compilers/flex.rb', line 20

def run_command(command)
   if config['verbose']
       system command
   else
     `#{command}`
   end
end

#unzip(file, destination) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/playersdk/compilers/flex.rb', line 85

def unzip(file, destination)
   Zip::ZipFile.open(file) { |zip_file|
       zip_file.each { |f|
           f_path = File.join(destination, f.name)
           
           if File.exist?(f_path) then
           	FileUtils.rm_rf f_path
           end
           
           FileUtils.mkdir_p(File.dirname(f_path))
           
           zip_file.extract(f, f_path) # unless File.exist?(f_path)
       }
   } 
end