flok 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/flok/build.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'yaml'
2
+ require 'json'
3
+
4
+
5
+ ##################################################################
6
+ #This file contains everything relating to compiling source files
7
+ ##################################################################
8
+
9
+ module Flok
10
+ #Merge a bunch of source files
11
+ #Take everything in a DIR_PATH folder that matches the TYPE and put it in a file OUTPUT_PATH
12
+ #Will also create the path if it dosen't exist
13
+ def self.src_glob type, dir_path, output_path
14
+ out = ""
15
+ FileUtils.mkdir_p(dir_path)
16
+ FileUtils.mkdir_p(File.dirname(output_path))
17
+ Dir[File.join(dir_path, "*.#{type}")].each do |f|
18
+ out << File.read(f) << "\n"
19
+ end
20
+
21
+ File.write(output_path, out)
22
+ end
23
+
24
+ #Build the whole world for a certain platform
25
+ def self.build_world build_path, platform
26
+ #What platform are we working with?
27
+ `rm -rf #{build_path}`
28
+
29
+ #1. `rake build` is run inside `./app/drivers/$platform`
30
+ driver_build_path = File.expand_path("drivers", build_path)
31
+ FileUtils.mkdir_p driver_build_path
32
+ Dir.chdir("./app/drivers/#{platform}") do
33
+ system!("rake build BUILD_PATH=#{driver_build_path}")
34
+ end
35
+
36
+ #2. All js files in `./app/kern/config/*.js` are globbed togeather and sent to `./products/$platform/glob/1kern_config.js`
37
+ Flok.src_glob("js", './app/kern/config', "#{build_path}/glob/1kern_config.js")
38
+
39
+ #3. All js files in `./app/kern/*.js` are globbed togeather and sent to `./products/$platform/glob/2kern.js`
40
+ Flok.src_glob("js", './app/kern', "#{build_path}/glob/2kern.js")
41
+
42
+ #4. All js files are globbed from `./products/$platform/glob` and combined into `./products/$platform/application.js`
43
+ Flok.src_glob("js", "#{build_path}/glob", "#{build_path}/application.js")
44
+
45
+ #5. Add custom commands
46
+ ################################################################################################################
47
+ #lsiface() - List interfaces for driver config.yml
48
+ #---------------------------------------------------------------------------------------
49
+ #Load the driver config.yml
50
+ driver_config = YAML.load_file("./app/drivers/#{platform}/config.yml")
51
+ raise "No config.yml found in your 'platform: #{platform}' driver" unless driver_config
52
+
53
+ #Create array that looks like a javascript array with single quotes
54
+ iface_arr = "[" + driver_config['ifaces'].map!{|e| "'#{e}'"}.join(", ") + "]"
55
+
56
+ #Append this to our output file
57
+ `echo "IFACES = #{iface_arr};" >> #{build_path}/application.js`
58
+ `echo "PLATFORM = \'#{platform}\';" >> #{build_path}/application.js`
59
+ #---------------------------------------------------------------------------------------
60
+ ################################################################################################################
61
+
62
+ `rm -rf #{build_path}/glob`
63
+ end
64
+
65
+ def self.system! cmd
66
+ res = system(cmd)
67
+ out = ""
68
+ out << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
69
+ out << "SHELL ERROR\n"
70
+ out << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n"
71
+ out << "\t(user@localhost) #{cmd}\n"
72
+ out << "\t(user@localhost) echo $?\n"
73
+ out << "\t#{res}\n"
74
+ out << "\t(user@localhost) pwd\n\t"
75
+ out << `pwd`
76
+ out << "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
77
+ raise out unless res
78
+ end
79
+ end
data/lib/flok/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
File without changes
@@ -0,0 +1,61 @@
1
+ #This spec checks to make sure that for each driver, the emitted javascript file actually executes correctly
2
+ #In addition, it runs a sanity check by calling flok()
3
+
4
+ require 'execjs'
5
+ require 'helpers'
6
+ require 'flok/build'
7
+
8
+ def build_world_for_platform platform
9
+ Flok.system!("rake build_world PLATFORM=#{platform}")
10
+ end
11
+
12
+ RSpec.describe "Emitted build products are valid for all platforms" do
13
+ it "can run application.js on execjs environment without runtime initial failure" do
14
+ #get a list of the platforms based on the drev folder names
15
+ platforms = (Dir["./app/drivers/*"]).map!{|e| File.basename(e)} - ["iface"]
16
+
17
+ platforms.each do |p|
18
+ puts "testing #{p}"
19
+ puts "\t-building world for $platform=#{p}"
20
+ build_world_for_platform(p)
21
+
22
+ puts "\t-executing world"
23
+ ctx = ExecJS.compile(File.read("./products/#{p}/application.js"))
24
+ end
25
+ end
26
+
27
+ it "supports IFACES global" do
28
+ #get a list of the platforms based on the drev folder names
29
+ platforms = (Dir["./app/drivers/*"]).map!{|e| File.basename(e)} - ["iface"]
30
+
31
+ platforms.each do |p|
32
+ puts "testing #{p}"
33
+ puts "\t-building world for $platform=#{p}"
34
+ build_world_for_platform(p)
35
+
36
+ #IFACES
37
+ puts "\t-executing world"
38
+ ctx = ExecJS.compile(File.read("./products/#{p}/application.js"))
39
+ ifaces = ctx.eval("IFACES")
40
+ driver_ifaces = YAML.load_file("./app/drivers/#{p}/config.yml")["ifaces"]
41
+ expect(ifaces).to eq(driver_ifaces)
42
+ end
43
+ end
44
+
45
+ it "supports PLATFORM global" do
46
+ #get a list of the platforms based on the drev folder names
47
+ platforms = (Dir["./app/drivers/*"]).map!{|e| File.basename(e)} - ["iface"]
48
+
49
+ platforms.each do |p|
50
+ puts "testing #{p}"
51
+ puts "\t-building world for $platform=#{p}"
52
+ build_world_for_platform(p)
53
+
54
+ #IFACES
55
+ puts "\t-executing world"
56
+ ctx = ExecJS.compile(File.read("./products/#{p}/application.js"))
57
+ platform = ctx.eval("PLATFORM")
58
+ expect(platform).to eq(p)
59
+ end
60
+ end
61
+ end
@@ -1,159 +1,159 @@
1
- require 'phantomjs'
2
- require 'rspec/wait'
3
- require 'webrick'
4
- require "./spec/helpers"
5
- require 'json'
6
- require 'os'
7
-
8
- RSpec.describe "Drivers::Net" do
9
- before(:all) do
10
- #Respond to kill
11
- @killable = []
12
- end
13
-
14
- after(:all) do
15
- @killable ||= []
16
- @killable.each {|p| p.kill}
17
-
18
- #Stopgap to kill everything
19
- if OS.mac?
20
- `ps -ax | grep net_spec | awk '{print $1}' | grep -v #{Process.pid} | xargs kill -9 >/dev/null 2>&1`;
21
- `ps -ax | grep phantomjs| awk '{print $1}' | xargs kill -9 >/dev/null 2>&1`
22
- end
23
- end
24
-
25
- it "can make a get request" do
26
- #Build driver
27
- `cd ./app/drivers/browser; rake build`
28
-
29
- cr = ChromeRunner.new "./products/drivers/browser.js"
30
-
31
- #Setup rspec test server
32
- called = false
33
- spek = Webbing.get "/" do |params|
34
- called = true
35
- {"hello" => "world"}.to_json
36
- end
37
- @killable << spek
38
- cr.eval "drivers.network.request('GET', 'http://localhost:#{spek.port}', {})"
39
- cr.commit
40
-
41
- #Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
42
- wait(3).for { called }.to eq(true)
43
- end
44
-
45
- it "can make a get request with parameters" do
46
- #Build driver
47
- `cd ./app/drivers/browser; rake build`
48
-
49
- cr = ChromeRunner.new "./products/drivers/browser.js"
50
-
51
- #Setup rspec test server
52
- called = false
53
- result = {}
54
- spek = Webbing.get "/" do |params|
55
- result = params
56
- called = true
57
- {"hello" => "world"}.to_json
58
- end
59
- @killable << spek
60
- cr.eval "drivers.network.request('GET', 'http://localhost:#{spek.port}', {'a':'b'})"
61
- cr.commit
62
-
63
- #Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
64
- wait(3).for { called }.to eq(true)
65
- expect(result).to eq({'a' => 'b'})
66
- end
67
-
68
- it "can make a get and respond from callback" do
69
- #Build driver
70
- `cd ./app/drivers/browser; rake build`
71
-
72
- cr = ChromeRunner.new "./products/drivers/browser.js"
73
-
74
- #Setup rspec test server
75
- @spek = Webbing.get "/" do |params|
76
- {"port" => @spek2.port}.to_json
77
- end
78
-
79
- called = false
80
- @spek2 = Webbing.get "/" do |params|
81
- called = true
82
- end
83
-
84
- @killable << @spek
85
- @killable << @spek2
86
- cr.eval %{
87
- drivers.network.request('GET', 'http://localhost:#{@spek.port}', {}, function(res) {
88
- var port = res.port;
89
- drivers.network.request('GET', 'http://localhost:'+port, {});
90
- })
91
- }
92
- cr.commit
1
+ #require 'phantomjs'
2
+ #require 'rspec/wait'
3
+ #require 'webrick'
4
+ #require "./spec/helpers"
5
+ #require 'json'
6
+ #require 'os'
7
+
8
+ #RSpec.describe "Drivers::Net" do
9
+ #before(:all) do
10
+ ##Respond to kill
11
+ #@killable = []
12
+ #end
13
+
14
+ #after(:all) do
15
+ #@killable ||= []
16
+ #@killable.each {|p| p.kill}
17
+
18
+ ##Stopgap to kill everything
19
+ #if OS.mac?
20
+ #`ps -ax | grep net_spec | awk '{print $1}' | grep -v #{Process.pid} | xargs kill -9 >/dev/null 2>&1`;
21
+ #`ps -ax | grep phantomjs| awk '{print $1}' | xargs kill -9 >/dev/null 2>&1`
22
+ #end
23
+ #end
24
+
25
+ #it "can make a get request" do
26
+ ##Build driver
27
+ #`cd ./app/drivers/browser; rake build`
28
+
29
+ #cr = ChromeRunner.new "./products/drivers/browser.js"
30
+
31
+ ##Setup rspec test server
32
+ #called = false
33
+ #spek = Webbing.get "/" do |params|
34
+ #called = true
35
+ #{"hello" => "world"}.to_json
36
+ #end
37
+ #@killable << spek
38
+ #cr.eval "drivers.network.request('GET', 'http://localhost:#{spek.port}', {})"
39
+ #cr.commit
93
40
 
