-
-
Save doowb/5456988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet; | |
var mountFolder = function (connect, dir) { | |
return connect.static(require('path').resolve(dir)); | |
}; | |
module.exports = function (grunt) { | |
// load all grunt tasks | |
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
// Import custom tasks | |
//grunt.loadTasks( "scripts/build/tasks" ); | |
// configurable paths | |
var yeomanConfig = { | |
app: 'app', | |
dist: 'dist/static' | |
}; | |
try { | |
yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app; | |
} catch (e) {} | |
grunt.initConfig({ | |
yeoman: yeomanConfig, | |
watch: { | |
compass: { | |
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], | |
tasks: ['compass'] | |
}, | |
livereload: { | |
files: [ | |
'<%= yeoman.app %>/{,*/}*.html', | |
'{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css', | |
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js', | |
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' | |
], | |
tasks: ['livereload'] | |
}, | |
debug: { | |
files: ['<%= watch.livereload.files %>'], | |
tasks: ['livereload', 'jshint', 'karma:unit'] | |
}, | |
}, | |
connect: { | |
options: { | |
port: 9000, | |
hostname: '0.0.0.0' | |
}, | |
livereload: { | |
options: { | |
middleware: function (connect) { | |
return [ | |
lrSnippet, | |
mountFolder(connect, '.tmp'), | |
mountFolder(connect, yeomanConfig.app) | |
]; | |
} | |
} | |
}, | |
test: { | |
options: { | |
middleware: function (connect) { | |
return [ | |
mountFolder(connect, '.tmp'), | |
mountFolder(connect, 'test') | |
]; | |
} | |
} | |
} | |
}, | |
open: { | |
server: { | |
url: 'http://localhost:<%= connect.options.port %>' | |
} | |
}, | |
clean: { | |
dist: { | |
files: [{ | |
dot: true, | |
src: [ | |
'.tmp', | |
'<%= yeoman.dist %>/*', | |
'!<%= yeoman.dist %>/.git*' | |
] | |
}] | |
}, | |
server: '.tmp' | |
}, | |
jshint: { | |
options: { | |
jshintrc: '.jshintrc' | |
}, | |
all: [ | |
'Gruntfile.js', | |
'<%= yeoman.app %>/scripts/{,*/}*.js' | |
] | |
}, | |
karma: { | |
unit: { | |
configFile: 'karma.conf.js', | |
singleRun: true | |
} | |
}, | |
compass: { | |
options: { | |
sassDir: '<%= yeoman.app %>/styles', | |
cssDir: '.tmp/styles', | |
imagesDir: '<%= yeoman.app %>/images', | |
javascriptsDir: '<%= yeoman.app %>/scripts', | |
fontsDir: '<%= yeoman.app %>/styles/fonts', | |
importPath: '<%= yeoman.app %>/components', | |
relativeAssets: true | |
}, | |
dist: {}, | |
server: { | |
options: { | |
debugInfo: true | |
} | |
} | |
}, | |
concat: { | |
dist: { | |
files: { | |
'<%= yeoman.dist %>/scripts/scripts.js': [ | |
'.tmp/scripts/{,*/}*.js', | |
'<%= yeoman.app %>/scripts/{,*/}*.js' | |
] | |
} | |
} | |
}, | |
useminPrepare: { | |
html: '<%= yeoman.app %>/index.html', | |
options: { | |
dest: '<%= yeoman.dist %>' | |
} | |
}, | |
usemin: { | |
html: ['<%= yeoman.dist %>/{,*/}*.html'], | |
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'], | |
options: { | |
dirs: ['<%= yeoman.dist %>'] | |
} | |
}, | |
imagemin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>/images', | |
src: '{,*/}*.{png,jpg,jpeg}', | |
dest: '<%= yeoman.dist %>/images' | |
}] | |
} | |
}, | |
cssmin: { | |
dist: { | |
files: { | |
'<%= yeoman.dist %>/styles/main.css': [ | |
'.tmp/styles/{,*/}*.css', | |
'<%= yeoman.app %>/styles/{,*/}*.css' | |
] | |
} | |
} | |
}, | |
htmlmin: { | |
dist: { | |
options: { | |
/*removeCommentsFromCDATA: true, | |
// https://github.com/yeoman/grunt-usemin/issues/44 | |
//collapseWhitespace: true, | |
collapseBooleanAttributes: true, | |
removeAttributeQuotes: true, | |
removeRedundantAttributes: true, | |
useShortDoctype: true, | |
removeEmptyAttributes: true, | |
removeOptionalTags: true*/ | |
}, | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>', | |
src: ['*.html', 'views/*.html'], | |
dest: '<%= yeoman.dist %>' | |
}] | |
} | |
}, | |
cdnify: { | |
dist: { | |
html: ['<%= yeoman.dist %>/*.html'] | |
} | |
}, | |
ngmin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.dist %>/scripts', | |
src: '*.js', | |
dest: '<%= yeoman.dist %>/scripts' | |
}] | |
} | |
}, | |
uglify: { | |
dist: { | |
files: { | |
'<%= yeoman.dist %>/scripts/scripts.js': [ | |
'<%= yeoman.dist %>/scripts/scripts.js' | |
], | |
} | |
} | |
}, | |
rev: { | |
dist: { | |
files: { | |
src: [ | |
'<%= yeoman.dist %>/scripts/{,*/}*.js', | |
'<%= yeoman.dist %>/styles/{,*/}*.css', | |
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}', | |
'<%= yeoman.dist %>/styles/fonts/*' | |
] | |
} | |
} | |
}, | |
copy: { | |
dist: { | |
files: [{ | |
expand: true, | |
dot: true, | |
cwd: '<%= yeoman.app %>', | |
dest: '<%= yeoman.dist %>', | |
src: [ | |
'*.{ico,txt}', | |
'.htaccess', | |
'components/**/*', | |
'_test/**/*', | |
'images/{,*/}*.{gif,webp}' | |
] | |
}] | |
} | |
}, | |
'saucelabs-qunit': { | |
all: { | |
username: process.env.SAUCE_USER_NAME, | |
key: process.env.SAUCE_API_KEY, | |
urls: [process.env.STATIC_SERVER_URL + '_test/index.html'], | |
tunneled: false, | |
browsers: [{ | |
browserName: process.env.SELENIUM_BROWSER, | |
platform: process.env.SELENIUM_PLATFORM, | |
'parent-tunnel': process.env.SAUCE_TUNNEL | |
}], | |
'parent-tunnel': process.env.SAUCE_TUNNEL | |
} | |
} | |
}); | |
grunt.renameTask('regarde', 'watch'); | |
grunt.registerTask('server', [ | |
'clean:server', | |
'compass:server', | |
'livereload-start', | |
'connect:livereload', | |
'open', | |
'watch' | |
]); | |
grunt.registerTask('debug', 'Debug server with continous linting and unit testing', function () { | |
grunt.option('force', true); | |
var tasks = [ | |
'clean:server', | |
'compass:server', | |
'livereload-start', | |
'connect:livereload', | |
'open', | |
'watch:debug' | |
]; | |
grunt.task.run(tasks); | |
}); | |
grunt.registerTask('test', [ | |
'jshint', | |
'clean:server', | |
'compass', | |
'connect:test', | |
'karma' | |
]); | |
grunt.registerTask('build', [ | |
'clean:dist', | |
'jshint', | |
'test', | |
'compass:dist', | |
'useminPrepare', | |
'imagemin', | |
'cssmin', | |
'htmlmin', | |
'concat', | |
'copy', | |
'cdnify', | |
'ngmin', | |
'uglify', | |
'usemin', | |
'multi-browser-unit-tests', | |
]); | |
grunt.registerTask('default', ['build']); | |
grunt.registerTask( 'multi-browser-unit-tests', 'Run unit tests in our supported browser matrix', function() { | |
if (process.env.SAUCE_API_KEY) { | |
grunt.task.run(['saucelabs-qunit']); | |
} else { | |
grunt.log.writeln('Skipping multiple browser unit testing, because SAUCE_API_KEY is missing'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment