Method: Flok.build_world

Defined in:
lib/flok/build.rb

.build_world(build_path, platform, environment) ⇒ Object

Build the whole world for a certain platform



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
# File 'lib/flok/build.rb', line 50

def self.build_world build_path, platform, environment
  #Environment must be either DEBUG or RELEASE
  raise "$FLOK_ENV must either be DEBUG or RELEASE, got #{environment.inspect}" unless %w{DEBUG RELEASE}.include? environment

  #Clean up previous build
  `rm -rf #{build_path}`

  #1. `rake build` is run inside `./app/drivers/$platform`
  driver_build_path = File.expand_path("drivers", build_path)
  FileUtils.mkdir_p driver_build_path
  Dir.chdir("./app/drivers/#{platform}") do 
  system!("rake build BUILD_PATH=#{driver_build_path}")
  end

  #2. All js files in `./app/kern/config/*.js` are globbed togeather and sent to `./products/$platform/glob/1kern_config.js`
  Flok.src_glob("js", './app/kern/config', "#{build_path}/glob/1kern_config.js")

  #3. All js files in `./app/kern/*.js` are globbed togeather and sent to `./products/$platform/glob/2kern.pre_macro.js`
  Flok.src_glob("js", './app/kern', "#{build_path}/glob/2kern.pre_macro.js")

  #4. All js files in `./app/kern/pagers/*.js` are appended to `./products/$PLATFORM/glob/3kern.pre_macro.js`
  Flok.src_glob("js", './app/kern/pagers/', "#{build_path}/glob/3kern.pre_macro.js")

  #5. All js files in `./products/$PLATFORM/glob/{2,3}kern.pre_macro.js` are run through `./app/kern/macro.rb's macro_process` and then sent to ./products/$PLATFORM/glob/{2,3}kern.js
  File.write("#{build_path}/glob/2kern.pre_macro.js", Flok.macro_process(File.read("#{build_path}/glob/2kern.pre_macro.js")))
  File.write("#{build_path}/glob/3kern.pre_macro.js", Flok.macro_process(File.read("#{build_path}/glob/3kern.pre_macro.js")))

  #6. All js files are globbed from `./products/$platform/glob` and combined into `./products/$platform/glob/application.js.erb`
  Flok.src_glob("js", "#{build_path}/glob", "#{build_path}/glob/application.js.erb")

  #7. Add custom commands
  ################################################################################################################
  #MODS - List mods listed in config.yml
  #---------------------------------------------------------------------------------------
  #Create array that looks like a javascript array with single quotes
  mods = Flok::Platform.mods(environment)
  mods_js_arr = "[" + mods.map{|e| "'#{e}'"}.join(", ") + "]"

  #Append this to our output file
  `echo "MODS = #{mods_js_arr};" >> #{build_path}/glob/application.js.erb`
  `echo "PLATFORM = \'#{platform}\';" >> #{build_path}/glob/application.js.erb`
  #---------------------------------------------------------------------------------------
  ################################################################################################################

  #8. Append relavent mods code in kernel with macros
  mods.each do |mod|
    s = File.read("./app/kern/mod/#{mod}.js")
    open("#{build_path}/glob/application.js.erb", "a") do |f|
      f.puts Flok.macro_process(s)
    end
  end

  #9. The compiled `glob/application.js.erb` file is run through the ERB compiler and formed into `application.js`
  erb_src = File.read "#{build_path}/glob/application.js.erb"
  renderr = ERB.new(erb_src)
  context = ApplicationJSERBContext.new()
  new_src = renderr.result(context.get_binding)
  File.write "#{build_path}/application.js", new_src
end