| 
									
										
										
										
											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') | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 	var argv = requirejs('lib/argv') | 
					
						
							| 
									
										
										
										
											2016-05-29 23:49:01 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 	get cliActions(){ | 
					
						
							| 
									
										
										
										
											2018-12-20 15:28:24 +03:00
										 |  |  | 		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 | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 	startREPL: ['- System/Start CLI interpreter', | 
					
						
							|  |  |  | 		{cli: '@repl'}, | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			var repl = nodeRequire('repl') | 
					
						
							| 
									
										
										
										
											2018-12-20 04:40:30 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 			this._keep_running = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// setup the global ns...
 | 
					
						
							|  |  |  | 			global.ig = | 
					
						
							|  |  |  | 			global.ImageGrid =  | 
					
						
							|  |  |  | 				this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			require('features/all') | 
					
						
							|  |  |  | 			global.ImageGridFeatures = core.ImageGridFeatures | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//var ig = core.ImageGridFeatures
 | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			repl | 
					
						
							|  |  |  | 				.start({ | 
					
						
							|  |  |  | 					prompt: 'ig> ', | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					useGlobal: true, | 
					
						
							| 
									
										
										
										
											2016-05-27 18:41:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					input: process.stdin, | 
					
						
							|  |  |  | 					output: process.stdout, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					//ignoreUndefined: true,
 | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				.on('exit', function(){ | 
					
						
							|  |  |  | 					//ig.stop() 
 | 
					
						
							|  |  |  | 					process.exit() }) }], | 
					
						
							|  |  |  | 	startGUI: ['- System/Start viewer GUI', | 
					
						
							|  |  |  | 		{cli: '@gui'}, | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			// XXX
 | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX this is reletively generic, might be useful globally...
 | 
					
						
							|  |  |  | 	makeIndex: ['- System/Make index', | 
					
						
							|  |  |  | 		{cli: { | 
					
						
							|  |  |  | 			name: '@make', | 
					
						
							|  |  |  | 			arg: 'PATH', | 
					
						
							|  |  |  | 			valueRequired: true, | 
					
						
							|  |  |  | 		}}, | 
					
						
							|  |  |  | 		function(path){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							| 
									
										
										
										
											2016-05-29 23:49:01 +03:00
										 |  |  | 			path = util.normalizePath(path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 			// XXX is cloning index here the correct way to go???
 | 
					
						
							|  |  |  | 			//var index = this.clone()
 | 
					
						
							|  |  |  | 			var index = this | 
					
						
							|  |  |  | 			return index.loadImages(path) | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 				// save base index...
 | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 				.then(function(){  | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					return index.saveIndex() }) | 
					
						
							|  |  |  | 				// sharp stuff...
 | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 				.then(function(){ | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					if(index.makePreviews){ | 
					
						
							|  |  |  | 						return Promise.all([ | 
					
						
							|  |  |  | 							index.cacheMetadata('all'), | 
					
						
							|  |  |  | 							index.makePreviews('all') ])} }) | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 				.then(function(){ | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					return index | 
					
						
							| 
									
										
										
										
											2016-05-28 02:47:52 +03:00
										 |  |  | 						.sortImages() | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 						.saveIndex() }) }], | 
					
						
							| 
									
										
										
										
											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: [ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 				var pkg = nodeRequire('./package.json') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				argv.Parser({ | 
					
						
							|  |  |  | 						// XXX argv.js is not picking these up because 
 | 
					
						
							|  |  |  | 						// 		of the require(..) mixup...
 | 
					
						
							|  |  |  | 						author: pkg.author, | 
					
						
							|  |  |  | 						version: pkg.version, | 
					
						
							|  |  |  | 						license: pkg.license, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// XXX setup presets...
 | 
					
						
							|  |  |  | 						//		...load sets of features and allow user 
 | 
					
						
							|  |  |  | 						//		to block/add specific features...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// XXX feature config...
 | 
					
						
							|  |  |  | 						// 		...get/set persistent config values...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// build the action command list...
 | 
					
						
							|  |  |  | 						...this.cliActions | 
					
						
							|  |  |  | 							.reduce(function(res, action){ | 
					
						
							|  |  |  | 								var cmd = that.getActionAttr(action, 'cli') | 
					
						
							|  |  |  | 								if(typeof(cmd) == typeof('str') || cmd === true){ | 
					
						
							|  |  |  | 									var name = cmd | 
					
						
							|  |  |  | 									var cmd = {name} } | 
					
						
							|  |  |  | 								var name = name === true ?  | 
					
						
							|  |  |  | 									action  | 
					
						
							|  |  |  | 									: cmd.name  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								res[name] = { | 
					
						
							|  |  |  | 									doc: (that.getActionAttr(action, 'doc') || '') | 
					
						
							|  |  |  | 										.split(/[\\\/]/g).pop(), | 
					
						
							|  |  |  | 									// XXX revise argument passing...
 | 
					
						
							|  |  |  | 									// 		...this must be as flexible as possible...
 | 
					
						
							|  |  |  | 									handler: function(rest, key, value){ | 
					
						
							|  |  |  | 										return that[action](value) }, | 
					
						
							|  |  |  | 									...cmd, | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								return res }, {}), | 
					
						
							| 
									
										
										
										
											2016-01-02 23:27:50 +03:00
										 |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					.onNoArgs(function(args){ | 
					
						
							|  |  |  | 						console.log('No args.') | 
					
						
							| 
									
										
										
										
											2015-12-31 22:23:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 						// XXX we should either start the GUI here or print help...
 | 
					
						
							|  |  |  | 						args.push('--help') | 
					
						
							|  |  |  | 						//args.push('gui')
 | 
					
						
							| 
									
										
										
										
											2016-05-23 03:42:53 +03:00
										 |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					.then(function(){ | 
					
						
							| 
									
										
										
										
											2016-01-01 01:58:55 +03:00
										 |  |  | 						// XXX
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 					})() | 
					
						
							| 
									
										
										
										
											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...
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:50 +03:00
										 |  |  | 				!this._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 }) |