| 
									
										
										
										
											2015-02-24 16:36:13 -05:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var fork = require('child_process').fork, | 
					
						
							|  |  |  | 	env = process.env, | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 	worker, | 
					
						
							|  |  |  | 	incomplete = []; | 
					
						
							| 
									
										
										
										
											2015-02-24 16:36:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 13:06:04 -05:00
										 |  |  | module.exports = function(grunt) { | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 	function update(action, filepath, target) { | 
					
						
							| 
									
										
										
										
											2015-02-24 18:22:38 -05:00
										 |  |  | 		var args = [], | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			fromFile = '', | 
					
						
							| 
									
										
										
										
											2015-02-24 18:05:00 -05:00
										 |  |  | 			compiling = '', | 
					
						
							|  |  |  | 			time = Date.now(); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:22:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-24 18:24:00 -05:00
										 |  |  | 		if (!grunt.option('verbose')) { | 
					
						
							| 
									
										
										
										
											2015-02-24 18:22:38 -05:00
										 |  |  | 			args.push('--log-level=info'); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if (target === 'lessUpdated') { | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			fromFile = ['js','tpl']; | 
					
						
							|  |  |  | 			compiling = 'less'; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		} else if (target === 'clientUpdated') { | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			fromFile = ['less','tpl']; | 
					
						
							|  |  |  | 			compiling = 'js'; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:46:37 -05:00
										 |  |  | 		} else if (target === 'templatesUpdated') { | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			fromFile = ['js','less']; | 
					
						
							|  |  |  | 			compiling = 'tpl'; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		} else if (target === 'serverUpdated') { | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 			fromFile = ['less','js','tpl']; | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 		fromFile = fromFile.filter(function(ext) { | 
					
						
							|  |  |  | 			return incomplete.indexOf(ext) === -1; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		args.push('--from-file=' + fromFile.join(',')); | 
					
						
							|  |  |  | 		incomplete.push(compiling); | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		worker.kill(); | 
					
						
							| 
									
										
										
										
											2015-02-24 17:14:28 -05:00
										 |  |  | 		worker = fork('app.js', args, { env: env }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		worker.on('message', function() { | 
					
						
							| 
									
										
										
										
											2015-02-24 18:05:00 -05:00
										 |  |  | 			if (incomplete.length) { | 
					
						
							|  |  |  | 				incomplete = []; | 
					
						
							| 
									
										
										
										
											2015-02-24 18:22:38 -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: { | 
					
						
							|  |  |  | 			lessUpdated: { | 
					
						
							|  |  |  | 				files: ['public/**/*.less', 'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/*/*.less', 'node_modules/nodebb-*/*/*/*.less', 'node_modules/nodebb-*/*/*/*/*.less'] | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			clientUpdated: { | 
					
						
							|  |  |  | 				files: ['public/src/**/*.js', 'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/*/*.js', 'node_modules/nodebb-*/*/*/*.js', 'node_modules/nodebb-*/*/*/*/*.js'] | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			serverUpdated: { | 
					
						
							|  |  |  | 				files: ['*.js', 'src/**/*.js'] | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			templatesUpdated: { | 
					
						
							| 
									
										
										
										
											2015-03-02 14:09:36 -05:00
										 |  |  | 				files: ['src/views/**/*.tpl', 'node_modules/nodebb-*/*.tpl', 'node_modules/nodebb-*/*/*.tpl', 'node_modules/nodebb-*/*/*/*.tpl', 'node_modules/nodebb-*/*/*/*/*.tpl', 'node_modules/nodebb-*/*/*/*/*/*.tpl'] | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-02-24 15:34:05 -05:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-02-24 18:16:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	grunt.loadNpmTasks('grunt-contrib-watch'); | 
					
						
							|  |  |  | 	grunt.registerTask('default', ['watch']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	env.NODE_ENV = 'development'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	worker = fork('app.js', [], { env: env }); | 
					
						
							|  |  |  | 	grunt.event.on('watch', update); | 
					
						
							| 
									
										
										
										
											2015-01-30 13:06:04 -05:00
										 |  |  | }; |