94
41
  ##Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
95
- wait(3).for { called }.to eq(true)
96
- end
97
-
98
- it "can make a get and cancel a request that has not yet been received via callback" do
99
- #Build driver
100
- `cd ./app/drivers/browser; rake build`
101
-
102
- cr = ChromeRunner.new "./products/drivers/browser.js"
103
-
104
- #Setup rspec test server
105
- called = false
106
- @spek = Webbing.get "/" do |params|
107
- {:port => @spek2.port}.to_json
108
- end
109
-
110
- @spek2 = Webbing.get "/" do |params|
111
- called = true
112
- end
113
-
114
- @killable << @spek
115
- cr.eval %{
116
- socket = drivers.network.request('GET', 'http://localhost:#{@spek.port}', {}, function(res) {
117
- var port = res.port;
118
- drivers.network.request('GET', 'http://localhost:'+port, {});
119
-
120
- });
121
-
122
- drivers.network.cancel_request(socket);
123
- }
124
- cr.commit
125
-
126
- #Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
127
- sleep 2
128
- expect(called).to eq(false)
129
- end
130
-
131
- it "returns an error for a non-existant resource" do
132
- #Build driver
133
- `cd ./app/drivers/browser; rake build`
134
-
135
- cr = ChromeRunner.new "./products/drivers/browser.js"
136
-
137
- #Setup rspec test server
138
- @spek = Webbing.get "/" do |params|
139
- {:port => @spek2.port}.to_json
140
- end
141
-
142
- error = nil
143
- @spek2 = Webbing.get "/" do |params|
144
- error = params["error"]
145
- end
146
-
147
- @killable << @spek
148
- cr.eval %{
149
- socket = drivers.network.request('GET', 'http://localhost:#{@spek.port}/404', {}, function(res, error) {
150
- drivers.network.request('GET', 'http://localhost:'+#{@spek2.port}, {error: error});
151
- });
152
- }
153
- cr.commit
154
-
155
- #Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
156
- sleep 2
157
- expect(error).to eq("true")
158
- end
159
- end
42
+ #wait(3).for { called }.to eq(true)
43
+ #end
44
+
45
+ #it "can make a get request with parameters" do
46
+ ##Build driver
47
+ #`cd ./app/drivers/browser; rake build`
48
+
49
+ #cr = ChromeRunner.new "./products/drivers/browser.js"
50
+
51
+ ##Setup rspec test server
52
+ #called = false
53
+ #result = {}
54
+ #spek = Webbing.get "/" do |params|
55
+ #result = params
56
+ #called = true
57
+ #{"hello" => "world"}.to_json
58
+ #end
59
+ #@killable << spek
60
+ #cr.eval "drivers.network.request('GET', 'http://localhost:#{spek.port}', {'a':'b'})"
61
+ #cr.commit
62
+
63
+ ##Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
64
+ #wait(3).for { called }.to eq(true)
65
+ #expect(result).to eq({'a' => 'b'})
66
+ #end
67
+
68
+ #it "can make a get and respond from callback" do
69
+ ##Build driver
70
+ #`cd ./app/drivers/browser; rake build`
71
+
72
+ #cr = ChromeRunner.new "./products/drivers/browser.js"
73
+
74
+ ##Setup rspec test server
75
+ #@spek = Webbing.get "/" do |params|
76
+ #{"port" => @spek2.port}.to_json
77
+ #end
78
+
79
+ #called = false
80
+ #@spek2 = Webbing.get "/" do |params|
81
+ #called = true
82
+ #end
83
+
84
+ #@killable << @spek
85
+ #@killable << @spek2
86
+ #cr.eval %{
87
+ #drivers.network.request('GET', 'http://localhost:#{@spek.port}', {}, function(res) {
88
+ #var port = res.port;
89
+ #drivers.network.request('GET', 'http://localhost:'+port, {});
90
+ #})
91
+ #}
92
+ #cr.commit
93
+
94
+ ###Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
95
+ #wait(3).for { called }.to eq(true)
96
+ #end
97
+
98
+ #it "can make a get and cancel a request that has not yet been received via callback" do
99
+ ##Build driver
100
+ #`cd ./app/drivers/browser; rake build`
101
+
102
+ #cr = ChromeRunner.new "./products/drivers/browser.js"
103
+
104
+ ##Setup rspec test server
105
+ #called = false
106
+ #@spek = Webbing.get "/" do |params|
107
+ #{:port => @spek2.port}.to_json
108
+ #end
109
+
110
+ #@spek2 = Webbing.get "/" do |params|
111
+ #called = true
112
+ #end
113
+
114
+ #@killable << @spek
115
+ #cr.eval %{
116
+ #socket = drivers.network.request('GET', 'http://localhost:#{@spek.port}', {}, function(res) {
117
+ #var port = res.port;
118
+ #drivers.network.request('GET', 'http://localhost:'+port, {});
119
+
120
+ #});
121
+
122
+ #drivers.network.cancel_request(socket);
123
+ #}
124
+ #cr.commit
125
+
126
+ ##Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
127
+ #sleep 2
128
+ #expect(called).to eq(false)
129
+ #end
130
+
131
+ #it "returns an error for a non-existant resource" do
132
+ ##Build driver
133
+ #`cd ./app/drivers/browser; rake build`
134
+
135
+ #cr = ChromeRunner.new "./products/drivers/browser.js"
136
+
137
+ ##Setup rspec test server
138
+ #@spek = Webbing.get "/" do |params|
139
+ #{:port => @spek2.port}.to_json
140
+ #end
141
+
142
+ #error = nil
143
+ #@spek2 = Webbing.get "/" do |params|
144
+ #error = params["error"]
145
+ #end
146
+
147
+ #@killable << @spek
148
+ #cr.eval %{
149
+ #socket = drivers.network.request('GET', 'http://localhost:#{@spek.port}/404', {}, function(res, error) {
150
+ #drivers.network.request('GET', 'http://localhost:'+#{@spek2.port}, {error: error});
151
+ #});
152
+ #}
153
+ #cr.commit
154
+
155
+ ##Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
156
+ #sleep 2
157
+ #expect(error).to eq("true")
158
+ #end
159
+ #end