Skip to content

Instantly share code, notes, and snippets.

@carcer
Created May 1, 2014 11:32
Show Gist options
  • Save carcer/124afa076a86bd609036 to your computer and use it in GitHub Desktop.
Save carcer/124afa076a86bd609036 to your computer and use it in GitHub Desktop.
// Generated on 2013-10-09 using generator-angular 0.4.0
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir), {maxAge: 1});
};
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
// configurable paths
var yeomanConfig = {
app: 'app',
dist: 'dist'
};
try {
yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
} catch (e) {}
grunt.initConfig({
yeoman: yeomanConfig,
watch: {
coffee: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
tasks: ['coffee:dist']
},
coffeeTest: {
files: ['test/spec/{,*/}*.coffee'],
tasks: ['coffee:test']
},
styles: {
files: ['<%= yeoman.app %>/content/css/{,*/}*.scss'],
tasks: ['sass', 'copy:styles', 'autoprefixer']
},
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'<%= yeoman.app %>/Content/sass/{,*/}*.scss',
'{.tmp,<%= yeoman.app %>}/content/scripts/{,*/}*.js',
'{.tmp,<%= yeoman.app %>}/content/languages/{,*/}*.json',
'<%= yeoman.app %>/content/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
],
tasks: ['sass']
}
},
autoprefixer: {
options: ['last 1 version'],
dist: {
files: [{
expand: true,
cwd: '.tmp/content/css/',
src: '{,*/}*.css',
dest: '.tmp/content/css/'
}]
}
},
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function (connect) {
return [
lrSnippet,
mountFolder(connect, yeomanConfig.app)
];
}
}
},
test: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, 'test')
];
}
}
},
dist: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, yeomanConfig.dist)
];
}
}
}
},
open: {
server: {
url: 'http://localhost:<%= connect.options.port %>'
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*',
'release'
]
}]
},
pre: {
src: [
'release'
]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/content/scripts/{,*/}*.js',
'test/spec/{,*/}*.js'
]
},
coffee: {
options: {
sourceMap: true,
sourceRoot: ''
},
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/scripts',
src: '{,*/}*.coffee',
dest: '.tmp/scripts',
ext: '.js'
}]
},
test: {
files: [{
expand: true,
cwd: 'test/spec',
src: '{,*/}*.coffee',
dest: '.tmp/spec',
ext: '.js'
}]
}
},
// not used since Uglify task does concat,
// but still available if needed
/*concat: {
dist: {}
},*/
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/content/scripts/{,*/}*.js',
'<%= yeoman.dist %>/content/css/{,*/}*.css'
]
}
}
},
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
dest: '<%= yeoman.dist %>'
}
},
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
options: {
dirs: ['<%= yeoman.dist %>']
}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/content/images',
src: '{,*/}*.{png,jpg,jpeg}',
dest: '<%= yeoman.dist %>/content/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/content/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/content/images'
}]
}
},
cssmin: {
// By default, your `index.html` <!-- Usemin Block --> will take care of
// minification. This option is pre-configured if you do not wish to use
// Usemin blocks.
dist: {
files: {
'<%= yeoman.dist %>/content/css/style.css': [
'<%= yeoman.app %>/content/css/style.css'
],
'<%= yeoman.dist %>/content/css/legacy.css': [
'<%= yeoman.app %>/content/css/legacy.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 %>'
}]
}
},
// Put files not handled in other tasks here
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'bower_components/**/*',
'images/{,*/}*.{gif,webp}',
'content/fonts/*',
'content/languages/*',
'bin/*',
'packages.config',
'Skyscanner.WorldCup.nuspec',
'Storm.Proxy.csproj',
'web.config'
]
}, {
expand: true,
cwd: '.tmp/content/images',
dest: '<%= yeoman.dist %>/images',
src: [
'generated/*'
]
}]
},
styles: {
expand: true,
cwd: '<%= yeoman.app %>/content/css',
dest: '.tmp/content/css/',
src: '{,*/}*.css'
}
},
concurrent: {
server: [
'coffee:dist',
'copy:styles'
],
test: [
'coffee',
'copy:styles'
],
dist: [
'coffee',
'copy:styles',
'imagemin',
'svgmin',
'htmlmin'
]
},
karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: false,
autoWatch: true
},
dist: {
configFile: 'karma.conf.js',
singleRun: true,
autoWatch: true
}
},
cdnify: {
dist: {
html: ['<%= yeoman.dist %>/*.html']
}
},
ngmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.dist %>/scripts',
src: '*.js',
dest: '<%= yeoman.dist %>/scripts'
}]
}
},
uglify: {
options: {
mangle: false
},
dist: {
files: {
'<%= yeoman.dist %>/content/scripts/scripts.js': [
'<%= yeoman.dist %>/content/scripts/scripts.js'
]
}
}
},
sass: {
dist: {
options:{
outputStyle: 'compact'
},
files: {
'<%= yeoman.app %>/Content/css/style.css': '<%= yeoman.app %>/Content/sass/style.scss',
'<%= yeoman.dist %>/Content/css/style.css': '<%= yeoman.app %>/Content/sass/style.scss',
'<%= yeoman.app %>/Content/css/legacy.css': '<%= yeoman.app %>/Content/sass/legacy.scss',
'<%= yeoman.dist %>/Content/css/legacy.css': '<%= yeoman.app %>/Content/sass/legacy.scss'
}
}
},
'string-replace': {
dist: {
files: {
'<%= yeoman.dist %>/content/scripts/scripts.js': '<%= yeoman.dist %>/content/scripts/scripts.js'
},
options: {
replacements: [{
pattern: 'http://localhost:4228/',
replacement: ''
},{
pattern: '["localhost."]',
replacement: '["skyscanner.", ".web1.stormid.com"]'
}]
}
}
},
zip: {
release: {
cwd: '<%= yeoman.dist %>',
src: ['<%= yeoman.dist %>/**/*'],
dest: 'release/release.zip'
}
},
shell: {
bower: {
command: 'bower install',
options: {
stdout: true
}
},
nuget: {
command: '.nuget/nuget.exe pack dist/Storm.Proxy.csproj',
options: {
stdout: true
}
}
}
});
grunt.registerTask('server', function () {
if (grunt.option('target') === 'dist') {
return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'open',
'watch'
]);
});
grunt.registerTask('test', [
'jshint',
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test',
'karma'
]);
grunt.registerTask('test:dist', [
'jshint',
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test',
'karma:dist'
]);
grunt.registerTask('build', [
'clean:dist',
'sass:dist',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'copy:dist',
'cdnify',
'ngmin',
'cssmin',
'uglify',
'string-replace:dist',
'rev',
'usemin'
]);
grunt.registerTask('default', [
'clean:pre',
'test:dist',
'build'
]);
grunt.registerTask('release', [
'clean:pre',
'shell:bower',
'test:dist',
'build',
'shell:nuget',
'zip'
]);
};
var gulp = require('gulp'),
sass = require('gulp-sass')
minifycss = require('gulp-minify-css')
rename = require('gulp-rename')
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rev = require('gulp-rev'),
usemin = require('gulp-usemin'),
minifyhtml = require('gulp-minify-html'),
clean = require('gulp-clean')
karma = require('gulp-karma')
connect = require('gulp-connect')
;
var dest = 'dist/'
var filesToMove = [
'app/*.{ico,png,txt}',
'app/.htaccess',
'app/bower_components/**/*',
'app/content/images/{,*/}*.{gif,webp}',
'app/content/fonts/*',
'app/content/languages/*',
'app/bin/*',
'app/packages.config',
'app/Skyscanner.WorldCup.nuspec',
'app/Storm.Proxy.csproj',
'app/web.config'
];
gulp.task('styles', function() {
gulp.src('app/content/sass/*.scss')
.pipe(sass({style: 'expanded'}))
.pipe(gulp.dest([dest + 'content/css', './app/content/css']))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(dest + 'content/css'));
});
gulp.task('jshint', function() {
return gulp.src('app/content/scripts/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(gulp.dest(dest + 'content/scripts'));
});
gulp.task('usemin', function() {
gulp.src('app/*.html')
.pipe(usemin({
html: [minifyhtml({empty: true})],
js: [uglify(), rev()]
}))
.pipe(gulp.dest(dest));
});
gulp.task('clean', function() {
return gulp.src([dest], {read: false})
.pipe(clean());
});
gulp.task('move', function(){
gulp.src(filesToMove, {base: './app'})
.pipe(gulp.dest(dest));
});
gulp.task('test', function() {
return gulp.src('./foobar')
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}))
});
gulp.task('connect', function() {
connect.server({
root: 'app',
livereload: true
});
});
gulp.task('html', function () {
gulp.src('./app/*.html')
.pipe(connect.reload());
});
gulp.task('watch', ['connect'],function () {
gulp.watch(['gulpfile.js','./app/*.html', './app/content/scripts/**/*.js'], ['styles', 'html']);
});
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'jshint', 'usemin', 'move');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment