droiuby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/droiuby/project.rb +52 -15
  2. metadata +2 -18
@@ -14,7 +14,7 @@ class Project < Thor
14
14
 
15
15
  include Thor::Actions
16
16
 
17
- source_root 'templates'
17
+ source_root File.join(File.dirname(__FILE__), 'templates')
18
18
 
19
19
  desc "launch device IP [URL]","Tell droiuby to connect to app hosted at URL"
20
20
  def launch(device_ip, url)
@@ -35,7 +35,11 @@ class Project < Thor
35
35
  @launcher_icon = ''
36
36
  @base_url = ''
37
37
  @main_xml = 'index.xml'
38
-
38
+
39
+ if output_dir.blank?
40
+ output_dir = Dir.pwd
41
+ end
42
+
39
43
  dest_folder = File.join(output_dir,"#{name}")
40
44
  template File.join('ruby','config.droiuby.erb'), File.join(dest_folder,"config.droiuby")
41
45
  template File.join('ruby','gitignore.erb'), File.join(dest_folder,".gitignore")
@@ -48,18 +52,31 @@ class Project < Thor
48
52
  desc "package NAME [WORKSPACE_DIR] [true|false]","package a project"
49
53
 
50
54
  def package(name, source_dir = 'projects', force = "false")
51
- src_folder = File.join(source_dir,"#{name}")
55
+ src_folder = if name.blank?
56
+ Dir.pwd
57
+ else
58
+ File.join(source_dir, name)
59
+ end
52
60
  say "compress #{src_folder}"
53
61
  compress(src_folder, force)
54
62
  end
55
63
 
64
+ require 'webrick'
65
+ include WEBrick
66
+
56
67
  desc "live NAME DEVICE_IP [HOST NAME] [SOURCE]", "Allow live editing of apps by starting a web server and pointing droiuby to the local instance"
57
- def live(name, device_ip, host_name, source_dir)
58
- require 'webrick'
59
- include WEBrick
68
+ def live(name, device_ip, host_name = nil, source_dir = 'projects')
69
+
70
+
60
71
  source_dir_args = source_dir ? source_dir : 'projects'
61
72
  host_name_args = host_name ? host_name : Socket.gethostname
62
- src_dir = source_dir_args.blank? ? '' : File.join(source_dir_args, name)
73
+
74
+ src_dir = if name.blank?
75
+ Dir.pwd
76
+ else
77
+ File.join(source_dir_args, name)
78
+ end
79
+
63
80
  port = 2000
64
81
 
65
82
  ready = false
@@ -67,11 +84,12 @@ class Project < Thor
67
84
  Thread.new do
68
85
  while !ready
69
86
  end
70
- `adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.client/.CanvasActivity`
87
+ `adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.application/.CanvasActivity`
71
88
  launch(device_ip, "http://#{host_name_args}:#{port}/config.droiuby")
72
89
  end
73
90
 
74
91
  puts "Starting server: http://#{host_name_args}:#{port}"
92
+ puts "Document root #{src_dir}"
75
93
  server = HTTPServer.new(:Port=>port,:DocumentRoot=> src_dir,:StartCallback => Proc.new {
76
94
  ready = true
77
95
  })
@@ -82,11 +100,24 @@ class Project < Thor
82
100
 
83
101
  desc "upload NAME DEVICE_IP [WORKSPACE_DIR]","uploads a droiuby application to target device running droiuby client"
84
102
  def upload(name, device_ip, source_dir = 'projects')
85
- src_package = File.join(source_dir,name,'build',"#{name}.zip")
103
+
104
+ source_dir = if name.blank?
105
+ Dir.pwd
106
+ else
107
+ File.join(source_dir, name)
108
+ end
109
+
110
+ src_package = unless name.blank?
111
+ File.join(source_dir,name,'build',"#{name}.zip")
112
+ else
113
+ name = File.basename(source_dir)
114
+ File.join(source_dir,'build',"#{name}.zip")
115
+ end
116
+
86
117
 
87
118
  url_str = "http://#{device_ip}:4000/upload"
88
119
  uri = URI.parse(url_str)
89
- say "uploading to #{url_str} -> #{uri.host}:#{uri.port}"
120
+ say "uploading #{src_package} to #{url_str} -> #{uri.host}:#{uri.port}"
90
121
  File.open(src_package) do |zip|
91
122
  req = Net::HTTP::Post::Multipart.new uri.path,
92
123
  "name" => name,
@@ -94,6 +125,8 @@ class Project < Thor
94
125
  "file" => UploadIO.new(zip, "application/zip", src_package,"content-disposition" => "form-data; name=\"file\"; filename=\"#{File.basename(src_package)}\"\r\n")
95
126
 
96
127
  retries = 0
128
+ res = nil
129
+
97
130
  while (retries < 3)
98
131
  sleep 1 + retries
99
132
  begin
@@ -106,13 +139,17 @@ class Project < Thor
106
139
  next
107
140
  end
108
141
  end
142
+
143
+ if res && res.code == "200"
109
144
 
110
-
111
- if res.code == "200"
112
145
  say_status 'upload', src_package
113
146
  else
114
- say 'upload failed.'
115
- say res.body
147
+ if res
148
+ say_status 'upload','res.body', :red
149
+ else
150
+ say_status 'upload',"upload failed. cannot connect to #{url_str}", :red
151
+ end
152
+
116
153
  end
117
154
 
118
155
  end
@@ -120,7 +157,7 @@ class Project < Thor
120
157
 
121
158
  desc "execute NAME DEVICE_IP [WORKSPACE_DIR]","package and execute a droiuby application to target device running droiuby client"
122
159
  def execute(name, device_ip, source_dir = 'projects')
123
- `adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.client/.CanvasActivity`
160
+ `adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.application/.CanvasActivity`
124
161
  package name, source_dir, "true"
125
162
  upload name, device_ip, source_dir
126
163
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droiuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-07 00:00:00.000000000 Z
12
+ date: 2013-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -27,22 +27,6 @@ dependencies:
27
27
  none: false
28
28
  prerelease: false
29
29
  type: :runtime
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- version_requirements: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - '>='
35
- - !ruby/object:Gem::Version
36
- version: '0'
37
- none: false
38
- requirement: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - '>='
41
- - !ruby/object:Gem::Version
42
- version: '0'
43
- none: false
44
- prerelease: false
45
- type: :runtime
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: thor
48
32
  version_requirements: !ruby/object:Gem::Requirement