| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define(function(require){ var module = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var data = require('data') | 
					
						
							|  |  |  | var images = require('images') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | var base = require('features/base') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-01-01 01:58:55 +03:00
										 |  |  | // XXX what we need here is:
 | 
					
						
							|  |  |  | // 		- base introspection
 | 
					
						
							|  |  |  | // 			- list features
 | 
					
						
							|  |  |  | // 			- list actions
 | 
					
						
							|  |  |  | // 			- list action scripts / commands
 | 
					
						
							|  |  |  | // 		- call action
 | 
					
						
							|  |  |  | // 		- call action script (a-la git commands)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // XXX the main functionality:
 | 
					
						
							|  |  |  | // 		- make previews
 | 
					
						
							|  |  |  | // 		- make index
 | 
					
						
							|  |  |  | // 		- merge
 | 
					
						
							|  |  |  | // 		- clone
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | //
 | 
					
						
							|  |  |  | // XXX a different approach to this would be an "external" cli controller
 | 
					
						
							|  |  |  | // 		script that would contain only cli code and load the ImageGrid
 | 
					
						
							|  |  |  | // 		only in the handler...
 | 
					
						
							|  |  |  | // 			+ would be allot faster to load.
 | 
					
						
							|  |  |  | // 			+ more flexible as we can load more than one instance...
 | 
					
						
							|  |  |  | // 		This could still be done via features, just load the cli feature
 | 
					
						
							|  |  |  | // 		alone at first and then either create new instances or setup 
 | 
					
						
							|  |  |  | // 		additional features as needed...
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var CLIActions = actions.Actions({ | 
					
						
							|  |  |  | 	makeIndex: ['- System/', | 
					
						
							|  |  |  | 		function(path){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return this.loadImages(path) | 
					
						
							|  |  |  | 				.then(function(){ return that.makePreviews('all') }) | 
					
						
							|  |  |  | 				.then(function(){ return that.sortImages() }) | 
					
						
							|  |  |  | 				//.then(function(){ return that.readAllMetadata() })
 | 
					
						
							|  |  |  | 				.then(function(){ return that.saveIndex() }) | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | var CLI =  | 
					
						
							|  |  |  | module.CLI = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'commandline', | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'lifecycle' | 
					
						
							|  |  |  | 	], | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	isApplicable: function(){  | 
					
						
							| 
									
										
										
										
											2016-01-01 02:22:17 +03:00
										 |  |  | 		return this.runtime == 'node' || this.runtime == 'nw' }, | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 	actions: CLIActions, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		['start', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 				var that = this | 
					
						
							| 
									
										
										
										
											2015-12-31 22:58:41 +03:00
										 |  |  | 				// get the arguments...
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 				if(this.runtime == 'nw'){ | 
					
						
							|  |  |  | 					var argv = requirejs('nw.gui').App.argv | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 19:41:11 +03:00
										 |  |  | 					// XXX appears to have a stray '--help' lodged in 
 | 
					
						
							|  |  |  | 					// 		all the time...
 | 
					
						
							|  |  |  | 					// 		...need to test this with a packed exec...
 | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 					console.log('>>>>', argv) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 				} else if(this.runtime == 'node'){ | 
					
						
							|  |  |  | 					var argv = process.argv | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 10:37:21 +03:00
										 |  |  | 				var cli = requirejs('commander') | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 				cli | 
					
						
							| 
									
										
										
										
											2015-12-31 22:58:41 +03:00
										 |  |  | 					// XXX get the version from config...
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 					.version('0.0.1') | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 					//.usage('[command] [options] ..')
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 					// list features...
 | 
					
						
							|  |  |  | 					// XXX make this a core action... (???)
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 					.option('lf, --list-features', 'list loaded features', function(){ | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 						// excluded...
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 						that.features.excluded.length > 0  | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 							&& console.warn('Features excluded (%d):\n   ', | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 								that.features.excluded.length,  | 
					
						
							|  |  |  | 								that.features.excluded.join('\n    ')) | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// not applicable...
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 						that.features.unapplicable.length > 0  | 
					
						
							|  |  |  | 							&& console.log('Features not applicable (%d):\n   ',  | 
					
						
							|  |  |  | 								that.features.unapplicable.length,  | 
					
						
							|  |  |  | 								that.features.unapplicable.join('\n    ')) | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// loaded...
 | 
					
						
							|  |  |  | 						console.log('Features loaded (%d):\n   ', | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 							that.features.features.length,  | 
					
						
							|  |  |  | 							that.features.features.join('\n    ')) | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2016-04-19 19:55:11 +03:00
										 |  |  | 					// XXX make this applicable features...
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 					.option('laf, --list-available-features', 'list available features', function(){ | 
					
						
							| 
									
										
										
										
											2016-04-19 19:55:11 +03:00
										 |  |  | 						// XXX bug, this hangs....
 | 
					
						
							|  |  |  | 						//console.log(core.ImageGridFeatures.buildFeatureList())
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 						var f = core.ImageGridFeatures.features | 
					
						
							|  |  |  | 						console.log('Features available (%d):\n   ', | 
					
						
							|  |  |  | 							f.length,  | 
					
						
							|  |  |  | 							f.join('\n    ')) | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// list actions...
 | 
					
						
							|  |  |  | 					// XXX this is a bit pointless as single actions are
 | 
					
						
							|  |  |  | 					// 		meaningless when no state is stored...
 | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 					.option('la, --list-actions', 'list loaded actions', function(){ | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 						console.log('Actions loaded (%d):\n   ',  | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 							that.length,  | 
					
						
							|  |  |  | 							Object.keys(that.getDoc()).join('\n    ')) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// XXX experimental....
 | 
					
						
							|  |  |  | 					// 		to see this in action use:
 | 
					
						
							|  |  |  | 					// 			ig lf sm lf
 | 
					
						
							|  |  |  | 					// 		...this will print the list of features before
 | 
					
						
							|  |  |  | 					// 		and after setup...
 | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 					.option('sm, --setup-minimal', 'setup minimal features', function(){ | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 						// load features we might need...
 | 
					
						
							| 
									
										
										
										
											2016-04-19 19:55:11 +03:00
										 |  |  | 						var all = require('features/all') | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// extend the current instance to a minimal non-ui
 | 
					
						
							|  |  |  | 						// state...
 | 
					
						
							|  |  |  | 						core.ImageGridFeatures | 
					
						
							|  |  |  | 							.setup(that, ['viewer-minimal']) | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 					.option('repl, --repl', 'start an ImageGrin REPL', function(){ | 
					
						
							|  |  |  | 						//var repl = require('repl')
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						//var ig = core.ImageGridFeatures
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						repl.start({ | 
					
						
							|  |  |  | 							prompt: 'ig> ', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							input: process.stdin, | 
					
						
							|  |  |  | 							output: process.stdout, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							ignoreUndefined: true, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							/* | 
					
						
							|  |  |  | 							eval: function(str, context, filename, callback){ | 
					
						
							|  |  |  | 								var res | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								var lst = str.split(/\s+/) | 
					
						
							|  |  |  | 								var cmd = lst.shift() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// we got an action...
 | 
					
						
							|  |  |  | 								if(cmd == 'var'){ | 
					
						
							|  |  |  | 									eval(str, context, filename, callback) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// action...
 | 
					
						
							|  |  |  | 								} else if(cmd in ig){ | 
					
						
							|  |  |  | 									ig[cmd].apply(ig, lst.map(eval)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// err
 | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									// XXX
 | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								callback(null, res) | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							*/ | 
					
						
							|  |  |  | 						}) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-03 03:03:36 +03:00
										 |  |  | 					// XXX the problem with this is that it still tires 
 | 
					
						
							|  |  |  | 					// 		to find and run 'ig-index'...
 | 
					
						
							|  |  |  | 					/* | 
					
						
							|  |  |  | 					.command('index [path]', 'build an index of path', function(path){ | 
					
						
							|  |  |  | 						console.log('!!!!!! INDEX', path) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 					*/ | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-23 00:07:04 +03:00
										 |  |  | 					// XXX might be a good idea to make the action call
 | 
					
						
							|  |  |  | 					// 		syntax like this:
 | 
					
						
							|  |  |  | 					// 			--<action-name> [args]
 | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 					.arguments('<action> [args]') | 
					
						
							|  |  |  | 					.action(function(action, args){ | 
					
						
							| 
									
										
										
										
											2016-01-01 01:58:55 +03:00
										 |  |  | 						// XXX
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 						//console.log('>>>>', action, args, !!that[action])
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						that[action](args) | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 					.parse(argv) | 
					
						
							|  |  |  | 			}] | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							|  |  |  | return module }) |