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

303 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: {
2014-07-12 02:07:09 +02:00
stylus: 'assets/styl',
2013-11-18 01:08:13 +01:00
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 %>/',
2014-07-10 16:34:01 +02:00
config: './_config.yml'
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: {
2014-07-10 16:34:01 +02:00
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
2014-07-12 02:07:09 +02:00
// Stylus
stylus: {
compile: {
options: {
2014-07-12 21:22:47 +02:00
'include css': true,
compress: false
},
2013-11-18 01:08:13 +01:00
files: {
2014-07-12 02:07:09 +02:00
'<%= config.site %>/<%= config.assets.css %>/kremalicious3.min.css' : '<%= config.src %>/<%= config.assets.stylus %>/kremalicious3.styl',
'<%= config.site %>/<%= config.assets.css %>/poststyle-2300.min.css' : '<%= config.src %>/<%= config.assets.stylus %>/poststyle-2300.styl'
2014-07-12 21:22:47 +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
// 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'
},
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/jquery/dist/jquery.js',
2014-08-10 01:17:16 +02:00
'bower_components/jquery-infinite-scroll/jquery.infinitescroll.js',
'bower_components/masonry/dist/masonry.pkgd.js',
2013-11-29 21:36:09 +01:00
'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
},
2014-07-12 02:07:09 +02:00
stylus: {
files: ['<%= config.src %>/<%= config.assets.stylus %>/*.styl'],
2014-07-12 21:22:47 +02:00
tasks: ['stylus', '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
],
2014-07-12 02:07:09 +02:00
tasks: ['jekyll:development', 'stylus', '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', [
2014-07-12 02:07:09 +02:00
'stylus',
2013-11-18 01:08:13 +01:00
'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',
2014-07-12 02:07:09 +02:00
'stylus',
'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',
2014-07-12 02:07:09 +02:00
'stylus',
2013-11-18 01:08:13 +01:00
'cmq',
'cssmin',
'uglify',
2014-07-22 23:18:03 +02: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
]);
};