| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2015-02-24 16:36:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | 		var compiling = ''; | 
					
						
							|  |  |  | 		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
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-17 13:56:47 -05:00
										 |  |  | 		if (incomplete.indexOf(compiling) === -1) { | 
					
						
							|  |  |  | 			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({ | 
					
						
							|  |  |  | 		watch: { | 
					
						
							| 
									
										
										
										
											2016-03-24 12:37:03 -04:00
										 |  |  | 			lessUpdated_Client: { | 
					
						
							| 
									
										
										
										
											2016-03-29 13:19:01 -04:00
										 |  |  | 				files: [ | 
					
						
							|  |  |  | 					'public/*.less', | 
					
						
							|  |  |  | 					'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/**/*.less', | 
					
						
							| 
									
										
										
										
											2016-03-29 14:37:40 -04:00
										 |  |  | 					'!node_modules/nodebb-*/node_modules/**', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					'!node_modules/nodebb-*/.git/**', | 
					
						
							| 
									
										
										
										
											2017-02-03 10:24:19 -05:00
										 |  |  | 				], | 
					
						
							|  |  |  | 				options: { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					interval: 1000, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-03-24 12:37:03 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			lessUpdated_Admin: { | 
					
						
							| 
									
										
										
										
											2017-02-03 10:24:19 -05:00
										 |  |  | 				files: ['public/**/*.less'], | 
					
						
							|  |  |  | 				options: { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					interval: 1000, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			clientUpdated: { | 
					
						
							| 
									
										
										
										
											2016-03-29 13:19:01 -04:00
										 |  |  | 				files: [ | 
					
						
							|  |  |  | 					'public/src/**/*.js', | 
					
						
							|  |  |  | 					'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/**/*.js', | 
					
						
							|  |  |  | 					'!node_modules/nodebb-*/node_modules/**', | 
					
						
							| 
									
										
										
										
											2016-03-29 14:37:40 -04:00
										 |  |  | 					'node_modules/templates.js/lib/templates.js', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					'!node_modules/nodebb-*/.git/**', | 
					
						
							| 
									
										
										
										
											2017-02-03 10:24:19 -05:00
										 |  |  | 				], | 
					
						
							|  |  |  | 				options: { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					interval: 1000, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			serverUpdated: { | 
					
						
							| 
									
										
										
										
											2017-02-03 10:24:19 -05:00
										 |  |  | 				files: ['*.js', 'install/*.js', 'src/**/*.js'], | 
					
						
							|  |  |  | 				options: { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					interval: 1000, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			templatesUpdated: { | 
					
						
							| 
									
										
										
										
											2016-03-29 13:19:01 -04:00
										 |  |  | 				files: [ | 
					
						
							|  |  |  | 					'src/views/**/*.tpl', | 
					
						
							|  |  |  | 					'node_modules/nodebb-*/*.tpl', 'node_modules/nodebb-*/**/*.tpl', | 
					
						
							| 
									
										
										
										
											2016-03-29 14:37:40 -04:00
										 |  |  | 					'!node_modules/nodebb-*/node_modules/**', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					'!node_modules/nodebb-*/.git/**', | 
					
						
							| 
									
										
										
										
											2017-02-03 10:24:19 -05:00
										 |  |  | 				], | 
					
						
							|  |  |  | 				options: { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					interval: 1000, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			langUpdated: { | 
					
						
							|  |  |  | 				files: [ | 
					
						
							| 
									
										
										
										
											2017-02-02 10:52:14 -05:00
										 |  |  | 					'public/language/en-GB/*.json', | 
					
						
							|  |  |  | 					'public/language/en-GB/**/*.json', | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 					'node_modules/nodebb-*/**/*.json', | 
					
						
							|  |  |  | 					'!node_modules/nodebb-*/node_modules/**', | 
					
						
							|  |  |  | 					'!node_modules/nodebb-*/.git/**', | 
					
						
							| 
									
										
										
										
											2017-01-19 10:53:25 -07:00
										 |  |  | 					'!node_modules/nodebb-*/plugin.json', | 
					
						
							|  |  |  | 					'!node_modules/nodebb-*/package.json', | 
					
						
							|  |  |  | 					'!node_modules/nodebb-*/theme.json', | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 				], | 
					
						
							| 
									
										
										
										
											2017-02-03 10:24:19 -05:00
										 |  |  | 				options: { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					interval: 1000, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2017-01-17 20:22:38 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	grunt.loadNpmTasks('grunt-contrib-watch'); | 
					
						
							| 
									
										
										
										
											2016-02-23 14:26:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 23:33:37 +00:00
										 |  |  | 	grunt.registerTask('default', ['watch']); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; |