videojuicer-player-sdk 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile ADDED
@@ -0,0 +1,35 @@
1
+ h1. Videojuicer Player SDK
2
+
3
+ h2. Configuration
4
+
5
+ You must create a `config.yml` to define the build tasks for the `playersdk` to use, the configuration file uses standard YAML syntaxs.
6
+
7
+ ---
8
+ # Flex SDK location
9
+ flex_sdk: "/Applications/Adobe\ Flex\ Builder\ 3/sdks/3.3.0"
10
+
11
+ # Flex framework version, the bundled RSLs are specific
12
+ flex_framework_version: "framework_3.3.0.4852"
13
+
14
+ # List of tasks the SDK will complete
15
+ tasks:
16
+ # Copies the Flex framework RSLs into the build folder
17
+ "framework": {
18
+ type: framework,
19
+ framework_rsl: 'framework_3.3.0.4852'
20
+ }
21
+ # Compiles an Addon for use with the Videojuicer Player
22
+ "player-addon": {
23
+ type: addon,
24
+ src: vj-player-ui/src, main: DefaultUI.mxml,
25
+ sdk: true,
26
+ engine: "builds/vj-player-engine",
27
+ libs: false,
28
+ target: player-addon
29
+ }
30
+
31
+ h2. TODO
32
+
33
+ - Tests
34
+ - Expand README
35
+ - License
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ gem 'jeweler', '>= 1.0.1'
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |s|
9
+ s.name = "player-sdk"
10
+ s.summary = %Q{Videojuicer Player SDK runtime and compiler to create and build Player Addons.}
11
+ s.email = "sixones@me.com"
12
+ s.homepage = "http://player.videojuicer.com"
13
+ s.description = "Videojuicer Player SDK runtime and compiler to create and build Player Addons."
14
+ s.authors = ["Adam Livesley"]
15
+ s.files.exclude 'test/dest'
16
+ s.test_files.exclude 'test/dest'
17
+ s.add_dependency('open4', '>= 0.9.6')
18
+ s.add_dependency('rubyzip', '>= 0.9.1')
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler not available. Install it with: sudo gem install jeweler --version '>= 1.0.1'"
22
+ exit(1)
23
+ end
24
+
25
+ Rake::TestTask.new do |t|
26
+ t.libs << 'lib'
27
+ t.pattern = 'test/**/test_*.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ Rake::RDocTask.new do |rdoc|
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = 'playersdk'
34
+ rdoc.options << '--line-numbers' << '--inline-source'
35
+ rdoc.rdoc_files.include('README*')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
38
+
39
+ begin
40
+ require 'rcov/rcovtask'
41
+ Rcov::RcovTask.new do |t|
42
+ t.libs << 'test'
43
+ t.test_files = FileList['test/**/test_*.rb']
44
+ t.verbose = true
45
+ end
46
+ rescue LoadError
47
+ end
48
+
49
+ task :default => [:test, :features]
50
+
51
+ # console
52
+
53
+ desc "Open an irb session preloaded with this library"
54
+ task :console do
55
+ sh "irb -rubygems -I lib -r player-sdk.rb"
56
+ end
57
+
58
+ begin
59
+ require 'cucumber/rake/task'
60
+
61
+ Cucumber::Rake::Task.new(:features) do |t|
62
+ t.cucumber_opts = "--format progress"
63
+ end
64
+ rescue LoadError
65
+ desc 'Cucumber rake task not available'
66
+ task :features do
67
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
68
+ end
69
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 2
4
+ :patch: 0
data/bin/playersdk ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ help = <<HELP
6
+ Videojuicer Player 3.0 SDK
7
+
8
+ Basic Command Line Usage:
9
+ playersdk # . -> ./_site
10
+ playersdk <path to write generated site> # . -> <path>
11
+ playersdk <path to source> <path to write generated site> # <path> -> <path>
12
+
13
+ Configuration is read from '<source>/_config.yml' but can be overriden
14
+ using the following options:
15
+
16
+ HELP
17
+
18
+ require 'optparse'
19
+ require 'playersdk'
20
+
21
+ exec = { }
22
+ options = { }
23
+
24
+ opts = OptionParser.new do |opts|
25
+ opts.banner = help
26
+
27
+ opts.on("--build-dir [DIR]", "Location of the build targets") do |location|
28
+ options['build_dir'] = location unless location.nil?
29
+ end
30
+
31
+ opts.on("--workspace-dir [DIR]", "Location of the workspace directory") do |location|
32
+ options['workspace_dir'] = location unless location.nil?
33
+ end
34
+
35
+ opts.on("--verbose", "Use verbose ouput mode") do
36
+ options['verbose'] = true
37
+ end
38
+
39
+ opts.on("--version", "Display current version") do
40
+ puts "Videojuicer Player SDK " + PlayerSDK.version
41
+ exit 0
42
+ end
43
+ end
44
+
45
+ # Read command line options into `options` hash
46
+ opts.parse!
47
+
48
+ # Get source and destintation from command line
49
+ case ARGV.size
50
+ when 0
51
+ when 1
52
+ options['workspace_dir'] = ARGV[0]
53
+ else
54
+ puts "Invalid options. Run `playersdk --help` for assistance."
55
+ exit(1)
56
+ end
57
+
58
+ config = PlayerSDK.configuration(options)
59
+
60
+ # Creates a new PlayerSDK compiler instance
61
+ compiler = PlayerSDK::Compiler.new(config)
62
+
63
+ compiler.process()
@@ -0,0 +1,60 @@
1
+ module PlayerSDK
2
+ class Compiler
3
+ attr_accessor :config, :compiler
4
+
5
+ def initialize(config)
6
+ self.config = config.clone
7
+
8
+ self.compiler = PlayerSDK::Compilers::Flex.new(self.config);
9
+ end
10
+
11
+ def process
12
+ tasks = self.config['tasks']
13
+
14
+ puts "Found #{tasks.length} task(s) to process"
15
+
16
+ tasks.each do |key,value|
17
+ self.run_task(key, value)
18
+ end
19
+
20
+ puts "\n\n"
21
+ puts "Completed #{tasks.length} tasks(s)"
22
+
23
+ if self.config['player_src'] != ''
24
+ #self.compiler.compile_mxmlc(self.config['player_source'], 'src/Main.mxml', true, true, false, 'vj-player.swf', self.config['build_dir'])
25
+ end
26
+ end
27
+
28
+ def run_task(key, value)
29
+ puts "Running task #{key} in #{value['src']}"
30
+
31
+ case value['type']
32
+ when "player"
33
+ self.compiler.compile_mxmlc(value['src'], value['main'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
34
+ when "engine"
35
+ self.compiler.compile_compc(value['src'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
36
+
37
+ puts "Optimizing engine swf .."
38
+
39
+ self.compiler.optimize_swc(value['target'], self.config['build_dir'])
40
+ when "addon"
41
+ self.compiler.compile_mxmlc(value['src'], value['main'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
42
+ when "framework"
43
+ puts "Moving Flex framework RSLs to #{config['build_dir']}"
44
+
45
+ self.compiler.run_command("cp #{config['flex_sdk']}/frameworks/rsls/#{value['framework_rsl']}.swz #{config['build_dir']}/framework.swz")
46
+ self.compiler.run_command("cp #{config['flex_sdk']}/frameworks/rsls/#{value['framework_rsl']}.swf #{config['build_dir']}/framework.swf")
47
+ when "clean"
48
+ puts "Cleaning directories ..."
49
+
50
+ self.compiler.run_command("rm -rf #{config['build_dir']}/* #{config['tmp_dir']}/*")
51
+ when ""
52
+ puts "Unknown task type, skipping task ..\n"
53
+ return
54
+ end
55
+
56
+ puts "\n"
57
+ puts "Successfully compiled #{key} to target #{value['target']}.\n"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,93 @@
1
+ module PlayerSDK
2
+ module Compilers
3
+ class Flex
4
+ attr_accessor :config
5
+
6
+ def initialize(config)
7
+ self.config = config.clone
8
+ end
9
+
10
+ def executable(name)
11
+ excutable = "#{config['flex_sdk']}/bin/#{name}"
12
+
13
+ if false
14
+ excutable += ".exe"
15
+ end
16
+
17
+ excutable
18
+ end
19
+
20
+ def run_command(command)
21
+ if config['verbose']
22
+ system command
23
+ else
24
+ `#{command}`
25
+ end
26
+ end
27
+
28
+ def compile_mxmlc(source_path, main_file, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url)
29
+ command ="#{executable('mxmlc')} -compiler.source-path #{source_path} -file-specs #{source_path}/#{main_file} -static-link-runtime-shared-libraries=false"
30
+
31
+ if include_sdk
32
+ command += " -runtime-shared-library-path=#{config['flex_sdk']}/frameworks/libs/framework.swc,framework.swz,#{deployment_url}crossdomain.xml,framework.swf"
33
+ end
34
+
35
+ if include_engine
36
+ command += " -runtime-shared-library-path=#{include_engine}.swc,#{deployment_url}#{output_file}"
37
+ end
38
+
39
+ if include_libs
40
+ command += " -compiler.include-libraries #{include_libs}"
41
+ end
42
+
43
+ command += " -use-network -benchmark -compiler.strict --show-actionscript-warnings=true -compiler.optimize -compiler.as3"
44
+ command += " -output #{output_dir}/#{output_file}.swf"
45
+
46
+ run_command(command)
47
+ end
48
+
49
+ def compile_compc(source_path, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url)
50
+ command = "#{executable('compc')} -source-path #{source_path} -include-sources #{source_path}"
51
+
52
+ if include_sdk
53
+ command += " -runtime-shared-library-path=#{config['flex_sdk']}/#{config['flex_framework_swc']},#{deployment_url}/#{config['flex_framework_version']}.swz,#{deployment_url}crossdomain.xml,#{deployment_url}/#{config['flex_framework_version']}.swf"
54
+ end
55
+
56
+ if include_engine
57
+ command += " -runtime-shared-library-path=#{include_engine}.swc,#{deployment_url}#{output_file}.swf"
58
+ end
59
+
60
+ if include_libs
61
+ command += " -compiler.include-libraries #{include_libs}"
62
+ end
63
+
64
+ command += " -use-network -benchmark -compiler.strict --show-actionscript-warnings=true -compiler.optimize -compiler.as3"
65
+ command += " -output #{output_dir}/#{output_file}.swc"
66
+
67
+ run_command(command)
68
+ end
69
+
70
+ def optimize_swc(output_file, output_dir)
71
+ self.unzip("#{output_dir}/#{output_file}.swc", "#{config['temp_dir']}")
72
+
73
+ command = "#{executable('optimizer')} -input #{config['temp_dir']}/library.swf -output #{output_dir}/#{output_file}.swf --keep-as3-metadata='Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient'"
74
+
75
+ run_command(command)
76
+
77
+ command = "#{executable('digest')} --digest.swc-path #{output_dir}/#{output_file}.swc --digest.rsl-file #{output_dir}/#{output_file}.swf"
78
+
79
+ run_command(command)
80
+ end
81
+
82
+ def unzip(file, destination)
83
+ Zip::ZipFile.open(file) { |zip_file|
84
+ zip_file.each { |f|
85
+ f_path = File.join(destination, f.name)
86
+ FileUtils.mkdir_p(File.dirname(f_path))
87
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
88
+ }
89
+ }
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,63 @@
1
+ class Hash
2
+
3
+ # Returns a new hash just like this one, but with all the string keys expressed as symbols.
4
+ # Also applies to hashes within self.
5
+ # Based on an implementation within Rails 2.x, thanks Rails!
6
+ def deep_symbolize
7
+ target = dup
8
+ target.inject({}) do |memo, (key, value)|
9
+ value = value.deep_symbolize if value.is_a?(Hash)
10
+ memo[(key.to_sym rescue key) || key] = value
11
+ memo
12
+ end
13
+ end
14
+
15
+ # Subtracts one hash from another by removing keys from the actor and recursing on any hash values.
16
+ # Returns a new Hash without affecting the actors.
17
+ # Example 1:
18
+ # {:foo=>"bar"} - {:foo=>"bar"} == {}
19
+ # Example 2 of deep nesting:
20
+ # {:foo=>{:bar=>"baz", :car=>"naz"}, :bar=>"baz"} - {:foo=>{:car=>"naz"}} == {:foo=>{:bar=>"baz"}, :bar=>"baz"}
21
+ def -(arg)
22
+ target = dup; actor = arg.dup
23
+ actor.each do |key, value|
24
+ if value.is_a?(Hash)
25
+ target[key] = target[key] - value
26
+ else
27
+ target.delete(key)
28
+ end
29
+ end
30
+ return target
31
+ end
32
+
33
+ # Returns a new hash just like this one, but with all STRING keys and values evaluated
34
+ # and rendered as liquid templates using the provided payload hash.
35
+ def deep_liquify(payload={})
36
+ target = dup
37
+ target.inject({}) do |memo, (key, value)|
38
+ value = value.deep_liquify(payload) if value.is_a?(Hash)
39
+ value = value.liquify(payload) if value.is_a?(String)
40
+ key = key.liquify(payload) if key.is_a?(String)
41
+ memo[(key.to_sym rescue key) || key] = value
42
+ memo
43
+ end
44
+ end
45
+
46
+ # Merges self with another hash, recursively.
47
+ #
48
+ # This code was lovingly stolen from some random gem:
49
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
50
+ #
51
+ # Thanks to whoever made it.
52
+ def deep_merge(hash)
53
+ target = dup
54
+ hash.keys.each do |key|
55
+ if hash[key].is_a? Hash and self[key].is_a? Hash
56
+ target[key] = target[key].deep_merge(hash[key])
57
+ next
58
+ end
59
+ target[key] = hash[key]
60
+ end
61
+ target
62
+ end
63
+ end
data/lib/playersdk.rb ADDED
@@ -0,0 +1,59 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+
3
+ # rubygems
4
+ require 'rubygems'
5
+
6
+ # core
7
+ require 'fileutils'
8
+ require 'yaml'
9
+ require 'zip/zip'
10
+
11
+ # internal requires
12
+ require 'playersdk/core_ext/hash.rb'
13
+ require 'playersdk/compiler.rb'
14
+ require 'playersdk/compilers/flex.rb'
15
+
16
+ module PlayerSDK
17
+ # Default options. Overriden by values in config.yml or command-line opts.
18
+ # (Strings rather symbols used for compatability with YAML)
19
+ DEFAULTS = {
20
+ 'build_dir' => 'builds',
21
+ 'temp_dir' => 'tmp',
22
+ 'workspace_dir' => '.',
23
+ 'flex_sdk' => '',
24
+ 'flex_framework_swc' => 'frameworks/libs/framework.swc',
25
+ 'flex_framework_version' => '',
26
+ 'tasks' => '',
27
+ 'verbose' => false
28
+ }
29
+
30
+ # Generate a Player SDK configuration Hash by merging the default options
31
+ # with anything in config.yml, and adding the given options on top
32
+ # +override+ is a Hash of config directives
33
+ #
34
+ # Returns Hash
35
+ def self.configuration(override)
36
+ # _config.yml may override default source location, but until
37
+ # then, we need to know where to look for _config.yml
38
+ workspace_dir = override['workspace_dir'] || PlayerSDK::DEFAULTS['workspace_dir']
39
+
40
+ # Get configuration from <source>/config.yml
41
+ config = {}
42
+ config_file = File.join(workspace_dir, 'config.yml')
43
+ begin
44
+ config = YAML.load_file(config_file)
45
+ puts "Configuration from #{config_file}"
46
+ rescue => err
47
+ puts "WARNING: Could not read configuration. Using defaults (and options)."
48
+ puts "\t" + err
49
+ end
50
+
51
+ # Merge DEFAULTS < config.yml < override
52
+ PlayerSDK::DEFAULTS.deep_merge(config).deep_merge(override)
53
+ end
54
+
55
+ def self.version
56
+ yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
57
+ "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: videojuicer-player-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.2"
5
+ platform: ruby
6
+ authors:
7
+ - Adam Livesley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-12 00:00:00 -07:00
13
+ default_executable: playersdk
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyzip
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: open4
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.6
34
+ version:
35
+ description: Videojuicer Player SDK runtime and compiler to create and build Player Addons.
36
+ email: sixones@me.com
37
+ executables:
38
+ - playersdk
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.textile
43
+ files:
44
+ - README.textile
45
+ - Rakefile
46
+ - VERSION.yml
47
+ - bin/playersdk
48
+ - lib/playersdk.rb
49
+ - lib/playersdk/core_ext/hash.rb
50
+ - lib/playersdk/compiler.rb
51
+ - lib/playersdk/compilers/flex.rb
52
+ has_rdoc: true
53
+ homepage: http://developer.videojuicer.com
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.2.0
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: Videojuicer Player SDK runtime and compiler.
78
+ test_files: []
79
+