1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-22 18:00:06 +01:00
blog/Gruntfile.js

304 lines
8.9 KiB
JavaScript
Raw Normal View History

2013-11-18 01:08:13 +01:00
module.exports = function(grunt){
'use strict';
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// config
var gruntConfig = {
src: '_src',
2013-12-11 21:14:17 +01:00
site: '_site',
2013-12-11 23:47:20 +01:00
build: '_build',
2013-11-18 01:08:13 +01:00
assets: {
less: 'assets/less',
css: 'assets/css',
js: 'assets/js',
img: 'assets/img',
fonts: 'assets/fonts'
2013-11-18 01:08:13 +01:00
}
};
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// banner
grunt.log.writeln("");
grunt.log.writeln(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
2013-11-18 01:08:13 +01:00
grunt.log.writeln("");
2013-11-23 21:53:52 +01:00
grunt.log.writeln(" (o) Just what do you think you're doing, Matthias? ");
2013-11-18 01:08:13 +01:00
grunt.log.writeln("");
grunt.log.writeln(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
2013-11-18 01:08:13 +01:00
grunt.log.writeln("");
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// Grunt config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: gruntConfig,
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// clean everything
clean: {
2013-12-11 23:47:20 +01:00
site: [
2014-07-02 13:33:27 +02:00
'<%= config.site %>/*',
'<%= config.site %>/.htaccess',
2013-11-24 01:05:20 +01:00
'!<%= config.site %>/media'
2013-12-11 23:47:20 +01:00
],
build: [
2014-07-02 13:33:27 +02:00
'<%= config.build %>/*',
2013-12-11 23:47:20 +01:00
'<%= config.build %>/.htaccess'
2013-11-24 01:05:20 +01:00
]
2013-11-18 01:08:13 +01:00
},
// Jekyll
jekyll: {
2013-11-29 00:01:40 +01:00
options: {
src : '<%= config.src %>/',
config: './_config.yml',
lsi: true
2013-11-29 00:01:40 +01:00
},
2013-11-24 17:31:03 +01:00
production: {
2013-11-29 00:01:40 +01:00
options: {
//lsi: true
2013-11-29 00:01:40 +01:00
}
2013-11-24 19:15:34 +01:00
},
2013-11-29 00:01:40 +01:00
development: {
options: {
drafts: true,
future: true,
2014-07-02 13:33:27 +02:00
//limit_posts: 5
2013-11-29 00:01:40 +01:00
}
2013-11-23 15:37:55 +01:00
}
2013-11-18 01:08:13 +01:00
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// less
less: {
production: {
files: {
2013-11-19 23:21:19 +01:00
'<%= config.site %>/<%= config.assets.css %>/kremalicious3.min.css' : '<%= config.src %>/<%= config.assets.less %>/kremalicious3.less',
'<%= config.site %>/<%= config.assets.css %>/poststyle-2300.min.css' : '<%= config.src %>/<%= config.assets.less %>/poststyle-2300.less'
2013-11-18 01:08:13 +01:00
},
},
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// combine css media queries
cmq: {
production: {
files: {
'<%= config.site %>/<%= config.assets.css %>/': ['<%= config.site %>/<%= config.assets.css %>/kremalicious3.min.css']
2013-11-18 01:08:13 +01:00
}
}
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// minify css
cssmin: {
production: {
files: {
2013-11-19 23:21:19 +01:00
'<%= config.site %>/<%= config.assets.css %>/kremalicious3.min.css': ['<%= config.site %>/<%= config.assets.css %>/*.css'],
'<%= config.site %>/<%= config.assets.css %>/poststyle-2300.min.css': ['<%= config.site %>/<%= config.assets.css %>/poststyle-2300.min.css']
2013-11-18 01:08:13 +01:00
}
}
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// Concatenate and minify js
uglify: {
options: {
report: 'min'
},
jquery: {
files: {
2014-04-06 15:25:37 +02:00
'<%= config.site %>/<%= config.assets.js %>/jquery.min.js': 'bower_components/jquery/dist/jquery.js'
}
},
2013-11-18 01:08:13 +01:00
production: {
files: {
'<%= config.site %>/<%= config.assets.js %>/picturefill.min.js': [
2014-07-02 13:33:27 +02:00
'bower_components/picturefill/dist/picturefill.js'
2013-11-23 21:53:52 +01:00
],
'<%= config.site %>/<%= config.assets.js %>/kremalicious3.min.js': [
'bower_components/infinitescroll/index.js',
2013-11-29 21:36:09 +01:00
'bower_components/masonry/index.js',
'bower_components/imagesloaded/imagesloaded.js',
2013-11-30 17:13:19 +01:00
'bower_components/simpleJekyllSearch/index.js',
'bower_components/jquery.adaptive-background/index.js',
2013-11-22 00:06:00 +01:00
'<%= config.src %>/<%= config.assets.js %>/app.js'
2013-11-18 01:08:13 +01:00
]
}
}
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// image optimization
imagemin: {
assets: {
2013-11-24 19:15:34 +01:00
files: [{
expand: true,
cwd: '<%= config.site %>/<%= config.assets.img %>/',
src: ['**/*.{png,jpg,jpeg,gif}'],
dest: '<%= config.site %>/<%= config.assets.img %>/'
}]
2013-11-18 01:08:13 +01:00
},
2013-11-22 00:35:07 +01:00
media: {
2013-11-24 19:15:34 +01:00
files: [{
expand: true,
cwd: '<%= config.site %>/media/',
src: ['**/*.{png,gif}'],
dest: '<%= config.site %>/media/'
}]
2013-11-22 00:35:07 +01:00
},
2013-11-18 01:08:13 +01:00
touchicons: {
2013-11-24 19:15:34 +01:00
files: [{
expand: true,
cwd: '<%= config.site %>/',
src: ['*.png'],
dest: '<%= config.site %>/'
}]
2013-11-24 01:05:20 +01:00
}
2013-11-18 01:08:13 +01:00
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// dev server
connect: {
server: {
options: {
port: 1337,
2013-11-21 23:40:53 +01:00
hostname: '*',
2013-11-30 17:13:19 +01:00
base: '<%= config.site %>'
2013-11-18 01:08:13 +01:00
}
}
},
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// watch
watch: {
options: {
livereload: true
},
less: {
files: ['<%= config.src %>/<%= config.assets.less %>/*.less'],
2013-11-30 04:10:58 +01:00
tasks: ['less','cmq','cssmin']
2013-11-18 01:08:13 +01:00
},
js: {
files: ['<%= config.src %>/<%= config.assets.js %>/*.js'],
tasks: ['uglify']
},
jekyll: {
files: [
2014-07-02 13:33:27 +02:00
'<%= config.src %>/**/*.html',
'<%= config.src %>/*.xml',
'<%= config.src %>/*.json',
'<%= config.src %>/.htaccess',
'<%= config.src %>/_includes/**',
'<%= config.src %>/_layouts/**',
2013-11-29 00:01:40 +01:00
'<%= config.src %>/_posts/**',
'<%= config.src %>/_drafts/**'
2013-11-18 01:08:13 +01:00
],
2013-11-30 04:10:58 +01:00
tasks: ['jekyll:development', 'less', 'cmq', 'cssmin', 'uglify']
2013-11-18 01:08:13 +01:00
},
},
2014-07-02 13:33:27 +02:00
// assets versioning
rev: {
files: {
src: [
'<%= config.build %>/assets/{css,js,img,fonts}/*.*'
]
}
},
2014-07-02 13:33:27 +02:00
// updating assets paths in html/css
usemin: {
html: ['<%= config.build %>/**/*.html'],
css: ['<%= config.build %>/**/*.css'],
options: {
2013-12-15 14:15:23 +01:00
dirs: '<%= config.build %>',
basedir: '<%= config.build %>',
2013-12-15 14:30:41 +01:00
assetsDirs: ['<%= config.build %>', '<%= config.build %>/assets/{css,js,img,fonts}']
}
},
2014-07-02 13:33:27 +02:00
// rsync stuff around
2013-11-18 01:08:13 +01:00
rsync: {
options: {
recursive: true
2013-11-18 01:08:13 +01:00
},
// copy media folder
copy_media: {
2013-11-18 01:08:13 +01:00
options: {
src: '<%= config.src %>/_media/',
2013-11-24 17:31:03 +01:00
dest: '<%= config.site %>/media',
exclude: ['**/gen'],
2014-01-02 18:13:03 +01:00
syncDestIgnoreExcl: true,
args: ['--update']
}
},
2013-12-11 23:47:20 +01:00
// copy build
copy_build: {
options: {
src: '<%= config.site %>/',
dest: '<%= config.build %>',
syncDest: true
}
},
// deployment
deploy: {
options: {
syncDest: true,
2013-12-11 23:47:20 +01:00
src: '<%= config.build %>/',
2013-11-24 17:31:03 +01:00
dest: 'domains/kremalicious.com/html',
host: 'kremalicious',
ssh: true,
2014-01-02 18:13:03 +01:00
compareMode: 'checksum',
2013-11-29 00:01:40 +01:00
args: ['--verbose']
2013-11-18 01:08:13 +01:00
}
}
}
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
});
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// Load NPM Tasks, smart code stolen from @bluemaex <https://github.com/bluemaex>
require('fs').readdirSync('node_modules').filter(function (file) {
return file && file.indexOf('grunt-') > -1;
}).forEach(function (file) {
grunt.loadNpmTasks(file);
});
2014-07-02 13:33:27 +02:00
2013-12-11 23:47:20 +01:00
// Default Task, assets only
2013-11-18 01:08:13 +01:00
grunt.registerTask('default', [
'less',
'cmq',
'cssmin',
2013-11-22 00:06:00 +01:00
'uglify',
2013-11-18 01:08:13 +01:00
'connect',
'watch'
]);
2014-07-02 13:33:27 +02:00
2013-12-10 21:08:28 +01:00
// Full Dev server
2013-11-23 18:48:45 +01:00
grunt.registerTask('server', [
2013-12-11 23:47:20 +01:00
'clean:site',
2013-11-29 00:01:40 +01:00
'jekyll:development',
'rsync:copy_media',
'less',
'cmq',
'cssmin',
'uglify',
'connect',
'watch'
]);
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// Production build
grunt.registerTask('build', [
'clean',
2013-11-24 19:15:34 +01:00
'jekyll:production',
'rsync:copy_media',
2013-11-18 01:08:13 +01:00
'less',
'cmq',
'cssmin',
'uglify',
2013-12-11 23:47:20 +01:00
'imagemin:assets',
'imagemin:touchicons',
'rsync:copy_build',
'rev',
'usemin'
2013-12-11 23:47:20 +01:00
]);
2014-07-02 13:33:27 +02:00
2013-12-11 23:47:20 +01:00
// Optimze media
grunt.registerTask('mediamin', [
'imagemin:media'
2013-11-18 01:08:13 +01:00
]);
2014-07-02 13:33:27 +02:00
2013-11-18 01:08:13 +01:00
// Deploy
grunt.registerTask('deploy', [
'rsync:deploy'
2013-11-18 01:08:13 +01:00
]);
};