cova 0.2.0 → 0.2.1

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.
Files changed (5) hide show
  1. data/bin/cova +1 -0
  2. data/lib/cova.rb +1 -0
  3. data/lib/covaio.rb +21 -0
  4. data/lib/covamain.rb +79 -25
  5. metadata +18 -4
data/bin/cova CHANGED
@@ -9,6 +9,7 @@ require 'cocoapods'
9
9
  require 'chunky_png'
10
10
  require 'fssm'
11
11
  require 'sqlite3'
12
+ require 'socket'
12
13
 
13
14
  require 'covaconfig'
14
15
  require 'covalog'
@@ -7,6 +7,7 @@ require 'cocoapods'
7
7
  require 'chunky_png'
8
8
  require 'fssm'
9
9
  require 'sqlite3'
10
+ require 'socket'
10
11
 
11
12
  require 'covaconfig'
12
13
  require 'covalog'
@@ -22,6 +22,27 @@ module CovaIO
22
22
  end
23
23
  end
24
24
 
25
+ def _io_findport(port)
26
+ ok = false
27
+ times = 100
28
+ until ok
29
+ begin
30
+ if times <= 0
31
+ port = -1
32
+ ok = true
33
+ else
34
+ socket = TCPSocket.new "localhost", port
35
+ socket.close
36
+ port = port + 1
37
+ times = times - 1
38
+ end
39
+ rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
40
+ ok = true
41
+ end
42
+ end
43
+ return port
44
+ end
45
+
25
46
  def _io_exec_xctool(cmd="build", config="Debug", sdk="iphonesimulator")
26
47
  _io_exec @dir_xctool_home + "/xctool.sh -workspace cova.xcworkspace -scheme Cova -configuration #{config} -sdk #{sdk} #{cmd}"
27
48
  end
@@ -269,8 +269,7 @@ class Cova < Thor
269
269
  return false
270
270
  end
271
271
 
272
- pid = File.read(pid_file)
273
- Process.kill("TERM", pid.to_i)
272
+ File.open(pid_file).each_line {|pid| Process.kill("TERM", pid.to_i)}
274
273
  `rm -rf #{pid_file}`
275
274
 
276
275
  if not _io_isfile pid_file, false
@@ -327,24 +326,39 @@ class Cova < Thor
327
326
  return true
328
327
  end
329
328
 
330
- db_file = @dir_cova_apps_home + "/" + name + "/store/log.db"
331
-
329
+ port = _io_findport 10080
330
+ if port < 0
331
+ _log_info "Too many handshakes. Try saying hi again."
332
+ return false
333
+ end
334
+
335
+ db_file = @dir_cova_apps_home + "/" + name + "/store/log.db"
336
+ if not File.exist?(db_file)
337
+ db = SQLite3::Database.new db_file
338
+ db.execute("CREATE TABLE changelog(file, event, date)")
339
+ end
340
+
341
+ if not File.exist?(db_file)
342
+ _log_info "Cannot start logging. Try saying hi again."
343
+ return false
344
+ end
345
+
332
346
  monitor = FSSM::Monitor.new
333
347
  monitor.path @dir_cova_apps_home + "/" + name do
334
348
  create do |b, r, t|
335
- if File.exist?(db_file) and not r == "store/log.db"
349
+ if File.exist?(db_file) and not r == "store/log.db" and not r == "store/hi.lock"
336
350
  db = SQLite3::Database.new db_file
337
351
  db.execute "insert into changelog values ('#{r}', 'created', '" + Time.new.strftime("%Y-%m-%d %H:%M:%S") + "')"
338
352
  end
339
353
  end
340
354
  update do |b, r, t|
341
- if File.exist?(db_file) and not r == "store/log.db"
355
+ if File.exist?(db_file) and not r == "store/log.db" and not r == "store/hi.lock"
342
356
  db = SQLite3::Database.new db_file
343
357
  db.execute "insert into changelog values ('#{r}', 'updated', '" + Time.new.strftime("%Y-%m-%d %H:%M:%S") + "')"
344
358
  end
345
359
  end
346
360
  delete do |b, r, t|
347
- if File.exist?(db_file) and not r == "store/log.db"
361
+ if File.exist?(db_file) and not r == "store/log.db" and not r == "store/hi.lock"
348
362
  db = SQLite3::Database.new db_file
