-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGruntfile.js
137 lines (129 loc) · 4.09 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var path = require("path");
var jpegtran = require('imagemin-jpegtran');
var optipng = require('imagemin-optipng');
var svgo = require('imagemin-svgo');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
stylus: {
compile: {
files: {
'public/css/main.css': 'public/css/main.styl',
}
}
},
jekyll: { // Task
options: { // Universal options
src : './'
},
dist: { // Target
options: { // Target options
dest: '_site',
config: '_config.yml'
}
},
serve: { // Another target
options: {
serve: true,
dest: '_site',
drafts: true,
future: true
}
}
},
buildcontrol: {
options: {
dir: '_site',
commit: true,
push: true,
message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
},
pages: {
options: {
remote: 'https://github.com/libreobjet/libreobjet.github.io.git',
branch: 'master'
}
}
},
imagemin: { // Task
dynamic: { // Another target
options: { // Target options
optimizationLevel: 3,
svgoPlugins: [{ removeViewBox: false }],
use: [
jpegtran(),
optipng(),
svgo()
]
},
files: [{
expand: true, // Enable dynamic expansion
cwd: '_site/objects/', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: '_site/objects/' // Destination path prefix
}]
}
},
image_resize: {
resize: {
options: {
width: 770,
height: 1000, // Because without that, it just generates a 1x1px file
//overwrite: true
},
files: [{
expand: true,
cwd: '_site/objects/',
src: ['**/*.{png,jpg,gif}'],
dest: '_site/objects/'
}]
}
},
htmlmin: { // Task
dist: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: '_site/',
src: ['**/*.{html,htm}'],
dest: '_site/'
}]
}
}
});
grunt.dynamicCompress = function (directory) {
var target = grunt.file.expand({ filter: "isDirectory" }, directory + '/*');
for (var i in target) {
var subfolder_name = target[i].substr( target[i].lastIndexOf("/") + 1 );
grunt.config.set('compress.' + subfolder_name, {
expand: true,
cwd: target[i],
src: ['**/*'],
options: {
mode: 'zip',
archive: '_site/objects/' + subfolder_name + '/' + subfolder_name + '.zip'
}
});
}
};
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-jekyll');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-build-control');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-image-resize');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.registerTask('zip-objects', 'Zip all the objects folders', function(){
grunt.dynamicCompress('_objects');
grunt.task.run('compress');
});
//grunt.registerTask('image_mignifier', ['image_resize', 'imagemin']);
grunt.registerTask('image_mignifier', ['image_resize']);
grunt.registerTask('default', ['stylus', 'jekyll:serve'] );
grunt.registerTask('build', ['stylus', 'jekyll:dist', 'htmlmin', 'image_mignifier', 'zip-objects'] );
grunt.registerTask('deploy', ['build', 'buildcontrol']);
};