| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define(function(require){ var module = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 23:49:01 +03:00
										 |  |  | var util = require('lib/util') | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 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-05-29 23:49:01 +03:00
										 |  |  | if(typeof(process) != 'undefined'){ | 
					
						
							|  |  |  | 	var pathlib = requirejs('path') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-27 18:41:28 +03:00
										 |  |  | 			// XXX is this correct???
 | 
					
						
							|  |  |  | 			path = path || this.location.path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 23:49:01 +03:00
										 |  |  | 			path = util.normalizePath(path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 			return this.loadImages(path) | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 				.then(function(){  | 
					
						
							| 
									
										
										
										
											2016-05-28 19:32:30 +03:00
										 |  |  | 					// save base index...
 | 
					
						
							| 
									
										
										
										
											2016-05-28 16:29:57 +03:00
										 |  |  | 					that.saveIndex(path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-28 19:32:30 +03:00
										 |  |  | 					// make the previews...
 | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 					that.makePreviews('all') | 
					
						
							| 
									
										
										
										
											2016-05-28 16:29:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 					//that.readAllMetadata()
 | 
					
						
							| 
									
										
										
										
											2016-05-28 19:32:30 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 					that | 
					
						
							|  |  |  | 						.sortImages() | 
					
						
							|  |  |  | 						// XXX for some reason this is not running from cli
 | 
					
						
							|  |  |  | 						.saveIndex(path) | 
					
						
							|  |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 		}], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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'){ | 
					
						
							| 
									
										
										
										
											2016-05-28 16:29:57 +03:00
										 |  |  | 					var argv = nw.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 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 				var package = requirejs('fs-extra').readJSONSync('./package.json') | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 10:37:21 +03:00
										 |  |  | 				var cli = requirejs('commander') | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 				cli | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 					// XXX get the version from package.json...
 | 
					
						
							|  |  |  | 					.version(package.version) | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 					//.usage('[command] [options] ..')
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-28 18:31:42 +03:00
										 |  |  | 					.option('-v, --verbose', 'verbose mode', function(){ | 
					
						
							|  |  |  | 						that.logger = {  | 
					
						
							|  |  |  | 							emit: function(){ console.log.apply(console, arguments) }  | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-28 18:31:42 +03:00
										 |  |  | 					.option('repl, --repl', 'start an ImageGrid REPL', function(){ | 
					
						
							|  |  |  | 						var repl = requirejs('repl') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// setup the global ns...
 | 
					
						
							|  |  |  | 						global.ig = | 
					
						
							|  |  |  | 						global.ImageGrid =  | 
					
						
							|  |  |  | 							that | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						require('features/all') | 
					
						
							|  |  |  | 						global.ImageGridFeatures = core.ImageGridFeatures | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						//var ig = core.ImageGridFeatures
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						repl.start({ | 
					
						
							|  |  |  | 							prompt: 'ig> ', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							input: process.stdin, | 
					
						
							|  |  |  | 							output: process.stdout, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 							//ignoreUndefined: true,
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 						}) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 					// XXX this needs both a local/linked nwjs installed and an 
 | 
					
						
							|  |  |  | 					// 		appropriate nw version under it...
 | 
					
						
							|  |  |  | 					// 			npm install -g nwjs
 | 
					
						
							|  |  |  | 					// 			npm link nwjs
 | 
					
						
							|  |  |  | 					// 			nw install 0.14.5-sdk
 | 
					
						
							|  |  |  | 					.option('gui, --gui', 'start ImageGrid.Viewer', function(){ | 
					
						
							|  |  |  | 						var path = requirejs('path') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						requirejs('child_process') | 
					
						
							|  |  |  | 							.spawn(requirejs('nwjs'), [ | 
					
						
							|  |  |  | 								path.dirname(process.argv[1]).replace(/\\/g, '/') + '/']) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-28 18:31:42 +03:00
										 |  |  | 						//console.log('>>>>', action, args, !!that[action])
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						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 }) |