Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
fix(gen): gulpfile.js generation fixes
Browse files Browse the repository at this point in the history
Fixes for a bunch of issues with gulpfile.js with @bumprat code

#1299
  • Loading branch information
Alexander Deider committed May 17, 2016
1 parent cb9d420 commit 28064ce
Showing 1 changed file with 66 additions and 36 deletions.
102 changes: 66 additions & 36 deletions templates/common/root/_gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,32 @@ var runSequence = require('run-sequence');

var yeoman = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
dist: 'dist',
temp: '.tmp',
test: 'test'
};

var jsx = '<% if (coffee) { %>coffee<% } else { %>js<% } %>';
var cssx = '<% if (sass) { %>scss<% } else { %>css<% } %>';

var paths = {
scripts: [yeoman.app + '/scripts/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'],
styles: [yeoman.app + '/styles/**/*.<% if (sass) { %>scss<% } else { %>css<% } %>'],
test: ['test/spec/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'],
scripts: [yeoman.app + '/scripts/**/*.' + jsx],
styles: [yeoman.app + '/styles/**/*.' + cssx],
test: ['test/spec/**/*.' + jsx],
testRequire: [
yeoman.app + '/bower_components/angular/angular.js',
yeoman.app + '/bower_components/angular-mocks/angular-mocks.js',
yeoman.app + '/bower_components/angular-resource/angular-resource.js',
yeoman.app + '/bower_components/angular-cookies/angular-cookies.js',
yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js',
yeoman.app + '/bower_components/angular-route/angular-route.js',<% if (coffee) { %>
'test/mock/**/*.coffee',
'test/spec/**/*.coffee'<% } else { %>
'test/mock/**/*.js',
'test/spec/**/*.js'<% } %>
yeoman.app + '/bower_components/angular-route/angular-route.js',
'test/mock/**/*.' + jsx,
'test/spec/**/*.' + jsx
],
karma: 'karma.conf.js',
views: {
main: yeoman.app + '/index.html',
bowermain: yeoman.temp + '/index.html',
files: [yeoman.app + '/views/**/*.html']
}
};
Expand All @@ -44,21 +48,29 @@ var paths = {
var lintScripts = lazypipe()<% if (coffee) { %>
.pipe($.coffeelint)
.pipe($.coffeelint.reporter);<% } else { %>
.pipe($.jshint, '.jshintrc')
.pipe($.jshint/*, '.jshintrc'*/)
.pipe($.jshint.reporter, 'jshint-stylish');<% } %>

var styles = lazypipe()<% if (sass) { %>
.pipe($.sass, {
outputStyle: 'expanded',
precision: 10
})<% } %>
.pipe($.autoprefixer, 'last 1 version')
.pipe(gulp.dest, '.tmp/styles');
.pipe($.autoprefixer, {browsers: ['last 2 version']})
.pipe(gulp.dest, yeoman.temp + '/styles');

///////////
// Tasks //
///////////

// get arguments
var argv = {};
process.argv.forEach(function(arg, index, all){
if (arg[0] == '-' && (index + 1 < all.length)) {
argv[arg.substr(1)] = all[index+1];
}
});

gulp.task('styles', function () {
return gulp.src(paths.styles)
.pipe(styles());
Expand All @@ -68,7 +80,7 @@ gulp.task('coffee', function() {
return gulp.src(paths.scripts)
.pipe(lintScripts())
.pipe($.coffee({bare: true}).on('error', $.util.log))
.pipe(gulp.dest('.tmp/scripts'));
.pipe(gulp.dest(yeoman.temp + '/scripts'));
});<% } %>

gulp.task('lint:scripts', function () {
Expand All @@ -77,27 +89,29 @@ gulp.task('lint:scripts', function () {
});

gulp.task('clean:tmp', function (cb) {
rimraf('./.tmp', cb);
rimraf(yeoman.temp, cb);
});

gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } %>'styles'], function () {
gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } else {%> 'lint:scripts', <%} %>'styles'], function () {
openURL('http://localhost:9000');
});

gulp.task('start:server', function() {
$.connect.server({
root: [yeoman.app, '.tmp'],
root: [yeoman.app, yeoman.temp],
livereload: true,
// Change this to '0.0.0.0' to access the server from outside.
port: 9000
port: 9000,
middleware: serveStaticBower
});
});

gulp.task('start:server:test', function() {
$.connect.server({
root: ['test', yeoman.app, '.tmp'],
root: [yeoman.test, yeoman.app, yeoman.temp],
livereload: true,
port: 9001
port: 9001,
middleware: serveStaticBower
});
});

Expand All @@ -113,30 +127,34 @@ gulp.task('watch', function () {

$.watch(paths.scripts)
.pipe($.plumber())
.pipe(lintScripts())<% if (coffee) { %>
.pipe(lintScripts())
<% if (coffee) { %>
.pipe($.coffee({bare: true}).on('error', $.util.log))
.pipe(gulp.dest('.tmp/scripts'))<% } %>
.pipe(gulp.dest(yeoman.temp + '/scripts'))
<% } %>
.pipe($.connect.reload());

$.watch(paths.test)
.pipe($.plumber())
.pipe(lintScripts());
.pipe($.plumber());

gulp.watch('bower.json', ['bower']);
});

gulp.task('serve', function (cb) {
runSequence('clean:tmp',
['bower'],
['lint:scripts'],
['start:client'],
'watch', cb);
});

// gulp serve:prod -port 8080
gulp.task('serve:prod', function() {
$.connect.server({
root: [yeoman.dist],
livereload: true,
port: 9000
livereload: true
port: argv.port || 80,
middleware: serveStaticBower
});
});
Expand All @@ -153,35 +171,36 @@ gulp.task('test', ['start:server:test'], function () {
gulp.task('bower', function () {
return gulp.src(paths.views.main)
.pipe(wiredep({
directory: yeoman.app + '/bower_components',
directory: /*yeoman.app + */'/bower_components',
ignorePath: '..'
}))
.pipe(gulp.dest(yeoman.app + '/views'));
// .pipe(gulp.dest(yeoman.app + '/views'));
.pipe(gulp.dest(yeoman.temp));
});

///////////
// Build //
///////////

gulp.task('clean:dist', function (cb) {
rimraf('./dist', cb);
rimraf(yeoman.dist, cb);
});

gulp.task('client:build', ['html', 'styles'], function () {
gulp.task('client:build', ['bower', 'html', 'styles'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');

return gulp.src(paths.views.main)
.pipe($.useref({searchPath: [yeoman.app, '.tmp']}))
return gulp.src(paths.views.bowermain)
.pipe($.useref({searchPath: [yeoman.app, yeoman.temp]}))
.pipe(jsFilter)
.pipe($.ngAnnotate())
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.minifyCss({cache: true}))
.pipe(cssFilter.restore())
.pipe($.rev())
.pipe($.revReplace())
// .pipe($.rev())
// .pipe($.revReplace())
.pipe(gulp.dest(yeoman.dist));
});

Expand All @@ -205,13 +224,24 @@ gulp.task('copy:extras', function () {
.pipe(gulp.dest(yeoman.dist));
});

gulp.task('copy:favicon', function () {
return gulp.src(yeoman.app + '/favicon.ico')
.pipe(gulp.dest(yeoman.dist));
});

gulp.task('copy:fonts', function () {
return gulp.src(yeoman.app + '/fonts/**/*')
return gulp.src('./bower_components/bootstrap/dist/fonts/**/*')
.pipe(gulp.dest(yeoman.dist + '/fonts'));
});

gulp.task('build', ['clean:dist'], function () {
runSequence(['images', 'copy:extras', 'copy:fonts', 'client:build']);
gulp.task('build', ['clean:dist', 'bower'], function () {
runSequence(['images', 'copy:extras', 'copy:fonts', 'copy:favicon', 'client:build']);
});

gulp.task('wiredep', ['bower']);
gulp.task('default', ['build']);


function serveStaticBower(connect, opt){
return [['/bower_components', connect.static('./bower_components')]
]}

0 comments on commit 28064ce

Please sign in to comment.