-
Notifications
You must be signed in to change notification settings - Fork 9
/
Gruntfile.js
141 lines (138 loc) · 4.44 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
138
139
140
141
var path = require("path");
var jpegtran = require('imagemin-jpegtran');
var optipng = require('imagemin-optipng');
var svgo = require('imagemin-svgo');
module.exports = function(grunt) {
var now = grunt.template.today('fullDate')
console.log("Publication date: " + now );
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main : {
src: "book.json.ejs",
dest: 'book.json',
options: {
process: function(content, path) {
return grunt.template.process(content, {data: {now: now} });
},
now: now
}
},
svg: {
files: [
// Copy SVG files from root image folder to the right directory
{expand: true, src: ['images/*.svg'], dest: 'en/', filter: 'isFile'}
]
}
},
run:{
server: {
exec: 'gitbook serve'
},
build: {
exec: 'gitbook build ./ ./exports/open-guide'
},
pdf: {
exec: 'gitbook pdf ./ ./exports/open-guide.pdf'
}
},
imagemin: { // Task
dynamic: { // Another target
options: { // Target options
optimizationLevel: 3,
svgoPlugins: [{ removeViewBox: false }],
use: [
jpegtran(),
optipng(),
svgo()
]
},
files: [{
expand: true, // Enable dynamic expansion
cwd: './exports/open-guide/en/images/', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: './exports/open-guide/en/images/' // Destination path prefix
}]
}
},
image_resize: {
resize: {
options: {
width: 770,
height: 1000, // Because without that, it just generates a 1x1px file
//overwrite: true
},
src: './exports/open-guide/en/images/*',
dest: './exports/open-guide/en/images/'
}
},
less: {
development:{
options: {
yuicompress: true
},
files: {
"theme/assets/website/style.css": "theme/stylesheets/website.less",
"theme/assets/ebook/pdf.css": "theme/stylesheets/pdf.less"
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-image-resize');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-imagemagick');
grunt.loadNpmTasks('grunt-shell');
/*** TASKs ***/
// Generates the book.json file with all the settings
grunt.registerTask('update_book_json', ['copy:main']);
// Converts Less files into CSS
grunt.registerTask('css', [ 'less']);
// Copy SVG images over the right subfolders
grunt.registerTask('copy_svg', [ 'copy:svg']);
// Calls the web server
grunt.registerTask('serve', ['default']);
// DEFAULT: Calls the web server
grunt.registerTask('default', [ 'css',
'update_book_json',
'run:server'
]);
// Generate the books
grunt.registerTask('pdf', [
'css',
'update_book_json',
'run:pdf'
]);
// Builds for publishingo on a webserver
grunt.registerTask('web', [
'css',
'update_book_json',
'run:build',
'image_resize',
'imagemin'
]);
// Colorizes the images and puts them in the right folder
grunt.registerTask('colorize', function(){
var src = grunt.file.expand({'cwd':'images'}, '*.+(jpg|JPG|png|PNG|gif|GIF)');
var dest = "en/images/";
if ( !grunt.file.exists( dest ) ){
grunt.file.mkdir( dest );
}
for ( var i=0; i < src.length; i++ ) {
var el = src[i];
var img_src = 'images/' + el;
var img_dest = dest + el;
var cmd = 'sh scripts/color-image.sh "' + img_src + '" "' + img_dest + '"';
var taskName = el;
console.log( img_src );
grunt.config(['shell', taskName ], {
command: cmd
});
}
grunt.task.run('shell');
grunt.task.run('copy_svg');
});
};