From c23acebbd8fabd391bfeee0d424f26e59f756a03 Mon Sep 17 00:00:00 2001 From: Eddie Monge Date: Mon, 18 Nov 2013 17:23:49 -0800 Subject: [PATCH] fix(build): add webapp upstream features and better coffee Merge changes from generator-webapp and better support for coffee/js tasks BREAKING CHANGES: Coffee support in the Gruntfile is only added when the coffee flag is set. Otherwise, JS is used Fixes: #35, #440 --- app/index.js | 1 + templates/common/Gruntfile.js | 54 ++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/index.js b/app/index.js index 53ca4c189..4d88fd3b0 100644 --- a/app/index.js +++ b/app/index.js @@ -281,6 +281,7 @@ Generator.prototype.createIndexHtml = function createIndexHtml() { }; Generator.prototype.packageFiles = function () { + this.coffee = this.env.options.coffee; this.template('../../templates/common/_bower.json', 'bower.json'); this.template('../../templates/common/_package.json', 'package.json'); this.template('../../templates/common/Gruntfile.js', 'Gruntfile.js'); diff --git a/templates/common/Gruntfile.js b/templates/common/Gruntfile.js index 24fad979f..488ef9b9c 100644 --- a/templates/common/Gruntfile.js +++ b/templates/common/Gruntfile.js @@ -26,15 +26,19 @@ module.exports = function (grunt) { }, // Watches files for changes and runs tasks based on the changed files - watch: { + watch: {<% if (coffee) { %> coffee: { - files: ['<%%= yeoman.app %>/scripts/{,*/}*.coffee'], + files: ['<%%= yeoman.app %>/scripts/{,*/}*.{coffee,litcoffee,coffee.md}'], tasks: ['newer:coffee:dist'] }, coffeeTest: { - files: ['test/spec/{,*/}*.{coffee,js}'], + files: ['test/spec/{,*/}*.{coffee,litcoffee,coffee.md}'], tasks: ['newer:coffee:test', 'karma'] - },<% if (compassBootstrap) { %> + },<% } else { %> + jsTest: { + files: ['test/spec/{,*/}*.js'], + tasks: ['karma'] + },<% } %><% if (compassBootstrap) { %> compass: { files: ['<%%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], tasks: ['compass:server', 'autoprefixer'] @@ -52,9 +56,9 @@ module.exports = function (grunt) { }, files: [ '<%%= yeoman.app %>/{,*/}*.html', - '.tmp/styles/{,*/}*.css', + '.tmp/styles/{,*/}*.css',<% if (!coffee) { %> '{.tmp,<%%= yeoman.app %>}/scripts/{,*/}*.js', - '<%%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' + <% } %>'<%%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' ] } }, @@ -100,8 +104,9 @@ module.exports = function (grunt) { reporter: require('jshint-stylish') }, all: [ - 'Gruntfile.js', - '<%%= yeoman.app %>/scripts/{,*/}*.js' + 'Gruntfile.js'<% if (!coffee) { %>, + '<%%= yeoman.app %>/scripts/{,*/}*.js', + 'test/spec/{,*/}*.js'<% } %> ] }, @@ -122,7 +127,9 @@ module.exports = function (grunt) { // Add vendor prefixed styles autoprefixer: { - options: ['last 1 version'], + options: { + browsers: ['last 1 version'] + }, dist: { files: [{ expand: true, @@ -133,6 +140,7 @@ module.exports = function (grunt) { } }, + <% if (coffee) { %> // Compiles CoffeeScript to JavaScript coffee: { options: { @@ -157,8 +165,9 @@ module.exports = function (grunt) { ext: '.js' }] } - },<% if (compassBootstrap) { %> + },<% } %> + <% if (compassBootstrap) { %> // Compiles Sass to CSS and generates necessary files if requested compass: { options: { @@ -167,14 +176,19 @@ module.exports = function (grunt) { generatedImagesDir: '.tmp/images/generated', imagesDir: '<%%= yeoman.app %>/images', javascriptsDir: '<%%= yeoman.app %>/scripts', - fontsDir: '<%%= yeoman.app %>/fonts', + fontsDir: '<%%= yeoman.app %>/styles/fonts', importPath: '<%%= yeoman.app %>/bower_components', httpImagesPath: '/images', httpGeneratedImagesPath: '/images/generated', - httpFontsPath: '/fonts', - relativeAssets: false + httpFontsPath: '/styles/fonts', + relativeAssets: false, + assetCacheBuster: false + }, + dist: { + options: { + generatedImagesDir: '<%%= yeoman.dist %>/images/generated' + } }, - dist: {}, server: { options: { debugInfo: true @@ -311,18 +325,18 @@ module.exports = function (grunt) { // Run some tasks in parallel to speed up the build process concurrent: { - server: [ - 'coffee:dist',<% if (compassBootstrap) { %> + server: [<% if (coffee) { %> + 'coffee:dist',<% } %><% if (compassBootstrap) { %> 'compass:server',<% } %> 'copy:styles' ], - test: [ - 'coffee',<% if (compassBootstrap) { %> + test: [<% if (coffee) { %> + 'coffee',<% } %><% if (compassBootstrap) { %> 'compass',<% } %> 'copy:styles' ], - dist: [ - 'coffee',<% if (compassBootstrap) { %> + dist: [<% if (coffee) { %> + 'coffee',<% } %><% if (compassBootstrap) { %> 'compass:dist',<% } %> 'copy:styles', 'imagemin',