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

339 lines
10 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',
2014-09-07 20:31:47 +02:00
cdnurl: 'https://d2jlreog722xe2.cloudfront.net',
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',
2014-09-07 20:31:47 +02:00
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-09-07 20:31:47 +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
2015-05-31 20:13:27 +02:00
// Post process css
postcss: {
options: {
processors: [
// autoprefixer
require('autoprefixer-core')({browsers: 'last 2 versions'}),
// combine media queries
require('css-mqpacker'),
// css minification
require('csswring')
]
},
dist: {
src: '<%= config.site %>/<%= config.assets.css %>/*.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': [
2015-05-29 01:14:12 +02:00
'node_modules/picturefill/dist/picturefill.js'
2013-11-23 21:53:52 +01:00
],
2015-04-17 23:04:01 +02:00
'<%= config.site %>/<%= config.assets.js %>/CustomElements.min.js': [
2015-05-31 21:56:40 +02:00
'node_modules/webcomponents.js/CustomElements.js'
2015-04-17 23:04:01 +02:00
],
'<%= config.site %>/<%= config.assets.js %>/kremalicious3.min.js': [
2015-05-29 01:14:12 +02:00
'node_modules/jquery/dist/jquery.js',
'node_modules/masonry-layout/dist/masonry.pkgd.js',
'node_modules/imagesloaded/imagesloaded.js',
2015-04-17 21:01:58 +02:00
'bower_components/simple-jekyll-search/dest/jekyll-search.js',
2015-04-17 23:04:01 +02:00
'bower_components/time-elements/time-elements.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'],
2015-05-31 20:13:27 +02:00
tasks: ['stylus', 'postcss']
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
],
2015-05-31 20:13:27 +02:00
tasks: ['jekyll:development', 'stylus', 'postcss', '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-09-07 20:31:47 +02:00
// insert CDN url by replacing text strings
replace: {
html: {
src: ['<%= config.build %>/**/*.html'],
overwrite: true,
replacements: [
{
from: '/assets/js/',
to: '<%= config.cdnurl %>/assets/js/'
},
2014-09-07 22:04:38 +02:00
{
from: '/assets/img/',
to: '<%= config.cdnurl %>/assets/img/'
},
2014-09-07 20:31:47 +02:00
{
from: '/media/',
to: '<%= config.cdnurl %>/media/'
},
{
from: 'https://kremalicious.com<%= config.cdnurl %>/media/',
to: 'https://kremalicious.com/media/'
2014-09-07 20:31:47 +02:00
}
]
},
2014-09-07 20:31:47 +02:00
css: {
src: ['<%= config.build %>/<%= config.assets.css %>/*.css'],
overwrite: true,
replacements: [
{
from: '../',
to: '<%= config.cdnurl %>/assets/'
}
]
}
},
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',
2015-05-31 20:13:27 +02:00
'postcss',
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',
2015-05-31 20:13:27 +02:00
'postcss',
'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',
2015-05-31 20:13:27 +02:00
'postcss',
'uglify',
2014-07-22 23:18:03 +02:00
'imagemin:assets',
'imagemin:touchicons',
'rsync:copy_build',
'rev',
'usemin',
2014-09-07 20:31:47 +02:00
'replace'
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
]);
2015-05-29 01:14:12 +02:00
};