mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	Refactor plugin logic.
This relies more heavily on `async` and also makes the loading process more asynchronous. It does remove one warning in the case that a plugin is enabled but not installed.
This commit is contained in:
		| @@ -72,25 +72,21 @@ var fs = require('fs'), | |||||||
| 				db.getSetMembers('plugins:active', next); | 				db.getSetMembers('plugins:active', next); | ||||||
| 			}, | 			}, | ||||||
| 			function(plugins, next) { | 			function(plugins, next) { | ||||||
| 				if (plugins && Array.isArray(plugins)) { | 				if (!plugins || !Array.isArray(plugins)) { | ||||||
| 					plugins.push(meta.config['theme:id']); | 					next(); | ||||||
|  | 				} | ||||||
|  |  | ||||||
| 					async.each(plugins, function(plugin, next) { | 				plugins.push(meta.config['theme:id']); | ||||||
| 						if (!plugin || typeof plugin !== 'string') { |  | ||||||
| 							return next(); |  | ||||||
| 						} |  | ||||||
|  |  | ||||||
| 						var modulePath = path.join(__dirname, '../node_modules/', plugin); | 				plugins = plugins.filter(function(plugin){ | ||||||
| 						if (fs.existsSync(modulePath)) { | 					return plugin && typeof plugin === 'string'; | ||||||
| 							Plugins.loadPlugin(modulePath, next); | 				}).map(function(plugin){ | ||||||
| 						} else { | 					return path.join(__dirname, '../node_modules/', plugin); | ||||||
| 							if (global.env === 'development') { | 				}); | ||||||
| 								winston.warn('[plugins] Plugin \'' + plugin + '\' not found'); |  | ||||||
| 							} | 				async.filter(plugins, fs.exists, function(plugins){ | ||||||
| 							next(); // Ignore this plugin silently | 					async.each(plugins, Plugins.loadPlugin, next); | ||||||
| 						} | 				}); | ||||||
| 					}, next); |  | ||||||
| 				} else next(); |  | ||||||
| 			}, | 			}, | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				if (global.env === 'development') winston.info('[plugins] Sorting hooks to fire in priority sequence'); | 				if (global.env === 'development') winston.info('[plugins] Sorting hooks to fire in priority sequence'); | ||||||
| @@ -434,28 +430,31 @@ var fs = require('fs'), | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Plugins.showInstalled = function(callback) { | 	Plugins.showInstalled = function(callback) { | ||||||
| 		npmPluginPath = path.join(__dirname, '../node_modules'); | 		var npmPluginPath = path.join(__dirname, '../node_modules'); | ||||||
|  |  | ||||||
| 		async.waterfall([ | 		async.waterfall([ | ||||||
| 			function(next) { | 			async.apply(fs.readdir, npmPluginPath), | ||||||
| 				fs.readdir(npmPluginPath, function(err, dirs) { |  | ||||||
| 					dirs = dirs.map(function(file) { |  | ||||||
| 						return path.join(npmPluginPath, file); |  | ||||||
| 					}).filter(function(file) { |  | ||||||
| 						if (fs.existsSync(file)) { |  | ||||||
| 							var stats = fs.statSync(file), |  | ||||||
| 								isPlugin =  file.substr(npmPluginPath.length + 1, 14) === 'nodebb-plugin-' || file.substr(npmPluginPath.length + 1, 14) === 'nodebb-widget-'; |  | ||||||
|  |  | ||||||
| 							if (stats.isDirectory() && isPlugin) return true; | 			function(dirs, next) { | ||||||
| 							else return false; | 				dirs = dirs.filter(function(dir){ | ||||||
| 						} else { | 					return dir.substr(0, 14) === 'nodebb-plugin-' || dir.substr(0, 14) === 'nodebb-widget-'; | ||||||
| 							return false; | 				}).map(function(dir){ | ||||||
|  | 					return path.join(npmPluginPath, dir); | ||||||
|  | 				}); | ||||||
|  |  | ||||||
|  | 				async.filter(dirs, function(dir, callback){ | ||||||
|  | 					fs.stat(dir, function(err, stats){ | ||||||
|  | 						if (err) { | ||||||
|  | 							return callback(false); | ||||||
| 						} | 						} | ||||||
| 					}); |  | ||||||
|  |  | ||||||
| 					next(err, dirs); | 						callback(stats.isDirectory()); | ||||||
|  | 					}) | ||||||
|  | 				}, function(plugins){ | ||||||
|  | 					next(null, plugins); | ||||||
| 				}); | 				}); | ||||||
| 			}, | 			}, | ||||||
|  |  | ||||||
| 			function(files, next) { | 			function(files, next) { | ||||||
| 				var plugins = []; | 				var plugins = []; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user