Class: Cova

Inherits:
Thor
  • Object
show all
Includes:
CovaConfig, CovaIO, CovaLog
Defined in:
lib/covamain.rb

Instance Method Summary collapse

Methods included from CovaIO

#_io_app_exists, #_io_clone_repo, #_io_cpdir, #_io_cpfile, #_io_exec, #_io_exec_xctool, #_io_init, #_io_isdir, #_io_isfile, #_io_lndir, #_io_ls, #_io_mkdir, #_io_open_app_source, #_io_pod_add_repo, #_io_rmdir

Methods included from CovaLog

#_log_block_error, #_log_block_start, #_log_block_success, #_log_info, #_log_line, #_log_line_error, #_log_line_ok

Methods included from CovaConfig

#_config_load

Constructor Details

#initialize(*args) ⇒ Cova

Returns a new instance of Cova.



7
8
9
10
# File 'lib/covamain.rb', line 7

def initialize(*args)
  super
  _io_init
end

Instance Method Details

#build(name) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/covamain.rb', line 301

def build (name)
	if not _cova_installed
			_cova_prompt_install
			return false
		end

	if not _io_app_exists name
		_log_line "App #{name} does not exist"
		_log_line_error
		return false
	end

	Dir.chdir(@dir_cova_apps_home + "/" + name + "/ios")
		_log_block_start "Building app #{name}"
 	if options[:dependencies] or not _io_isfile "Cova.xcworkspace" or not _io_isdir "Pods"
  	if not _cova_build_dependencies
  		_log_block_error
  		return false
  	end
		end

		_io_exec_xctool (options[:tests] ? "test" : "build")
		_io_open_app_source name
end

#create(name) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/covamain.rb', line 190

def create (name)

		if not _cova_installed
			_cova_prompt_install
			return false
		end

  	appname = name.strip.delete(' ')
  	_log_block_start "Creating Cova app #{appname}"
  	dir = Dir.pwd + "/" + appname

  	if _io_isdir dir, false or _io_app_exists appname or not _io_mkdir dir or not _io_lndir dir, @dir_cova_apps_home + "/" + appname
  		_log_block_error
  		return false
  	end

  	if not _io_cpfile @dir_cova_home + "/cova/config/app.config", dir + "/app.config"
			_log_block_error
  		return false
  	end

  	if _io_cpdir @dir_cova_home + "/cova/web/app", dir + "/www"
  		config_content = File.read(dir + "/www/config.php")
  		config_content = config_content.gsub(/%cova_home%/, @dir_cova_home)
			File.open(dir + "/www/config.php", 'w') { |file| file.puts config_content }
  	end
  		
  	if _io_cpdir @dir_cova_home + "/cova/ios", dir + "/ios"
 	Dir.chdir(@dir_cova_apps_home + "/" + name + "/ios")
   	
   	#project  = Xcodeproj::Project.new "Cova.xcodeproj"
			#target = project.targets[0]
			#test_target = project.targets[1]
			#test_debug_build_settings = test_target.build_configuration_list.build_configurations[1].build_settings

			# puts test_debug_build_settings
		# target.name = name
			# project.targets[1].name = "#{name}Tests"
			
			#release_build_settings = target.build_configuration_list.build_configurations[0].build_settings
			#debug_build_settings = target.build_configuration_list.build_configurations[1].build_settings
			#project.save_as("Cova.xcodeproj")

  		if options[:build]
   	if not _cova_build_dependencies
   		_log_line "Attempted to build the app dependencies"
   		_log_line_error
 	 		return false
  		end
  			
_io_exec_xctool "test"
_io_open_app_source name
  			return true
  		end

	  	_log_block_success
   	return true
  	end

		_log_block_error
  	return false
end

#deploy(name) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/covamain.rb', line 254

def deploy (name)
	if not _cova_installed
			_cova_prompt_install
			return false
		end

	if not _io_app_exists name
		_log_line "App #{name} does not exist"
		_log_line_error
		return false
	end

	Dir.chdir(@dir_cova_apps_home + "/" + name)
	if not _io_isfile "app.config"
		_log_line "App configuration file app.config does not exist."
		_log_line_error
  _log_info "Please add the app.config file."
  return false
	end

	config = _config_load "app.config"
	deploy_dir = config['local.www']
	if not deploy_dir
			_log_line "Expecting the local.www path to be configured."
		_log_line_error			
		_log_info "Please set the local.www path in your app.config file."
  return false
	end

 if _io_isdir "www" and _io_isdir deploy_dir
 	`rm -rf #{deploy_dir}/*`
 	`rm -rf #{deploy_dir}/.htaccess`
			`cp -r www/* #{deploy_dir}`
			`cp www/.htaccess #{deploy_dir}/.htaccess`	
			_log_line "Deploying the app to #{deploy_dir}"
			_log_line_ok	
		return true
		end
	
		_log_line "Deploying the app to #{deploy_dir}"
		_log_line_error			
  return false
end

#find(name) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/covamain.rb', line 77

def find(name)
		if not _cova_installed
			_cova_prompt_install
			return false
		end

		_log_line "Searching for app #{name}"
		if _io_app_exists name
			_log_line_ok
			return true
		end

		_log_line_error
		return false
end

#imageObject



181
182
183
184
185
186
# File 'lib/covamain.rb', line 181

def image ()
	png = ChunkyPNG::Image.new(320, 480, ChunkyPNG::Color::TRANSPARENT)
		png[1,1] = ChunkyPNG::Color.rgba(10, 20, 30, 128)
		png[2,1] = ChunkyPNG::Color('black @ 0.5')
		png.save('Default.png', :interlace => true)
end

#installObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/covamain.rb', line 38

def install
  _log_block_start "Installing Cova"

  if _io_isdir(@dir_cova_home, false) or _io_isdir(@dir_cova_ios_mods_home, false)
	  _log_info "It looks like Cova is already installed. Please uninstall it first before installing again."	  	 
	  _log_block_error
	  return false
  end

  if _io_mkdir @dir_cova_home and _io_mkdir @dir_cova_apps_home and _io_mkdir @dir_cocoapods_home
  	  if _io_clone_repo @repo_xctool, @dir_cova_home and _io_clone_repo @repo_cova, @dir_cova_home
  	  	  if _io_pod_add_repo "cova", @repo_cova_ios_mods
		  	  _log_block_success
		  	  puts
 				  puts "Congrats! Cove is now installed. Enjoy and build the next great app sensation!".green
 				  puts
 			  	  puts "For more info check out http://cova.io"
 			 	  puts
	  	  	  return true
	  	  end
	  end
  end

  _log_block_error
  return false
end

#listObject



66
67
68
69
70
71
72
73
74
# File 'lib/covamain.rb', line 66

def list
		if not _cova_installed
			_cova_prompt_install
			return false
		end

		_io_ls @dir_cova_apps_home
		return true
end

#newapp(name) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/covamain.rb', line 94

def newapp (name)

	#	`cp -r Cova #{name}`
	#	app_root = "#{name}"
#	Dir.chdir app_root

#	_io_exec "pod repo update cova"
	#	_io_exec "pod install"
	#	_io_exec "open Cova.xcworkspace"

#		`mv app.xcodeproj #{name}.xcodeproj`	
 #   	project  = Xcodeproj::Project.new "#{name}.xcodeproj"
#		target = project.targets[0]
 #   	target.name = name
#		project.targets[1].name = "#{name}Tests"

#		debug_build_settings = target.build_configuration_list.build_configurations[1].build_settings

	# `cp ../cova/cova/cova-Info.plist #{name}-Info.plist`
	# `cp ../cova/cova/AppDelegate.h AppDelegate.h`
	# `cp ../cova/cova/AppDelegate.m AppDelegate.m`
	# `cp ../cova/cova/cova-Prefix.pch #{name}-Prefix.pch`
	# `cp ../cova/cova/main.m main.m`
		#info_plist_file = project.new_file("app-Info.plist")
		#pch_file = project.new_file("#{name}-Prefix.pch")
		# main_file = project.new_file("main.m")
		# delegate_h_file = project.new_file("AppDelegate.h")
		# delegate_m_file = project.new_file("AppDelegate.m")
		# target.add_file_references([main_file, delegate_h_file, delegate_m_file])
  #       release_build_settings = target.build_configuration_list.build_configurations[0].build_settings
  #       release_build_settings['INFOPLIST_FILE'] = "#{name}-Info.plist"
  #       release_build_settings['GCC_PREFIX_HEADER'] = "#{name}-Prefix.pch"
		# debug_build_settings = target.build_configuration_list.build_configurations[1].build_settings
  #       debug_build_settings['INFOPLIST_FILE'] = "#{name}-Info.plist"
  #       debug_build_settings['GCC_PREFIX_HEADER'] = "#{name}-Prefix.pch"
		# project.add_system_framework "CoreData", target
  #   	project.add_system_framework "UIKit", target
  #   	project.add_system_framework "Foundation", target

#		project.save_as("#{name}.xcodeproj")
#		_io_exec "open #{name}.xcodeproj"

    #debug_build_settings['PRODUCT_NAME'] = name
    #puts 
    #puts debug_build_settings['PRODUCT_NAME'] 

	#puts project.pretty_print

	#info_plist = project.main_group.new_file("#{name}-Info.plist")
		#target.add_file_references([info_plist])

	#debug = project.build_configurations
	#pp debug

	#config   = project.configuration_list :ios
		
		#project.add_system_framework "CoreData", target
	#project.add_system_framework "UIKit", target
	#project.add_system_framework "Foundation", target

	#src = project.new_group "src"
	#res = project.new_group "res"
	#test = project.new_group "test"

		#File.open("src/main.m", 'w') {|f| f.write("#import <UIKit/UIKit.h>\r\n#import \"AppDelegate.h\"\r\nint main(int argc, char *argv[]) {\r\n@autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }\r\n}")}
		#File.open("src/AppDelegate.h", 'w') {|f| f.write("#import <UIKit/UIKit.h>\r\n@interface AppDelegate : UIResponder <UIApplicationDelegate>\r\n @property (strong, nonatomic) UIWindow *window; \r\n@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; \r\n@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; \r\n@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; \r\n- (void)saveContext; \r\n- (NSURL *)applicationDocumentsDirectory; \r\n@end")}
		#main_file = src.new_file("src/main.m")
		#delegate_file = src.new_file("src/AppDelegate.h")
		
		#project.save_as("#{name}.xcodeproj")

		#File.open("Podfile", 'w') {|f| f.write("platform :ios, '5.0'\r\npod 'covamod-core'")}
		#_io_exec "pod setup"
		#_io_exec "pod repo update cova"
		#_io_exec "pod install"
		#_io_exec "open #{name}.xcworkspace"
		
		#_io_exec "open #{name}.xcodeproj"
end

#setupObject



175
176
177
178
# File 'lib/covamain.rb', line 175

def setup ()
	_io_exec "curl -fsSL https://raw.github.com/mxcl/homebrew/go"
		_io_exec "brew update"
end

#statusObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/covamain.rb', line 13

def status
   _log_block_start "Checking if Cova is installed"
   if _io_isdir(@dir_cova_home) and _io_isdir(@dir_cova_ios_mods_home)
   		_log_block_success
   		return true
   end
   _log_block_error
   _cova_prompt_install
   return false
end

#uninstallObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/covamain.rb', line 25

def uninstall
   _log_block_start "Uninstalling Cova"
   _io_rmdir(@dir_cova_home)
   _io_rmdir(@dir_cova_ios_mods_home)
   if _io_isdir(@dir_cova_home, false) or _io_isdir(@dir_cova_ios_mods_home, false)
   		_log_block_error
   		return false
   end
   _log_block_success
   return true
end