Skip to content

Instantly share code, notes, and snippets.

@curiouslychase
Created November 12, 2013 03:57
Show Gist options
  • Save curiouslychase/7425232 to your computer and use it in GitHub Desktop.
Save curiouslychase/7425232 to your computer and use it in GitHub Desktop.
My Gruntfile for realchaseadams.com
// Generated on 2013-08-07 using generator-jekyllrb 0.3.6. Yo Jekyll!
'use strict';
var liveReloadPort = 35729;
var packagejson = require('./package.json');
var lrSnippet = require('connect-livereload')({port: liveReloadPort});
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
var yeomanConfig = {
pkg: packagejson,
app: 'src',
dist: 'dist'
};
// Directory reference:
// css: css
// sass: _sass
// javascript: js
// images: image
// fonts: fonts
module.exports = function (grunt) {
// Configuration
grunt.initConfig({
yeoman: yeomanConfig,
watch: {
sass: {
files: ['<%= yeoman.app %>/_sass/*.{scss,sass}'],
tasks: ['sass:server']
},
prefixCss: {
files: ['<%= yeoman.app %>/css/*.css'],
tasks: ['copy:stageCss', 'autoprefixer:server']
},
jekyll: {
files: ['<%= yeoman.app %>/{_posts,_layouts,_includes,_drafts}/**/*.{html,yml,md,mkd,markdown}',
'<%= yeoman.app %>/*.{html,yml,md,mkd,markdown}',
'<%= yeoman.app %>/_config.yml'],
tasks: ['jekyll:server']
},
livereload: {
options: {
livereload: liveReloadPort
},
files: [
'.jekyll/[0-9A-Za-z]/**/*.html',
'.tmp/css/*.css',
'<%= yeoman.app %>/image',
'{.tmp,<%= yeoman.app %>}/js/*.js'
]
}
},
connect: {
options: {
port: 9000,
// Change hostname to null to access the server from outside.
hostname: 'localhost'
},
livereload: {
options: {
middleware: function (connect) {
return [
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, '.jekyll'),
mountFolder(connect, yeomanConfig.app)
];
}
}
},
dist: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, yeomanConfig.dist)
];
}
}
}
},
open: {
server: {
path: 'http://dev.realchaseadams.com:<%= connect.options.port %>/'
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*',
'<%= yeoman.app %>/css'
]
}]
},
server: ['.tmp', '.jekyll']
},
sass: {
options: {
bundleExec: true,
debugInfo: false,
lineNumbers: false,
loadPath: '<%= yeoman.app %>/_sass'
},
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/_sass',
src: '**/*.{scss,sass}',
dest: '<%= yeoman.app %>/css',
filter: 'isFile',
ext: '.css'
}]
},
server: {
options: {
debugInfo: true,
lineNumbers: true
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>/_sass',
src: '**/*.{scss,sass}',
dest: '.tmp/css',
filter: 'isFile',
ext: '.css'
}]
}
},
autoprefixer: {
options: {
browsers: ['last 2 versions']
},
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.dist %>/css',
src: '**/*.css',
dest: '<%= yeoman.dist %>/css'
}]
},
server: {
files: [{
expand: true,
cwd: '.tmp/css',
src: '**/*.css',
dest: '.tmp/css'
}]
}
},
jekyll: {
options: {
bundleExec: true,
src : '<%= yeoman.app %>'
},
dist: {
options: {
dest: '<%= yeoman.dist %>',
config: '<%= yeoman.app %>/_config.yml,<%= yeoman.app %>/_config.build.yml'
}
},
server: {
options: {
dest: '.jekyll',
config: '<%= yeoman.app %>/_config.dev.yml,<%= yeoman.app %>/_config.yml',
drafts: true
}
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'{.tmp,<%= yeoman.app %>}/js/**/*.js',
'test/spec/**/*.js',
'!<%= yeoman.app %>/js/vendor/**/*',
'!<%= yeoman.app %>/lib/**/*'
],
report: [
'{.tmp,<%= yeoman.app %>}/js/**/*.js',
'!<%= yeoman.app %>/js/vendor/**/*'
]
},
csscss: {
options: {
bundleExec: true,
minMatch: 2,
ignoreSassMixins: false,
colorize: true,
shorthand: false,
verbose: true
},
// Add files to be tested here
report: {
src: ['<%= yeoman.app %>/css/**/*.css',
'<%= yeoman.app %>/_sass/**/*.scss',
'<%= yeoman.app %>/_sass/**/*.sass']
}
},
csslint: {
options: {
csslintrc: '.csslintrc'
},
report: {
src: ['{.tmp,<%= yeoman.app %>}/css/**/*.css']
}
},
// UseminPrepare will only scan one page for usemin blocks. If you have
// usemin blocks that aren't used in index.html, create a usemin manifest
// page (hackery!) and point this task there.
useminPrepare: {
options: {
dest: '<%= yeoman.dist %>'
},
html: '<%= yeoman.dist %>/index.html'
},
usemin: {
options: {
basedir: '<%= yeoman.dist %>',
dirs: ['<%= yeoman.dist %>/**/*']
},
html: ['<%= yeoman.dist %>/**/*.html', '!<%= yeoman.dist %>/lib/**/*.html'],
css: ['<%= yeoman.dist %>/css/**/*.css']
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: ['**/*.html'],
dest: '<%= yeoman.dist %>'
}]
}
},
// Usemin adds files to concat
concat: {},
// Usemin adds files to uglify
uglify: {
options: {
banner: '/*! <%= yeoman.pkg.name %> - v<%= yeoman.pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
}
},
// Usemin adds files to cssmin
cssmin: {
dist: {
options: {
report: 'gzip'
}
},
},
imagemin: {
dist: {
options: {
progressive: true
},
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: '**/*.{jpg,jpeg,png}',
dest: '<%= yeoman.dist %>'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: '**/*.svg',
dest: '<%= yeoman.dist %>'
}]
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
src: [
// Jekyll moves all html and text files. Usemin moves css and js
// files with concat. Add other files and patterns your site
// reqires for distrobution here, e.g., Bower components that
// aren't in a usemin block.
// 'js/lib/jquery.min.js',
// Copy moves asset files and directories
'*.{ico,png}',
'image/**/*'
],
dest: '<%= yeoman.dist %>'
}, {
expand: true,
cwd: '<%= yeoman.app %>/_lib/font-awesome',
src: 'css/font-awesome.css',
dest: '<%= yeoman.app %>'
}, {
expand: true,
cwd: '<%= yeoman.app %>/_lib/font-awesome',
src: 'css/font-awesome.css',
dest: '<%= yeoman.dist %>'
}, {
expand: true,
cwd: '<%= yeoman.app %>/_lib/font-awesome',
src: 'fonts/*',
dest: '<%= yeoman.dist %>'
}, {
expand: true,
cwd: '<%= yeoman.app %>/_lib/font-awesome',
src: 'fonts/*',
dest: '<%= yeoman.app %>'
}, {
expand: true,
cwd: '<%= yeoman.app %>/_lib/requirejs',
src: 'require.js',
dest: '<%= yeoman.dist %>/js/lib'
}, {
expand: true,
cwd: '<%= yeoman.app %>',
src: 'js/*.js',
dest: '<%= yeoman.dist %>'
}],
},
raw: {
expand: true,
cwd: '<%= yeoman.app %>',
src: 'css/*.css',
dest: '<%= yeoman.dist %>'
},
// Copy css into .tmp directory for processing
stageCss: {
files: [{
expand: true,
dot: true,
flatten: true,
cwd: '<%= yeoman.app %>',
src: ['css/*.css', '_lib/font-awesome/css/*.css'],
dest: '.tmp/css'
}]
}
},
rev: {
options: {
length: 4
},
dist: {
files: {
src: [
'<%= yeoman.dist %>/js/**/{!fb}*.js',
'<%= yeoman.dist %>/css/**/*.css',
'<%= yeoman.dist %>/image/**/*.{gif,jpg,jpeg,png,svg,webp}',
'<%= yeoman.dist %>/fonts/**/*.{eot*,svg,ttf,woff}'
]
}
}
},
concurrent: {
server: [
'sass:server',
'copy:stageCss',
'copy:dist',
'jekyll:server'
],
dist: [
'sass:dist',
'copy:dist'
]
},
bump: {
options: {
files: ['package.json', '<%= yeoman.app %>/app.json'],
updateConfigs: [],
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['-a'], // '-a' for all files
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: false,
pushTo: 'digitalocean',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d' // options to use with '$ git describe'
}
},
secret: grunt.file.readJSON('secret.json'),
sshconfig: {
"prod": grunt.file.readJSON('secret.json')
},
sshexec: {
flip: {
command: 'cp -R <%= secret.staging %>* <%= secret.prod %>',
options: {
config: 'prod'
}
}
},
sftp: {
raw: {
files: {
"./": "dist/**"
},
options: {
path: '<%= secret.raw %>',
host: '<%= secret.host %>',
username: '<%= secret.username %>',
password: '<%= secret.password %>',
srcBasePath: "dist/",
createDirectories: true
}
},
dist: {
files: {
"./": "dist/**"
},
options: {
path: '<%= secret.staging %>',
host: '<%= secret.host %>',
username: '<%= secret.username %>',
password: '<%= secret.password %>',
srcBasePath: "dist/",
createDirectories: true
}
}
}
});
// Load plugins
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Define Tasks
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'concurrent:server',
'autoprefixer:server',
'connect:livereload',
'open',
'watch'
]);
});
grunt.registerTask('report', [
'clean:server',
'sass:server',
'jshint:report',
'csscss:report',
'csslint:report'
]);
grunt.registerTask('build', [
'clean:dist',
// Jekyll cleans all non-git files from the target directory, so must run first
'jekyll:dist',
'concurrent:dist',
'sass',
'useminPrepare',
'concat',
'autoprefixer:dist',
'cssmin',
'uglify',
'imagemin',
'svgmin',
'rev',
'usemin',
'htmlmin'
]);
grunt.registerTask('raw', [
'clean:dist',
'jekyll:dist',
'concurrent:dist',
'copy:raw',
'sass',
'sftp:raw'
]);
grunt.registerTask('deploy', [
'bump',
'build',
'sshexec:preStaging',
'sftp:dist'
]);
grunt.registerTask('flip', [
'sshexec:flip'
]);
grunt.registerTask('default', [
'report',
'build'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment