Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions slushfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
],
Expand Down
64 changes: 59 additions & 5 deletions templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
*/
Expand Down Expand Up @@ -145,14 +164,14 @@ gulp.task('dist', ['vendors', 'assets', 'styles-dist', 'scripts-dist'], function
.pipe(gulp.dest('./dist/'));
});

<%if(!middleware){%>
/**
* Static file server
*/
gulp.task('statics', g.serve({
port: 3000,
root: ['./.tmp', './.tmp/src/app', './src/app', './bower_components']
}));

/**
* Watch
*/
Expand All @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
6 changes: 5 additions & 1 deletion templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"<% } %>
}
}
29 changes: 29 additions & 0 deletions test/slush-angular_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down