349
363
  db.execute "insert into changelog values ('#{r}', 'deleted', '" + Time.new.strftime("%Y-%m-%d %H:%M:%S") + "')"
350
364
  end
@@ -354,25 +368,65 @@ class Cova < Thor
354
368
  pid = fork do
355
369
  monitor.run
356
370
  end
371
+ # Process.detach(pid)
372
+ File.open(pid_file, 'a') {|f| f.puts pid}
357
373
 
358
- File.open(@dir_cova_apps_home + "/" + name + "/store/hi.lock", 'w') {|f| f.write(pid)}
359
- Process.detach(pid)
360
-
361
- if _io_isfile pid_file
362
- if not File.exist?(db_file)
363
- db = SQLite3::Database.new db_file
364
- db.execute("CREATE TABLE changelog(file, event, date)")
365
- _log_info "Hi!"
366
- return true
367
- end
368
-
369
- _log_info "Hi again!"
370
- return true
371
- end
372
-
373
- _log_line "Oops, something went wrong."
374
- _log_line_error
375
- return false
374
+ Dir.chdir(@dir_cova_apps_home + "/" + name)
375
+ # Open3.popen3("php -S localhost:#{port} -t www &> store/server.log") {|stdin, stdout, stderr, wait_thr|
376
+ # puts "@@@"
377
+ # }
378
+
379
+ # pid_server = fork {
380
+ # `php -S localhost:10080 &> store/server.log`
381
+ # IO.popen("php -S localhost:10080 -t www") do |stdout|
382
+ # puts "stdout = " + stdout.pid
383
+ # end
384
+ # Open3.popen3("php -S localhost:10080 -t www") do |stdin, stdout, stderr, wait_thr|
385
+ # puts wait_thr
386
+ # puts wait_thr.pid
387
+ # # while line = stdout.gets
388
+ # # puts line
389
+ # # end
390
+ # end
391
+ pid_server = fork {
392
+ [$stdout, $stderr].each {|fh| fh.reopen File.open("store/server.log", "a") }
393
+ exec "php -S localhost:10080 -t www"
394
+ }
395
+ File.open(pid_file, 'a') {|f| f.puts pid_server}
396
+ # cmd = 'ping google.com'
397
+ # Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
398
+ # while line = stdout.gets
399
+ # puts "@@@@@"
400
+ # puts line
401
+ # end
402
+ # end
403
+
404
+ # pipe = IO.popen()
405
+ # File.open(pid_file, 'a') {|f| f.puts pipe.pid}
406
+ # }
407
+ # Process.detach(pid_server)
408
+ # File.open(pid_file, 'a') {|f| f.puts pid_server}
409
+ # puts status
410
+
411
+ # system "php", "-S", "localhost:10080", "-t", "www", "&>", "store/server.log"
412
+ # fork {
413
+ # IO.popen "php -S localhost:#{port} -t www &> store/server.log" do |pipe|
414
+ # puts "parent pid: #{$$}, popen return (child) pid: #{pipe.pid}"
415
+ # end
416
+ # }
417
+ # File.open(pid_file, 'a') {|f| f.puts $?.pid}
418
+ # `php -S localhost:#{port} -t www &> store/server.log; echo $$ > som.pid`
419
+ # puts $?.pid
420
+ # puts pid_server
421
+ # pid_server = fork {
422
+ # IO.popen "php -S localhost:10080 -t www &> t.log" do |pipe|
423
+ # File.open(pid_file, 'a') {|f| f.puts pipe.pid}
424
+ # end
425
+ # }
426
+ # Process.detach(pid_server)
427
+
428
+ _log_info "Hi! Checkout localhost:#{port}"
429
+ return true
376
430
  end
377
431
 
378
432
  desc 'deploy NAME', 'Builds an app'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cova
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Calinescu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-06 00:00:00 Z
18
+ date: 2013-06-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: logger
@@ -129,6 +129,20 @@ dependencies:
129
129
  version: "0"
130
130
  type: :runtime
131
131
  version_requirements: *id008
132
+ - !ruby/object:Gem::Dependency
133
+ name: socket
134
+ prerelease: false
135
+ requirement: &id009 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ type: :runtime
145
+ version_requirements: *id009
132
146
  description: Cova removes a lot of the complexity that comes with designing, coding, testing, prototyping and publishing mobile applications.
133
147
  email: dan@cova.io
134
148
  executables: