diff --git a/package.json b/package.json index 562ff2b..a9b882e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slush-angular", - "version": "0.4.5", + "version": "0.4.6", "description": "A slush generator for AngularJS using the Google Angular App Structure Recommendations", "main": "slushfile.js", "scripts": { diff --git a/slushfile.js b/slushfile.js index 182a548..95a3617 100644 --- a/slushfile.js +++ b/slushfile.js @@ -38,6 +38,7 @@ gulp.task('default', function (done) { {name: 'LESS', value: 'less'}, {name: 'Sass', value: 'sass'} ]}, + {type: 'confirm', name: 'middleware', message: 'Do you want to use middleware for proxy support?', default: false}, {type: 'confirm', name: 'coffee', message: 'Do you want to use CoffeeScript in your app?', default: false}, {type: 'confirm', name: 'example', message: 'Do you want to include a Todo List example in your app?', default: true} ], diff --git a/templates/gulpfile.js b/templates/gulpfile.js index 15023fa..754ed7e 100644 --- a/templates/gulpfile.js +++ b/templates/gulpfile.js @@ -11,6 +11,12 @@ var gulp = require('gulp'), lazypipe = require('lazypipe'), stylish = require('jshint-stylish'), bower = require('./bower'), + <%if(middleware){%> + proxy = require('proxy-middleware'), + url = require('url'), + connect = require('gulp-connect'), + _ = require('lodash'), + <%}%> isWatching = false; var htmlminOpts = { @@ -21,6 +27,19 @@ var htmlminOpts = { removeRedundantAttributes: true }; + +<%if(middleware){%> + //Configure your proxy for integrating with services + var proxyOptions = _.extend(url.parse('http://demo-venkatvp.rhcloud.com/services'), { + route: '/services', + headers: { + 'Origin': 'http://yourdomain.com', + 'Access-Control-Request-Method': 'GET', + 'Access-Control-Request-Headers': 'X-Custom-Header' + } + }); +<%}%> + /** * JS Hint */ @@ -145,6 +164,7 @@ gulp.task('dist', ['vendors', 'assets', 'styles-dist', 'scripts-dist'], function .pipe(gulp.dest('./dist/')); }); +<%if(!middleware){%> /** * Static file server */ @@ -152,7 +172,6 @@ gulp.task('statics', g.serve({ port: 3000, root: ['./.tmp', './.tmp/src/app', './src/app', './bower_components'] })); - /** * Watch */ @@ -179,6 +198,37 @@ gulp.task('watch', ['statics', 'default'], function () { } }); }); +<%} else {%> +/** +* connect server with middleware +*/ +gulp.task('connect', function() { + connect.server({ + root: ['./.tmp', './.tmp/src/app', './src/app', './bower_components'], + port: 3000, + livereload: true, + middleware: function() { + return [(function() { + return proxy(proxyOptions); + })()]; + } + }); +}); +/** + * Watch + */ +gulp.task('serve', ['watch']); +gulp.task('watch', ['connect', 'default'], function() { + isWatching = true; + // Initiate livereload server: + <% if (coffee) { %> + gulp.watch('./src/app/**/*.coffee', ['coffee']);<% } %> + gulp.watch('./<% if (coffee) { %>.tmp/<% } %>src/app/**/*.js', ['jshint']); + gulp.watch('./src/app/index.html', ['index']); + gulp.watch(['./src/app/**/*.html', '!./src/app/index.html'], ['templates']); + gulp.watch(['./src/app/**/*.less'], ['csslint']); +}); +<%} %> /** * Default task @@ -310,11 +360,15 @@ function dist (ext, name, opt) { /** * Livereload (or noop if not run by watch) */ -function livereload () { - return lazypipe() - .pipe(isWatching ? g.livereload : noop)(); +function livereload() { <% + if (middleware) { %> + return lazypipe() + .pipe(isWatching ? connect.reload : noop)(); <% + } else { %> + return lazypipe() + .pipe(isWatching ? g.livereload : noop)(); <% + } %> } - /** * Jshint with stylish reporter */ diff --git a/templates/package.json b/templates/package.json index e69cebe..ee84658 100644 --- a/templates/package.json +++ b/templates/package.json @@ -47,6 +47,10 @@ "karma-script-launcher": "~0.1.0", "karma-chrome-launcher": "~0.1.4", "karma-firefox-launcher": "~0.1.3", - "karma": "~0.12.16" + "karma": "~0.12.16"<% if (middleware) { %>, + "proxy-middleware": "^0.9.0", + "url": "^0.10.2", + "gulp-connect": "^2.2.0", + "lodash": "^3.0.0"<% } %> } } diff --git a/test/slush-angular_test.js b/test/slush-angular_test.js index f4e46d3..11d5153 100644 --- a/test/slush-angular_test.js +++ b/test/slush-angular_test.js @@ -108,6 +108,35 @@ describe('slush-angular', function() { }); }); + describe('Middleware Example', function () { + + it('should generate template with middleware and LESS', function (done) { + mockPrompt({name: 'module', csstype: 'less', example: true, middleware : true}); + + gulp.start('default').once('stop', function () { + mockGulpDest.assertDestContains([ + 'src/app/app.less', + 'src/app/styles/_base.less', + 'src/app/todo/todo.less' + ]); + done(); + }); + }); + + it('should generate template with middleware and sass', function (done) { + mockPrompt({name: 'module', csstype: 'sass', example: true, middleware : true}); + + gulp.start('default').once('stop', function () { + mockGulpDest.assertDestContains([ + 'src/app/app.scss', + 'src/app/styles/_base.scss', + 'src/app/todo/todo.scss' + ]); + done(); + }); + }); + }); + describe('Todo example', function () { it('should not add any todo example files by default', function (done) { mockPrompt({name: 'module', example: false});