| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 16:12:10 +03:00
										 |  |  | var data = require('imagegrid/data') | 
					
						
							|  |  |  | var images = require('imagegrid/images') | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 17:51:26 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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)
 | 
					
						
							| 
									
										
										
										
											2020-06-24 02:26:40 +03:00
										 |  |  | // 		- repl (debug/testing)
 | 
					
						
							| 
									
										
										
										
											2016-01-01 01:58:55 +03:00
										 |  |  | //
 | 
					
						
							|  |  |  | // 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({ | 
					
						
							| 
									
										
										
										
											2018-12-20 15:28:24 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	get cli_commands(){ | 
					
						
							|  |  |  | 		return this.actions | 
					
						
							|  |  |  | 			.filter(function(action){ | 
					
						
							|  |  |  | 				return this.getActionAttr(action, 'cli') }.bind(this)) }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-20 04:40:30 +03:00
										 |  |  | 	// XXX should this be here???
 | 
					
						
							|  |  |  | 	// 		...move this to progress...
 | 
					
						
							|  |  |  | 	__progress: null, | 
					
						
							|  |  |  | 	showProgress: ['- System/', | 
					
						
							|  |  |  | 		function(text, value, max){ | 
					
						
							|  |  |  | 			var msg = text instanceof Array ? text.slice(1).join(': ') : null | 
					
						
							|  |  |  | 			text = text instanceof Array ? text[0] : text | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var state = this.__progress = this.__progress || {} | 
					
						
							|  |  |  | 			state = state[text] = state[text] || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// normalize max and value...
 | 
					
						
							|  |  |  | 			max = state.max = max != null ?  | 
					
						
							|  |  |  | 					(typeof(max) == typeof('str') && /[+-][0-9]+/.test(max) ?  | 
					
						
							|  |  |  | 						(state.max || 0) + parseInt(max) | 
					
						
							|  |  |  | 					: max) | 
					
						
							|  |  |  | 				: state.max | 
					
						
							|  |  |  | 			value = state.value = value != null ?  | 
					
						
							|  |  |  | 					(typeof(value) == typeof('str') && /[+-][0-9]+/.test(value) ?  | 
					
						
							|  |  |  | 						(state.value || 0) + parseInt(value) | 
					
						
							|  |  |  | 					: value) | 
					
						
							|  |  |  | 				: state.value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// format the message...
 | 
					
						
							|  |  |  | 			msg = msg ? ': '+msg : '' | 
					
						
							|  |  |  | 			msg = ' '+ msg  | 
					
						
							|  |  |  | 				//+ (value && value >= (max || 0) ? ' ('+value+' done)' 
 | 
					
						
							|  |  |  | 				+ (value && value >= (max || 0) ? ' (done)'  | 
					
						
							|  |  |  | 					: value && max && value != max ? ' ('+ value +' of '+ max +')' | 
					
						
							|  |  |  | 					: '...') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			msg != state.msg | 
					
						
							|  |  |  | 				&& console.log(msg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			state.msg = msg | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 	makeIndex: ['- System/', | 
					
						
							| 
									
										
										
										
											2018-12-20 15:28:24 +03:00
										 |  |  | 		{cli: true}, | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 		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-06-03 04:46:51 +03:00
										 |  |  | 				// save base index...
 | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 				.then(function(){  | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 					return that.saveIndex(path) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				// make the previews...
 | 
					
						
							|  |  |  | 				.then(function(){ | 
					
						
							| 
									
										
										
										
											2018-12-20 04:40:30 +03:00
										 |  |  | 					if(that.makePreviews){ | 
					
						
							|  |  |  | 						return that.makePreviews('all') | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 				}) | 
					
						
							|  |  |  | 				.then(function(){ | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 					//that.readAllMetadata()
 | 
					
						
							| 
									
										
										
										
											2016-05-28 19:32:30 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 					return that | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 						.sortImages() | 
					
						
							|  |  |  | 						// XXX for some reason this is not running from cli
 | 
					
						
							|  |  |  | 						.saveIndex(path) | 
					
						
							|  |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 		}], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-23 22:54:40 +03:00
										 |  |  | // XXX revise architecture....
 | 
					
						
							| 
									
										
										
										
											2020-06-09 16:48:23 +03:00
										 |  |  | // XXX move this to the argv parser used in object.js
 | 
					
						
							| 
									
										
										
										
											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: [ | 
					
						
							| 
									
										
										
										
											2020-06-09 16:48:23 +03:00
										 |  |  | 		'lifecycle', | 
					
						
							|  |  |  | 		'logger', | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 	], | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 08:08:40 +03:00
										 |  |  | 	// XXX should this be ONLY node???
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 	isApplicable: function(){  | 
					
						
							| 
									
										
										
										
											2017-10-04 08:08:40 +03:00
										 |  |  | 		return this.runtime.node && !this.runtime.browser }, | 
					
						
							| 
									
										
										
										
											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: [ | 
					
						
							| 
									
										
										
										
											2019-01-19 18:20:06 +03:00
										 |  |  | 		// XXX should some of the flag handlers be actions???
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 		['ready', | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 			function(){ | 
					
						
							| 
									
										
										
										
											2016-01-03 04:49:00 +03:00
										 |  |  | 				var that = this | 
					
						
							| 
									
										
										
										
											2018-12-20 15:07:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 22:58:41 +03:00
										 |  |  | 				// get the arguments...
 | 
					
						
							| 
									
										
										
										
											2017-10-04 08:08:40 +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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 08:08:40 +03:00
										 |  |  | 				} else if(this.runtime.node){ | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 					var argv = process.argv | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				var keep_running = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 				// XXX this is not portable...
 | 
					
						
							|  |  |  | 				//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...
 | 
					
						
							| 
									
										
										
										
											2018-01-12 21:59:08 +03:00
										 |  |  | 					.version(that.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(){ | 
					
						
							| 
									
										
										
										
											2017-03-01 00:05:10 +03:00
										 |  |  | 						// XXX use a standard logger...
 | 
					
						
							| 
									
										
										
										
											2016-05-28 18:31:42 +03:00
										 |  |  | 						that.logger = {  | 
					
						
							| 
									
										
										
										
											2017-03-01 00:05:10 +03:00
										 |  |  | 							root: true, | 
					
						
							|  |  |  | 							push: function(){  | 
					
						
							|  |  |  | 								var o = Object.create(this)  | 
					
						
							|  |  |  | 								o.root = false | 
					
						
							| 
									
										
										
										
											2018-11-12 23:04:00 +03:00
										 |  |  | 								o.__prefix = (this.__prefix || []).concat([...arguments]) | 
					
						
							| 
									
										
										
										
											2017-03-01 00:05:10 +03:00
										 |  |  | 								return o | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							pop: function(){ | 
					
						
							|  |  |  | 								return this.root ? this : this.__proto__ | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							emit: function(){  | 
					
						
							|  |  |  | 								console.log.apply(console,  | 
					
						
							| 
									
										
										
										
											2018-11-12 23:04:00 +03:00
										 |  |  | 									(this.__prefix || []).concat([...arguments])) | 
					
						
							| 
									
										
										
										
											2017-03-01 00:05:10 +03:00
										 |  |  | 							},  | 
					
						
							| 
									
										
										
										
											2016-05-28 18:31:42 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-20 15:28:24 +03:00
										 |  |  | 					.option('l, --list-commands', 'list commands', function(){ | 
					
						
							|  |  |  | 						console.log('Commands:\n   ', that.cli_commands.join('\n\t')) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2017-12-09 03:14:36 +03:00
										 |  |  | 							.setup(that, ['imagegrid-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(){ | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 						var repl = nodeRequire('repl') | 
					
						
							| 
									
										
										
										
											2016-05-28 18:31:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 						keep_running = true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-28 18:31:42 +03:00
										 |  |  | 						// 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
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 						 | 
					
						
							|  |  |  | 						repl | 
					
						
							|  |  |  | 							.start({ | 
					
						
							|  |  |  | 								prompt: 'ig> ', | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 								useGlobal: true, | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 								input: process.stdin, | 
					
						
							|  |  |  | 								output: process.stdout, | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 								//ignoreUndefined: true,
 | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 							.on('exit', function(){ | 
					
						
							|  |  |  | 								ig.stop() | 
					
						
							|  |  |  | 							}) | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							| 
									
										
										
										
											2019-01-17 17:51:26 +03:00
										 |  |  | 					.option('nw, --nw', 'start ImageGrid.Viewer (nw)', function(){ | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 						throw new Error('ig: GUI startup not implemented.') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 						var path = requirejs('path') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						requirejs('child_process') | 
					
						
							|  |  |  | 							.spawn(requirejs('nwjs'), [ | 
					
						
							|  |  |  | 								path.dirname(process.argv[1]).replace(/\\/g, '/') + '/']) | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						keep_running = true | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2019-01-17 17:51:26 +03:00
										 |  |  | 					.option('electron, --electron', 'start ImageGrid.Viewer (electron)', function(){ | 
					
						
							|  |  |  | 						var path = requirejs('path') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						requirejs('child_process') | 
					
						
							|  |  |  | 							.spawn(requirejs('electron'), [ | 
					
						
							|  |  |  | 									path.join( | 
					
						
							|  |  |  | 										path.dirname(nodeRequire.main.filename),  | 
					
						
							|  |  |  | 										'e.js')]) | 
					
						
							|  |  |  | 							// XXX need to stop the process iff nothing 
 | 
					
						
							|  |  |  | 							// 		else is running, like repl... 
 | 
					
						
							|  |  |  | 							// XXX feels hackish...
 | 
					
						
							|  |  |  | 							.on('exit', function(){ | 
					
						
							|  |  |  | 								(!global.ig | 
					
						
							|  |  |  | 										|| global.ig.isStopped()) | 
					
						
							|  |  |  | 									&& process.exit() | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						keep_running = true | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2016-05-29 19:50:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-20 15:07:42 +03:00
										 |  |  | 					/* // XXX the problem with this is that it still tires  | 
					
						
							| 
									
										
										
										
											2016-01-03 03:03:36 +03:00
										 |  |  | 					// 		to find and run 'ig-index'...
 | 
					
						
							| 
									
										
										
										
											2018-12-20 15:07:42 +03:00
										 |  |  | 					.command('index [path]', 'build an index of path') | 
					
						
							|  |  |  | 					.action(function(path){ | 
					
						
							| 
									
										
										
										
											2016-01-03 03:03:36 +03:00
										 |  |  | 						console.log('!!!!!! INDEX', path) | 
					
						
							| 
									
										
										
										
											2018-12-20 15:07:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						//this.makeIndex(path)
 | 
					
						
							| 
									
										
										
										
											2016-01-03 03:03:36 +03:00
										 |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2018-12-20 15:07:42 +03:00
										 |  |  | 					//*/
 | 
					
						
							| 
									
										
										
										
											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])
 | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 						if(!that[action]){ | 
					
						
							|  |  |  | 							console.error('No such action:', action) | 
					
						
							|  |  |  | 							return | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-20 15:07:42 +03:00
										 |  |  | 						var res = that[action](args) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						if(res instanceof Promise){ | 
					
						
							|  |  |  | 							keep_running = true | 
					
						
							|  |  |  | 							res.then(function(){ | 
					
						
							|  |  |  | 								process.exit() | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 					.parse(argv) | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 				// XXX is this the right way to trigger state change 
 | 
					
						
							|  |  |  | 				// 		from within a state action...
 | 
					
						
							| 
									
										
										
										
											2018-12-11 17:18:02 +03:00
										 |  |  | 				!keep_running | 
					
						
							| 
									
										
										
										
											2018-12-12 00:53:17 +03:00
										 |  |  | 					&& this.afterAction(function(){ process.exit() }) | 
					
						
							|  |  |  | 			}], | 
					
						
							| 
									
										
										
										
											2015-12-31 07:00:18 +03:00
										 |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							|  |  |  | return module }) |