Module: Flok
- Defined in:
- lib/flok/build.rb,
lib/flok.rb,
app/kern/macro.rb,
lib/flok/macro.rb,
lib/flok/project.rb,
lib/flok/version.rb,
lib/flok/platform.rb,
lib/flok/utilities.rb,
lib/flok/interactive.rb,
lib/flok/user_compiler.rb,
lib/flok/user_compiler.rb,
lib/flok/hooks_compiler.rb,
lib/flok/services_compiler.rb,
lib/flok/services_compiler.rb,
lib/flok/transition_compiler.rb,
lib/flok/transition_compiler.rb,
lib/flok/user_hook_generators/pop.rb,
lib/flok/user_hook_generators/goto.rb,
lib/flok/user_hook_generators/push.rb
Overview
Compiler executes all rb code inside this context
Defined Under Namespace
Modules: HooksCompiler, Platform, Project, ServicesCompiler, TransitionCompiler, UserCompiler, UserCompilerMacro, UserHooksToManifestOrchestrator Classes: ApplicationJSERBContext, GotoHooksDSLEnv, HooksManifest, HooksManifestEntry, InteractiveServer, PopHooksDSLEnv, PushHooksDSLEnv, Service, ServicesCompilerConfigContext, ServicesCompilerContext, TransitionCompilerAction, TransitionCompilerContext, TransitionCompilerController, TransitionCompilerOn, UserCompilerAction, UserCompilerContext, UserCompilerController, UserCompilerOn
Constant Summary collapse
- VERSION =
"0.0.105"
Class Method Summary collapse
-
.build_world(build_path, platform, environment) ⇒ Object
Build the whole world for a certain platform.
-
.macro_process(text) ⇒ Object
Process one js code file at a time.
-
.platforms ⇒ Object
Alias.
-
.src_glob(type, dir_path, output_path) ⇒ Object
Merge a bunch of source files Take everything in a DIR_PATH folder that matches the TYPE and put it in a file OUTPUT_PATH Will also create the path if it dosen’t exist.
- .src_glob_r(type, dir_path, output_path) ⇒ Object
- .system!(cmd) ⇒ Object
Class Method Details
.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.("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 |
.macro_process(text) ⇒ Object
Process one js code file at a time
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/kern/macro.rb', line 3 def self.macro_process text out = StringIO.new text.split("\n").each do |l| #Send macro if l =~ /SEND/ l.strip! l.gsub!(/SEND\(/, "") l.gsub! /\)$/, "" l.gsub! /\);$/, "" o = l.split(",").map{|e| e.strip} queue_name = o.shift.gsub(/"/, "") res = %{#{queue_name}_q.push([#{o.count-1}, #{o.join(", ")}])} out.puts res else out.puts l end end return out.string end |
.platforms ⇒ Object
Alias
52 53 54 |
# File 'lib/flok/platform.rb', line 52 def self.platforms return Platform.list end |
.src_glob(type, dir_path, output_path) ⇒ Object
Merge a bunch of source files Take everything in a DIR_PATH folder that matches the TYPE and put it in a file OUTPUT_PATH Will also create the path if it dosen’t exist
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flok/build.rb', line 18 def self.src_glob type, dir_path, output_path out = "" FileUtils.mkdir_p(dir_path) FileUtils.mkdir_p(File.dirname(output_path)) NaturalSort.sort(Dir[File.join(dir_path, "*.#{type}")]).each do |f| out << File.read(f) << "\n" end File.write(output_path, out) end |
.src_glob_r(type, dir_path, output_path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/flok/build.rb', line 29 def self.src_glob_r type, dir_path, output_path out = "" Dir.chdir dir_path do FileUtils.mkdir_p(dir_path) FileUtils.mkdir_p(File.dirname(output_path)) nodes = [] nodes += Dir["./init/**/*.#{type}"].select{|e| File.file?(e)} nodes += Dir["./config/**/*.#{type}"].select{|e| File.file?(e)} final_nodes = Dir["./final/**/*.#{type}"].select{|e| File.file?(e)} nodes += Dir["./*.#{type}"].select{|e| File.file?(e)} nodes += (Dir["./**/*"] - nodes - final_nodes).select{|e| File.file?(e)} nodes += final_nodes nodes.each do |f| out << File.read(f) << "\n" end end File.write(output_path, out) end |
.system!(cmd) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/flok/utilities.rb', line 2 def self.system! cmd res = system(cmd) out = "" out << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" out << "SHELL ERROR\n" out << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n" out << "\t(user@localhost) #{cmd}\n" out << "\t(user@localhost) echo $?\n" out << "\t#{res}\n" out << "\t(user@localhost) pwd\n\t" out << `pwd` out << "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" raise out unless res end |