Skip to content

Instantly share code, notes, and snippets.

@xynova
Last active August 16, 2016 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xynova/e36da44fda6a8bca43b69dc119eb5555 to your computer and use it in GitHub Desktop.
Save xynova/e36da44fda6a8bca43b69dc119eb5555 to your computer and use it in GitHub Desktop.
Gulp api and layouts server
'use strict'
var gulp = require('gulp')
, forever = require('forever-monitor')
, livereload = require('gulp-livereload')
, paths = require('./paths')
, _ = require('lodash')
;
/* Specifies the ports for local server dev */
var localPorts = { layoutsServer: 1234, apiServer: 2345 };
/**
* Automatically re-build project common modules when files are changed
*/
gulp.task('DEV WATCH(templates,common,css)|BUILD', function() {
// a bunch of watch tasks
// eg: gulp.watch(paths.ravenScripts, {read:false} , ['BUILD concat.raven.js']);
});
/**
* Starts nodejs servers to serve layout and api
* watches the *-dist.html and executes a reload
*/
gulp.task('DEV START.servers'
,[ 'DEV START.api.server'
,'DEV START.layouts.server'
,'DEV START.livereload.server'
]
, function(){
return gulp.watch(
[ paths.localDevLayoutsDirFiles , paths.appModuleScripts ]
, {read:false}
, _.debounce(function(){
gulp.src('app/index.html')
.pipe(livereload());
},50)
);
});
/**
* Starts a local UI server.
* - Serves the html pages and proxies the api calls to a local api stub server
*/
gulp.task('DEV START.layouts.server', function() {
let child = new (forever.Monitor)(paths.localDevDir + 'appServer.js',{
args: ['--port='+ localPorts.layoutsServer
,'--apiPort='+ localPorts.apiServer
, '--enableLiveReload']
, watch:true
, watchDirectory: paths.localDevDir
, max:2
, killTree: true
})
.start();
// Force terminate process hierarchy on windows when pressing CTRL-C
process.once('SIGINT',function(){
child.stop();
});
});
/**
* Starts a local api server.
* - Mimics the final api when developing locally
*/
gulp.task('DEV START.api.server', function() {
let child = new (forever.Monitor)(paths.localDevDir + 'apiServer.js',{
args: ['--port='+ localPorts.apiServer, '--responseDelay=' + 500 ]
, watch:true
, watchDirectory: paths.localDevDir
, max:5
, killTree: true
})
.start();
// Force terminate process hierarchy on windows when pressing CTRL-C
process.once('SIGINT',function(){
child.stop();
});
});
/**
* Starts a live reload server to refresh the browser when things change
*/
gulp.task('DEV START.livereload.server',function(){
return livereload.listen();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment