| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2015-04-21 14:32:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | var winston = require('winston'); | 
					
						
							|  |  |  | var express = require('express'); | 
					
						
							|  |  |  | var bodyParser = require('body-parser'); | 
					
						
							|  |  |  | var fs = require('fs'); | 
					
						
							|  |  |  | var path = require('path'); | 
					
						
							| 
									
										
										
										
											2017-11-27 13:44:30 -07:00
										 |  |  | var childProcess = require('child_process'); | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | var less = require('less'); | 
					
						
							|  |  |  | var async = require('async'); | 
					
						
							| 
									
										
										
										
											2018-03-26 13:37:53 -06:00
										 |  |  | var uglify = require('uglify-es'); | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | var nconf = require('nconf'); | 
					
						
							| 
									
										
										
										
											2017-08-24 17:26:50 -06:00
										 |  |  | var Benchpress = require('benchpressjs'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | var app = express(); | 
					
						
							|  |  |  | var server; | 
					
						
							| 
									
										
										
										
											2015-04-21 14:52:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | var formats = [ | 
					
						
							|  |  |  | 	winston.format.colorize(), | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const timestampFormat = winston.format((info) => { | 
					
						
							|  |  |  | 	var dateString = new Date().toISOString() + ' [' + global.process.pid + ']'; | 
					
						
							|  |  |  | 	info.level = dateString + ' - ' + info.level; | 
					
						
							|  |  |  | 	return info; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | formats.push(timestampFormat()); | 
					
						
							|  |  |  | formats.push(winston.format.splat()); | 
					
						
							|  |  |  | formats.push(winston.format.simple()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | winston.configure({ | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 	level: 'verbose', | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 	format: winston.format.combine.apply(null, formats), | 
					
						
							|  |  |  | 	transports: [ | 
					
						
							| 
									
										
										
										
											2018-10-16 15:17:14 -04:00
										 |  |  | 		new winston.transports.Console({ | 
					
						
							|  |  |  | 			handleExceptions: true, | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 		new winston.transports.File({ | 
					
						
							|  |  |  | 			filename: 'logs/webinstall.log', | 
					
						
							| 
									
										
										
										
											2018-10-16 15:17:14 -04:00
										 |  |  | 			handleExceptions: true, | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 		}), | 
					
						
							|  |  |  | 	], | 
					
						
							| 
									
										
										
										
											2015-09-02 18:41:05 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | var web = module.exports; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | var scripts = [ | 
					
						
							| 
									
										
										
										
											2017-11-23 08:50:10 -07:00
										 |  |  | 	'node_modules/jquery/dist/jquery.js', | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | 	'public/vendor/xregexp/xregexp.js', | 
					
						
							|  |  |  | 	'public/vendor/xregexp/unicode/unicode-base.js', | 
					
						
							|  |  |  | 	'public/src/utils.js', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 	'public/src/installer/install.js', | 
					
						
							| 
									
										
										
										
											2019-03-19 14:01:31 -04:00
										 |  |  | 	'node_modules/zxcvbn/dist/zxcvbn.js', | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | ]; | 
					
						
							| 
									
										
										
										
											2015-04-21 14:32:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | var installing = false; | 
					
						
							| 
									
										
										
										
											2018-05-23 12:39:04 -04:00
										 |  |  | var success = false; | 
					
						
							|  |  |  | var error = false; | 
					
						
							| 
									
										
										
										
											2018-05-26 13:12:33 -04:00
										 |  |  | var launchUrl; | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | web.install = function (port) { | 
					
						
							| 
									
										
										
										
											2015-04-22 15:52:12 -04:00
										 |  |  | 	port = port || 4567; | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 	winston.info('Launching web installer on port ' + port); | 
					
						
							| 
									
										
										
										
											2015-04-21 14:32:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | 	app.use(express.static('public', {})); | 
					
						
							| 
									
										
										
										
											2017-09-13 13:50:00 -06:00
										 |  |  | 	app.engine('tpl', function (filepath, options, callback) { | 
					
						
							|  |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				fs.readFile(filepath, 'utf-8', next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (buffer, next) { | 
					
						
							|  |  |  | 				Benchpress.compileParse(buffer.toString(), options, next); | 
					
						
							| 
									
										
										
										
											2017-09-13 16:51:31 -04:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-09-13 13:50:00 -06:00
										 |  |  | 		], callback); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | 	app.set('view engine', 'tpl'); | 
					
						
							|  |  |  | 	app.set('views', path.join(__dirname, '../src/views')); | 
					
						
							|  |  |  | 	app.use(bodyParser.urlencoded({ | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		extended: true, | 
					
						
							| 
									
										
										
										
											2015-09-02 18:17:58 -04:00
										 |  |  | 	})); | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 	async.parallel([compileLess, compileJS, copyCSS, loadDefaults], function (err) { | 
					
						
							| 
									
										
										
										
											2017-08-04 22:23:55 -04:00
										 |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2020-06-20 23:32:12 -04:00
										 |  |  | 			winston.error(err.stack); | 
					
						
							| 
									
										
										
										
											2017-08-04 22:23:55 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-04-21 16:21:04 -04:00
										 |  |  | 		setupRoutes(); | 
					
						
							|  |  |  | 		launchExpress(port); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-21 14:32:21 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 14:52:57 -04:00
										 |  |  | function launchExpress(port) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	server = app.listen(port, function () { | 
					
						
							| 
									
										
										
										
											2015-05-24 10:15:16 -04:00
										 |  |  | 		winston.info('Web installer listening on http://%s:%s', '0.0.0.0', port); | 
					
						
							| 
									
										
										
										
											2015-04-21 14:52:57 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupRoutes() { | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | 	app.get('/', welcome); | 
					
						
							|  |  |  | 	app.post('/', install); | 
					
						
							| 
									
										
										
										
											2015-04-22 14:49:31 -04:00
										 |  |  | 	app.post('/launch', launch); | 
					
						
							| 
									
										
										
										
											2018-01-24 21:05:08 -05:00
										 |  |  | 	app.get('/ping', ping); | 
					
						
							|  |  |  | 	app.get('/sping', ping); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function ping(req, res) { | 
					
						
							|  |  |  | 	res.status(200).send(req.path === '/sping' ? 'healthy' : '200'); | 
					
						
							| 
									
										
										
										
											2015-04-21 14:52:57 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | function welcome(req, res) { | 
					
						
							| 
									
										
										
										
											2018-08-08 14:13:48 -05:00
										 |  |  | 	var dbs = ['redis', 'mongo', 'postgres']; | 
					
						
							| 
									
										
										
										
											2017-11-22 12:19:08 -05:00
										 |  |  | 	var databases = dbs.map(function (databaseName) { | 
					
						
							|  |  |  | 		var questions = require('../src/database/' + databaseName).questions.filter(function (question) { | 
					
						
							|  |  |  | 			return question && !question.hideOnWebInstall; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | 		return { | 
					
						
							| 
									
										
										
										
											2017-11-22 12:19:08 -05:00
										 |  |  | 			name: databaseName, | 
					
						
							|  |  |  | 			questions: questions, | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-04-21 19:10:47 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | 	var defaults = require('./data/defaults'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 15:29:29 -04:00
										 |  |  | 	res.render('install/index', { | 
					
						
							| 
									
										
										
										
											2018-05-15 15:25:59 -04:00
										 |  |  | 		url: nconf.get('url') || (req.protocol + '://' + req.get('host')), | 
					
						
							| 
									
										
										
										
											2018-05-26 13:12:33 -04:00
										 |  |  | 		launchUrl: launchUrl, | 
					
						
							| 
									
										
										
										
											2018-05-15 15:25:59 -04:00
										 |  |  | 		skipGeneralSetup: !!nconf.get('url'), | 
					
						
							| 
									
										
										
										
											2015-04-22 15:29:29 -04:00
										 |  |  | 		databases: databases, | 
					
						
							| 
									
										
										
										
											2015-04-24 15:11:22 -04:00
										 |  |  | 		skipDatabaseSetup: !!nconf.get('database'), | 
					
						
							| 
									
										
										
										
											2018-05-23 12:39:04 -04:00
										 |  |  | 		error: error, | 
					
						
							|  |  |  | 		success: success, | 
					
						
							| 
									
										
										
										
											2016-08-12 01:14:01 +03:00
										 |  |  | 		values: req.body, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		minimumPasswordLength: defaults.minimumPasswordLength, | 
					
						
							| 
									
										
										
										
											2019-03-19 14:01:31 -04:00
										 |  |  | 		minimumPasswordStrength: defaults.minimumPasswordStrength, | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | 		installing: installing, | 
					
						
							| 
									
										
										
										
											2015-04-21 19:10:47 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-21 14:52:57 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | function install(req, res) { | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | 	if (installing) { | 
					
						
							|  |  |  | 		return welcome(req, res); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-16 14:27:44 -05:00
										 |  |  | 	req.setTimeout(0); | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | 	installing = true; | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 	var setupEnvVars = nconf.get(); | 
					
						
							| 
									
										
										
										
											2015-04-22 11:36:19 -04:00
										 |  |  | 	for (var i in req.body) { | 
					
						
							| 
									
										
										
										
											2015-04-24 15:11:22 -04:00
										 |  |  | 		if (req.body.hasOwnProperty(i) && !process.env.hasOwnProperty(i)) { | 
					
						
							| 
									
										
										
										
											2018-01-15 15:05:33 -05:00
										 |  |  | 			setupEnvVars[i.replace(':', '__')] = req.body[i]; | 
					
						
							| 
									
										
										
										
											2015-04-22 11:36:19 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-22 11:22:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 	// Flatten any objects in setupEnvVars
 | 
					
						
							|  |  |  | 	const pushToRoot = function (parentKey, key) { | 
					
						
							|  |  |  | 		setupEnvVars[parentKey + '__' + key] = setupEnvVars[parentKey][key]; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	for (var j in setupEnvVars) { | 
					
						
							| 
									
										
										
										
											2018-03-22 19:35:53 -04:00
										 |  |  | 		if (setupEnvVars.hasOwnProperty(j) && typeof setupEnvVars[j] === 'object' && setupEnvVars[j] !== null && !Array.isArray(setupEnvVars[j])) { | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 			Object.keys(setupEnvVars[j]).forEach(pushToRoot.bind(null, j)); | 
					
						
							|  |  |  | 			delete setupEnvVars[j]; | 
					
						
							| 
									
										
										
										
											2018-03-22 19:35:53 -04:00
										 |  |  | 		} else if (Array.isArray(setupEnvVars[j])) { | 
					
						
							|  |  |  | 			setupEnvVars[j] = JSON.stringify(setupEnvVars[j]); | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 18:45:00 -04:00
										 |  |  | 	winston.info('Starting setup process'); | 
					
						
							|  |  |  | 	winston.info(setupEnvVars); | 
					
						
							| 
									
										
										
										
											2018-05-26 13:12:33 -04:00
										 |  |  | 	launchUrl = setupEnvVars.url; | 
					
						
							| 
									
										
										
										
											2018-03-22 18:45:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 14:39:37 -04:00
										 |  |  | 	var child = require('child_process').fork('app', ['--setup'], { | 
					
						
							| 
									
										
										
										
											2018-01-15 15:05:33 -05:00
										 |  |  | 		env: setupEnvVars, | 
					
						
							| 
									
										
										
										
											2015-04-22 11:22:55 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-22 11:36:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	child.on('close', function (data) { | 
					
						
							| 
									
										
										
										
											2018-05-23 11:39:58 -04:00
										 |  |  | 		installing = false; | 
					
						
							| 
									
										
										
										
											2018-05-23 12:39:04 -04:00
										 |  |  | 		success = data === 0; | 
					
						
							|  |  |  | 		error = data !== 0; | 
					
						
							| 
									
										
										
										
											2015-04-22 14:39:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		welcome(req, res); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-21 19:50:58 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 14:49:31 -04:00
										 |  |  | function launch(req, res) { | 
					
						
							| 
									
										
										
										
											2015-04-22 15:29:29 -04:00
										 |  |  | 	res.json({}); | 
					
						
							| 
									
										
										
										
											2015-04-22 15:51:14 -04:00
										 |  |  | 	server.close(); | 
					
						
							| 
									
										
										
										
											2019-10-07 17:42:29 -04:00
										 |  |  | 	req.setTimeout(0); | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 	var child; | 
					
						
							| 
									
										
										
										
											2015-04-22 17:51:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 	if (!nconf.get('launchCmd')) { | 
					
						
							|  |  |  | 		child = childProcess.spawn('node', ['loader.js'], { | 
					
						
							|  |  |  | 			detached: true, | 
					
						
							|  |  |  | 			stdio: ['ignore', 'ignore', 'ignore'], | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		console.log('\nStarting NodeBB'); | 
					
						
							|  |  |  | 		console.log('    "./nodebb stop" to stop the NodeBB server'); | 
					
						
							|  |  |  | 		console.log('    "./nodebb log" to view server output'); | 
					
						
							|  |  |  | 		console.log('    "./nodebb restart" to restart NodeBB'); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// Use launchCmd instead, if specified
 | 
					
						
							|  |  |  | 		child = childProcess.exec(nconf.get('launchCmd'), { | 
					
						
							|  |  |  | 			detached: true, | 
					
						
							|  |  |  | 			stdio: ['ignore', 'ignore', 'ignore'], | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-02 18:17:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 08:50:10 -07:00
										 |  |  | 	var filesToDelete = [ | 
					
						
							|  |  |  | 		'installer.css', | 
					
						
							|  |  |  | 		'installer.min.js', | 
					
						
							|  |  |  | 		'bootstrap.min.css', | 
					
						
							|  |  |  | 	]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	async.each(filesToDelete, function (filename, next) { | 
					
						
							|  |  |  | 		fs.unlink(path.join(__dirname, '../public', filename), next); | 
					
						
							|  |  |  | 	}, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-22 11:45:22 -05:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			winston.warn('Unable to remove installer files'); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-02 18:17:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 11:45:22 -05:00
										 |  |  | 		child.unref(); | 
					
						
							|  |  |  | 		process.exit(0); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-22 14:49:31 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 16:21:04 -04:00
										 |  |  | function compileLess(callback) { | 
					
						
							| 
									
										
										
										
											2020-07-03 15:16:47 +02:00
										 |  |  | 	var installSrc = path.join(__dirname, '../public/less/install.less'); | 
					
						
							|  |  |  | 	fs.readFile(installSrc, function (err, style) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2020-06-20 23:32:12 -04:00
										 |  |  | 			return winston.error('Unable to read LESS install file: ', err.stack); | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 15:16:47 +02:00
										 |  |  | 		less.render(style.toString(), { | 
					
						
							|  |  |  | 			filename: path.resolve(installSrc), | 
					
						
							|  |  |  | 		}, function (err, css) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:52:56 -07:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2020-06-20 23:32:12 -04:00
										 |  |  | 				return winston.error('Unable to compile LESS: ', err.stack); | 
					
						
							| 
									
										
										
										
											2015-04-21 16:21:04 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 11:45:22 -05:00
										 |  |  | 			fs.writeFile(path.join(__dirname, '../public/installer.css'), css.css, callback); | 
					
						
							| 
									
										
										
										
											2015-04-21 16:21:04 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-04-21 14:32:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 17:02:36 -04:00
										 |  |  | function compileJS(callback) { | 
					
						
							| 
									
										
										
										
											2017-08-04 22:23:55 -04:00
										 |  |  | 	var code = ''; | 
					
						
							|  |  |  | 	async.eachSeries(scripts, function (srcPath, next) { | 
					
						
							|  |  |  | 		fs.readFile(path.join(__dirname, '..', srcPath), function (err, buffer) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return next(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-04-21 17:02:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 22:23:55 -04:00
										 |  |  | 			code += buffer.toString(); | 
					
						
							|  |  |  | 			next(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}, function (err) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			var minified = uglify.minify(code, { | 
					
						
							|  |  |  | 				compress: false, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			if (!minified.code) { | 
					
						
							|  |  |  | 				return callback(new Error('[[error:failed-to-minify]]')); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			fs.writeFile(path.join(__dirname, '../public/installer.min.js'), minified.code, callback); | 
					
						
							|  |  |  | 		} catch (e) { | 
					
						
							|  |  |  | 			callback(e); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-04-21 17:02:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 08:50:10 -07:00
										 |  |  | function copyCSS(next) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			fs.readFile(path.join(__dirname, '../node_modules/bootstrap/dist/css/bootstrap.min.css'), 'utf8', next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (src, next) { | 
					
						
							|  |  |  | 			fs.writeFile(path.join(__dirname, '../public/bootstrap.min.css'), src, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], next); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | function loadDefaults(next) { | 
					
						
							| 
									
										
										
										
											2018-03-22 14:50:33 -04:00
										 |  |  | 	var setupDefaultsPath = path.join(__dirname, '../setup.json'); | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 	fs.access(setupDefaultsPath, fs.constants.F_OK | fs.constants.R_OK, function (err) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			// setup.json not found or inaccessible, proceed with no defaults
 | 
					
						
							|  |  |  | 			return setImmediate(next); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 14:50:33 -04:00
										 |  |  | 		winston.info('[installer] Found setup.json, populating default values'); | 
					
						
							| 
									
										
										
										
											2018-03-21 17:00:49 -04:00
										 |  |  | 		nconf.file({ | 
					
						
							|  |  |  | 			file: setupDefaultsPath, | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		next(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } |