Skip to content

Instantly share code, notes, and snippets.

@sescobb27
Created December 15, 2015 18:37
Show Gist options
  • Save sescobb27/f5eb91f6363ef1c27483 to your computer and use it in GitHub Desktop.
Save sescobb27/f5eb91f6363ef1c27483 to your computer and use it in GitHub Desktop.
// Generated on 2014-11-18 using generator-angular-fullstack 2.0.13
'use strict';
module.exports = function (grunt) {
// Load grunt tasks automatically, when needed
require('jit-grunt')(grunt, {
express: 'grunt-express-server',
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
protractor: 'grunt-protractor-runner',
injector: 'grunt-asset-injector'
});
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
var appConfig = {
// configurable paths
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
pkg: grunt.file.readJSON('package.json'),
yeoman: appConfig,
open: {
server: {
url: 'http://festinare.com.co'
}
},
watch: {
injectJS: {
files: [
'<%= yeoman.app %>/scripts/**/*.js',
'!<%= yeoman.app %>/scripts/**/*.spec.js',
'!<%= yeoman.app %>/scripts/**/*.mock.js',
'!<%= yeoman.app %>/scripts/app.js'
],
tasks: ['injector:scripts']
},
injectCss: {
files: [
'<%= yeoman.app %>/{styles,scripts}/**/*.css'
],
tasks: ['injector:css']
},
mochaTest: {
files: ['server/**/*.spec.js'],
tasks: ['env:test', 'mochaTest']
},
jsTest: {
files: [
'<%= yeoman.app %>/scripts/**/*.spec.js',
'<%= yeoman.app %>/scripts/**/*.mock.js'
],
tasks: ['newer:jshint:all', 'karma']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
files: [
'{.tmp,<%= yeoman.app %>}/{scripts,styles}/**/*.css',
'{.tmp,<%= yeoman.app %>}/{scripts,styles}/**/*.html',
'{.tmp,<%= yeoman.app %>}/{scripts,styles}/**/*.js',
'!{.tmp,<%= yeoman.app %>}{scripts,styles}/**/*.spec.js',
'!{.tmp,<%= yeoman.app %>}/{scripts,styles}/**/*.mock.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
],
options: {
livereload: true
}
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '<%= yeoman.app %>/.jshintrc',
reporter: require('jshint-stylish')
},
server: {
options: {
jshintrc: 'server/.jshintrc'
},
src: [
'server/**/*.js',
'!server/**/*.spec.js'
]
},
serverTest: {
options: {
jshintrc: 'server/.jshintrc-spec'
},
src: ['server/**/*.spec.js']
},
all: [
'<%= yeoman.app %>/{scripts}/**/*.js',
'!<%= yeoman.app %>/{scripts}/**/*.spec.js',
'!<%= yeoman.app %>/{scripts}/**/*.mock.js'
],
test: {
src: [
'<%= yeoman.app %>/{scripts}/**/*.spec.js',
'<%= yeoman.app %>/{scripts}/**/*.mock.js'
]
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*',
'!<%= yeoman.dist %>/.openshift',
'!<%= yeoman.dist %>/Procfile'
]
}]
},
server: '.tmp'
},
// Add vendor prefixed styles
autoprefixer: {
options: {
browsers: ['last 1 version']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/',
src: '{,*/}*.css',
dest: '.tmp/'
}]
}
},
// Automatically inject Bower components into the app
wiredep: {
target: {
src: '<%= yeoman.app %>/index.html',
exclude: ['/json3/', '/es5-shim/'],
fileTypes: {
html: {
replace: {
js: '<script src=\"{{filePath}}\"></script>',
css: '<link rel="stylesheet" href=\"{{filePath}}\"/>',
}
}
}
}
},
// Renames files for browser caching purposes
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/app/{,*/}*.js',
'<%= yeoman.dist %>/app/{,*/}*.css',
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'<%= yeoman.dist %>/assets/fonts/*'
]
}
}
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
html: ['<%= yeoman.app %>/index.html'],
options: {
dest: '<%= yeoman.dist %>'
}
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/app/{,*/}*.css'],
js: ['<%= yeoman.dist %>/app/{,*/}*.js'],
options: {
assetsDirs: [
'<%= yeoman.dist %>',
'<%= yeoman.dist %>/images'
],
// This is so we update image references in our ng-templates
patterns: {
js: [
[/(images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
]
}
}
},
// The following *-min tasks produce minified files in the dist folder
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg,gif}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
// Allow the use of non-minsafe AngularJS files. Automatically makes it
// minsafe compatible so Uglify does not destroy the ng references
ngAnnotate: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat',
src: '*/**.js',
dest: '.tmp/concat'
}]
}
},
// Package all the html partials into a single javascript payload
ngtemplates: {
options: {
// This should be the name of your apps angular module
module: 'festinare',
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
usemin: 'app/scripts.js'
},
main: {
cwd: 'app',
src: ['scripts/**/*.html'],
dest: '.tmp/templates.js'
},
tmp: {
cwd: '.tmp',
src: ['scripts/**/*.html'],
dest: '.tmp/tmp-templates.js'
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'bower_components/**/*',
'images/{,*/}*.{webp}',
'assets/fonts/**/*',
'index.html',
'404.html'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= yeoman.dist %>/images',
src: ['generated/*']
}]
},
styles: {
expand: true,
cwd: '<%= yeoman.app %>',
dest: '.tmp/',
src: ['{scripts,styles}/**/*.css']
}
},
// Run some tasks in parallel to speed up the build process
concurrent: {
dist: [
'imagemin',
'svgmin'
]
},
injector: {
options: {
},
// Inject application script files into index.html (doesn't include bower)
scripts: {
options: {
transform: function (filePath) {
filePath = filePath.replace('/app/', '');
filePath = filePath.replace('/.tmp/', '');
return '<script src="' + filePath + '"></script>';
},
starttag: '<!-- injector:js -->',
endtag: '<!-- endinjector -->'
},
files: {
'<%= yeoman.app %>/index.html': [
['{.tmp,<%= yeoman.app %>}/scripts/**/*.js',
'!{.tmp,<%= yeoman.app %>}/scripts/app.js',
'!{.tmp,<%= yeoman.app %>}/scripts/**/*.spec.js',
'!{.tmp,<%= yeoman.app %>}/scripts/**/*.mock.js']
]
}
},
// Inject component css into index.html
css: {
options: {
transform: function (filePath) {
filePath = filePath.replace('/app/', '');
filePath = filePath.replace('/.tmp/', '');
return '<link rel="stylesheet" href="' + filePath + '">';
},
starttag: '<!-- injector:css -->',
endtag: '<!-- endinjector -->'
},
files: {
'<%= yeoman.app %>/index.html': [
'<%= yeoman.app %>/{scripts,styles}/**/*.css'
]
}
}
}
});
// Used for delaying livereload until after server has restarted
grunt.registerTask('wait', function () {
grunt.log.ok('Waiting for server reload...');
var done = this.async();
setTimeout(function () {
grunt.log.writeln('Done waiting!');
done();
}, 1500);
});
grunt.registerTask('serve', function () {
grunt.task.run([
'clean:server',
'injector',
'wiredep',
'autoprefixer',
'wait',
'open',
'watch'
]);
});
grunt.registerTask('test', function (target) {
if (target === 'server') {
return grunt.task.run([
'env:all',
'env:test',
'mochaTest'
]);
} else if (target === 'client') {
return grunt.task.run([
'clean:server',
'env:all',
'concurrent:test',
'injector',
'autoprefixer',
'karma'
]);
} else if (target === 'e2e') {
var generalTasks = [
'clean:server',
'env:all',
'env:test',
'concurrent:test',
'injector',
'wiredep',
'autoprefixer',
'express:dev'
];
return grunt.task.run(generalTasks);
} else {
grunt.task.run(['test:server', 'test:client']);
}
});
grunt.registerTask('build', [
'clean:dist',
'concurrent:dist',
'injector',
'wiredep',
'useminPrepare',
'autoprefixer',
'ngtemplates',
'concat',
'ngAnnotate',
'copy:dist',
'cssmin',
'uglify',
'rev',
'usemin'
]);
grunt.registerTask('default', [
'newer:jshint',
'test',
'build'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment