| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2015-02-24 16:36:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | var async = require('async'); | 
					
						
							| 
									
										
										
										
											2017-02-17 20:20:42 -07:00
										 |  |  | var fork = require('child_process').fork; | 
					
						
							|  |  |  | var env = process.env; | 
					
						
							|  |  |  | var worker; | 
					
						
							|  |  |  | var updateWorker; | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | var initWorker; | 
					
						
							| 
									
										
										
										
											2017-02-17 20:20:42 -07:00
										 |  |  | var incomplete = []; | 
					
						
							|  |  |  | var running = 0; | 
					
						
							| 
									
										
										
										
											2015-02-24 16:36:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-23 14:00:37 -06:00
										 |  |  | env.NODE_ENV = env.NODE_ENV || 'development'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | var nconf = require('nconf'); | 
					
						
							|  |  |  | nconf.file({ | 
					
						
							|  |  |  | 	file: 'config.json', | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | nconf.defaults({ | 
					
						
							|  |  |  | 	base_dir: __dirname, | 
					
						
							|  |  |  | 	views_dir: './build/public/templates', | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | var winston = require('winston'); | 
					
						
							|  |  |  | winston.configure({ | 
					
						
							|  |  |  | 	transports: [ | 
					
						
							|  |  |  | 		new winston.transports.Console({ | 
					
						
							|  |  |  | 			handleExceptions: true, | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | var db = require('./src/database'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | module.exports = function (grunt) { | 
					
						
							| 
									
										
										
										
											2016-04-18 10:59:55 -04:00
										 |  |  | 	var args = []; | 
					
						
							| 
									
										
										
										
											2017-02-17 22:07:50 +00:00
										 |  |  | 	var initArgs = ['--build']; | 
					
						
							| 
									
										
										
										
											2016-04-18 10:59:55 -04:00
										 |  |  | 	if (!grunt.option('verbose')) { | 
					
						
							|  |  |  | 		args.push('--log-level=info'); | 
					
						
							| 
									
										
										
										
											2017-02-17 22:07:50 +00:00
										 |  |  | 		initArgs.push('--log-level=info'); | 
					
						
							| 
									
										
										
										
											2016-04-18 10:59:55 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 	function update(action, filepath, target) { | 
					
						
							| 
									
										
										
										
											2017-02-17 20:20:42 -07:00
										 |  |  | 		var updateArgs = args.slice(); | 
					
						
							| 
									
										
										
										
											2017-05-31 15:05:56 -04:00
										 |  |  | 		var compiling; | 
					
						
							| 
									
										
										
										
											2017-02-17 20:20:42 -07:00
										 |  |  | 		var time = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 12:37:03 -04:00
										 |  |  | 		if (target === 'lessUpdated_Client') { | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 			compiling = 'clientCSS'; | 
					
						
							| 
									
										
										
										
											2016-03-24 12:37:03 -04:00
										 |  |  | 		} else if (target === 'lessUpdated_Admin') { | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 			compiling = 'acpCSS'; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		} else if (target === 'clientUpdated') { | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			compiling = 'js'; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:46:37 -05:00
										 |  |  | 		} else if (target === 'templatesUpdated') { | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			compiling = 'tpl'; | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 		} else if (target === 'langUpdated') { | 
					
						
							|  |  |  | 			compiling = 'lang'; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		} else if (target === 'serverUpdated') { | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 			// Do nothing, just restart
 | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 		if (compiling && !incomplete.includes(compiling)) { | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 			incomplete.push(compiling); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 		updateArgs.push('--build'); | 
					
						
							|  |  |  | 		updateArgs.push(incomplete.join(',')); | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		worker.kill(); | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 		if (updateWorker) { | 
					
						
							|  |  |  | 			updateWorker.kill('SIGKILL'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		updateWorker = fork('app.js', updateArgs, { env: env }); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:12:18 -07:00
										 |  |  | 		running += 1; | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 		updateWorker.on('exit', function () { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:12:18 -07:00
										 |  |  | 			running -= 1; | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 			if (running === 0) { | 
					
						
							| 
									
										
										
										
											2017-02-17 22:07:50 +00:00
										 |  |  | 				worker = fork('app.js', args, { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 					env: env, | 
					
						
							| 
									
										
										
										
											2017-02-17 22:07:50 +00:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 				worker.on('message', function () { | 
					
						
							|  |  |  | 					if (incomplete.length) { | 
					
						
							|  |  |  | 						incomplete = []; | 
					
						
							| 
									
										
										
										
											2015-02-24 18:22:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 						if (grunt.option('verbose')) { | 
					
						
							|  |  |  | 							grunt.log.writeln('NodeBB restarted in ' + (Date.now() - time) + ' ms'); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:05:00 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	grunt.initConfig({ | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 		watch: {}, | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	grunt.loadNpmTasks('grunt-contrib-watch'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	grunt.registerTask('default', ['watch']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	grunt.registerTask('init', function () { | 
					
						
							|  |  |  | 		var done = this.async(); | 
					
						
							|  |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				db.init(next); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 			function (next) { | 
					
						
							|  |  |  | 				db.getSortedSetRange('plugins:active', 0, -1, next); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 			function (plugins, next) { | 
					
						
							|  |  |  | 				addBaseThemes(plugins, next); | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 			function (plugins, next) { | 
					
						
							|  |  |  | 				if (!plugins.includes('nodebb-plugin-composer-default')) { | 
					
						
							|  |  |  | 					plugins.push('nodebb-plugin-composer-default'); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				const lessUpdated_Client = plugins.map(p => 'node_modules/' + p + '/**/*.less'); | 
					
						
							|  |  |  | 				const lessUpdated_Admin = plugins.map(p => 'node_modules/' + p + '/**/*.less'); | 
					
						
							|  |  |  | 				const clientUpdated = plugins.map(p => 'node_modules/' + p + '/**/*.js'); | 
					
						
							|  |  |  | 				const templatesUpdated = plugins.map(p => 'node_modules/' + p + '/**/*.tpl'); | 
					
						
							|  |  |  | 				const langUpdated = plugins.map(p => 'node_modules/' + p + '/**/*.json'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				grunt.config(['watch'], { | 
					
						
							|  |  |  | 					lessUpdated_Client: { | 
					
						
							|  |  |  | 						files: [ | 
					
						
							|  |  |  | 							'public/less/*.less', | 
					
						
							|  |  |  | 							'!public/less/admin/**/*.less', | 
					
						
							|  |  |  | 							...lessUpdated_Client, | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/node_modules/**', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/.git/**', | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						options: { | 
					
						
							|  |  |  | 							interval: 1000, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					lessUpdated_Admin: { | 
					
						
							|  |  |  | 						files: [ | 
					
						
							|  |  |  | 							'public/less/admin/**/*.less', | 
					
						
							|  |  |  | 							...lessUpdated_Admin, | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/node_modules/**', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/.git/**', | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						options: { | 
					
						
							|  |  |  | 							interval: 1000, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					clientUpdated: { | 
					
						
							|  |  |  | 						files: [ | 
					
						
							|  |  |  | 							'public/src/**/*.js', | 
					
						
							|  |  |  | 							...clientUpdated, | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/node_modules/**', | 
					
						
							|  |  |  | 							'node_modules/benchpressjs/build/benchpress.js', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/.git/**', | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						options: { | 
					
						
							|  |  |  | 							interval: 1000, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					serverUpdated: { | 
					
						
							|  |  |  | 						files: ['*.js', 'install/*.js', 'src/**/*.js', '!src/upgrades/**'], | 
					
						
							|  |  |  | 						options: { | 
					
						
							|  |  |  | 							interval: 1000, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					templatesUpdated: { | 
					
						
							|  |  |  | 						files: [ | 
					
						
							|  |  |  | 							'src/views/**/*.tpl', | 
					
						
							|  |  |  | 							...templatesUpdated, | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/node_modules/**', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/.git/**', | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						options: { | 
					
						
							|  |  |  | 							interval: 1000, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					langUpdated: { | 
					
						
							|  |  |  | 						files: [ | 
					
						
							|  |  |  | 							'public/language/en-GB/*.json', | 
					
						
							|  |  |  | 							'public/language/en-GB/**/*.json', | 
					
						
							|  |  |  | 							...langUpdated, | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/node_modules/**', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/.git/**', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/plugin.json', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/package.json', | 
					
						
							|  |  |  | 							'!node_modules/nodebb-*/theme.json', | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						options: { | 
					
						
							|  |  |  | 							interval: 1000, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				next(); | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 		], done); | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 	grunt.task.run('init'); | 
					
						
							| 
									
										
										
										
											2016-02-23 14:26:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 	env.NODE_ENV = 'development'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 14:26:16 -05:00
										 |  |  | 	if (grunt.option('skip')) { | 
					
						
							| 
									
										
										
										
											2017-02-17 22:07:50 +00:00
										 |  |  | 		worker = fork('app.js', args, { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			env: env, | 
					
						
							| 
									
										
										
										
											2017-02-17 22:07:50 +00:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-02-23 14:26:16 -05:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-02-17 23:33:37 +00:00
										 |  |  | 		initWorker = fork('app.js', initArgs, { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			env: env, | 
					
						
							| 
									
										
										
										
											2017-02-17 23:33:37 +00:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 23:33:37 +00:00
										 |  |  | 		initWorker.on('exit', function () { | 
					
						
							|  |  |  | 			worker = fork('app.js', args, { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				env: env, | 
					
						
							| 
									
										
										
										
											2017-02-17 23:33:37 +00:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	grunt.event.on('watch', update); | 
					
						
							| 
									
										
										
										
											2017-02-18 02:30:48 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-06-11 12:50:40 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | function addBaseThemes(plugins, callback) { | 
					
						
							|  |  |  | 	const themeId = plugins.find(p => p.startsWith('nodebb-theme-')); | 
					
						
							|  |  |  | 	if (!themeId) { | 
					
						
							|  |  |  | 		return setImmediate(callback, null, plugins); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	function getBaseRecursive(themeId) { | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			const baseTheme = require(themeId + '/theme').baseTheme; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (baseTheme) { | 
					
						
							|  |  |  | 				plugins.push(baseTheme); | 
					
						
							|  |  |  | 				getBaseRecursive(baseTheme); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} catch (err) { | 
					
						
							|  |  |  | 			console.log(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getBaseRecursive(themeId); | 
					
						
							|  |  |  | 	callback(null, plugins); | 
					
						
							|  |  |  | } |