From 7a3be5d786ee42727569e5e47af30b752dfb924f Mon Sep 17 00:00:00 2001 From: Lorenzo Ganni Date: Wed, 4 Jan 2017 18:51:19 +0100 Subject: [PATCH] Randomize development build server port --- README.md | 4 ++-- app.js | 4 ++-- gulpfile.js | 34 +++++++++++++++------------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 57c37fa..f85edfa 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ You'll need NodeJS, use this command to access the main branch and install the d cd vnmsim && npm install ``` -You'll need Gulp and Express to compile it. For debugging mode (it will start a web server on `localhost:3000` and you'll find the compiled simulator source in `build`) just run: +You'll need Gulp and Express to compile it. For debugging mode (it will start a web server on `localhost`, the port will be displayed as soon as the compilation ends and you'll find the compiled simulator source in `build`) just run: ``` gulp ``` -To compile it for production (it will take a little more time to uglify the source code, it won't start the server and the output will be located in `dist`): +To compile it for production (it won't start the server and the output will be located in `dist`): ``` gulp --production diff --git a/app.js b/app.js index a62a1f0..5244b01 100644 --- a/app.js +++ b/app.js @@ -4,5 +4,5 @@ var express = require('express'), app.use(express.static(__dirname + '/build')); -app.listen(3000); -console.log('Listening on port 3000'); +var listener = app.listen(0); +console.log('Express server listening on port ' + listener.address().port); diff --git a/gulpfile.js b/gulpfile.js index 616970c..049ae14 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -94,19 +94,6 @@ gulp.task('samplesZip', () => { .pipe(gulp.dest(dest)); }); -// server and watchers -gulp.task('server', function () { - server.run(['app.js']); - - gulp.watch('src/templates/**/*', ['templates']); - gulp.watch('src/js/**/*.js', ['scripts']); - gulp.watch('src/locale/*.json', ['scripts']); - gulp.watch('src/img/**/*', ['styles']); - gulp.watch('src/sass/**/*.sass', ['styles']); - gulp.watch('samples/*.json', ['samplesList', 'samplesFolder', 'samplesZip']); - gulp.watch('build/**/*', server.notify); -}); - // tasks to be executed during build var tasks = [ 'styles', @@ -115,14 +102,23 @@ var tasks = [ 'samplesFolder', 'samplesZip', 'templates', - 'fonts', - 'server' + 'fonts' ]; -// remove server task in production mode -if (argv.production) tasks.pop(); // default task gulp.task('default', tasks, function() { - // end message - console.log('Build ended'); + + // in development start server and watchers + if (!argv.production) { + server.run(['app.js']); + + gulp.watch('src/templates/**/*', ['templates']); + gulp.watch('src/js/**/*.js', ['scripts']); + gulp.watch('src/locale/*.json', ['scripts']); + gulp.watch('src/img/**/*', ['styles']); + gulp.watch('src/sass/**/*.sass', ['styles']); + gulp.watch('samples/*.json', ['samplesList', 'samplesFolder', 'samplesZip']); + gulp.watch('build/**/*', server.notify); + + } });