var args = require('yargs').argv;
var config = require('./gulp.config')();
+var serverConfig = require('./server/server.config')();
var gulp = require('gulp');
-var plugins = require('gulp-load-plugins')({
- pattern: ['gulp-*', 'gulp.*'], // the glob(s) to search for
- scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look within
- replaceString: /^gulp(-|\.)/, // what to remove from the name of the module when adding it to the context
- camelize: true, // if true, transforms hyphenated plugins names to camel case
- lazy: true, // whether the plugins should be lazy loaded on demand
- rename: {} // a mapping of plugins to rename
-});
+var plugins = require('gulp-load-plugins')({lazy: true});
/**
* Arguments:
* --stubs : Using stubs in index.html (for mocking services, controllers or any other stuff)
*/
+
+/**
+ * Default tasks
+ *
+ */
gulp.task('help', plugins.taskListing);
+gulp.task('default', ['help']);
+
/**
- * @description
- * vet (evaluate) the code and create coverage report
+ * vet (evaluate) the code and create coverage report.
*
* @return {Stream}
*/
gulp.task('vet', function() {
- plugins.util.log(plugins.util.colors.blue('Checking source with JSHint and JSCS'));
+ log('Checking source files with JSHint and JSCS');
return gulp.src(config.jsAllFiles)
.pipe(plugins.if(args.verbose, plugins.print()))
}));
});
+/**
+ * wire up bower dependencies and inject files in index.html
+ *
+ * @return {Stream}
+ */
gulp.task('wiredep', function() {
- plugins.util.log('Wiring bower dependencies into html');
+ log('Wiring bower dependencies into html');
var wiredep = require('wiredep').stream;
- var wiredepOptions = config.getWiredepDefaultOptions();
+ var wiredepOptions = config.getWiredepOptions();
var jsFiles = args.stubs ? [].concat(config.jsFilesWithoutSpecs, config.jsFilesStubs) : config.jsFilesWithoutSpecs;
});
/**
- * @description
+ * Runs HTTP server in development mode.
+ */
+gulp.task('server-dev', ['wiredep'], function() {
+ log('Starting server in development mode');
+
+ server(true);
+});
+
+/**
* Inject files in a sorted sequence at a specified inject label.
*
* @param {Array} source Source files (glob patterns)
return plugins.inject(
gulp.src(source)
.pipe(plugins.angularFilesort(), options));
+}
+
+/**
+ * Runs HTTP server.
+ *
+ * @param {boolean} isDev - development or build mode.
+ */
+function server(isDev) {
+ var nodeOptions = {
+ script: serverConfig.script,
+ delayTime: 1,
+ env: {
+ 'NODE_ENV': isDev ? 'dev' : 'build'
+ },
+ watch: [serverConfig.directory]
+ };
+
+ return plugins.nodemon(nodeOptions)
+ .on('restart', ['vet'], function(ev) {
+ log('HTTP server restarted');
+ log('files changed:\n' + ev);
+ })
+ .on('start', function () {
+ log('HTTP server started');
+ })
+ .on('crash', function () {
+ log('HTTP server crashed');
+ })
+ .on('exit', function () {
+ log('HTTP server exited');
+ });
+}
+
+function log(message) {
+ plugins.util.log(plugins.util.colors.blue(message));
}
\ No newline at end of file
+++ /dev/null
-var express = require('express');
-var proxy = require('express-http-proxy');
-var app = express();
-
-// URL to backend server
-var moduleName = process.env.npm_package_config_backend_server_url;
-
-// Backend server port:
-var serverPort = process.env.npm_package_config_backend_port;
-
-// Backend server name:
-var serverName = process.env.npm_package_config_backend_server_name;
-
-
-app.use('/', express.static(__dirname));
-app.use('/', express.static('app'));
-app.use('/' + moduleName, proxy('http://' + serverName, {
- forwardPath: function(req, res) {
- return require('url').parse('/' + moduleName + req.url).path;
- },
- port: serverPort
-}));
-
-
-app.listen(process.env.npm_package_config_express_port);
--- /dev/null
+'use strict';
+
+var express = require('express');
+var app = express();
+var favicon = require('serve-favicon');
+var logger = require('morgan');
+var config = require('./server.config')();
+var port = config.port;
+var environment = process.env.NODE_ENV;
+
+app.use(favicon(__dirname + '/favicon.ico'));
+app.use(logger('dev'));
+
+switch (environment) {
+ case 'build':
+ console.log('build mode');
+
+ app.use(express.static('./build/'));
+
+ // Deep linking
+ app.use('/*', express.static('./build/index.html'));
+ break;
+ default:
+ console.log('development mode');
+
+ app.use(express.static(config.main));
+ app.use(express.static('./'));
+
+ // Deep linking
+ app.use('/*', express.static(config.index));
+ break;
+}
+
+app.listen(port, function() {
+ console.log('Express server listening on port ' + port);
+ console.log('env = ' + app.get('env') +
+ '\n __dirname = ' + __dirname +
+ '\n process.cwd = ' + process.cwd());
+});