-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
132 lines (117 loc) · 2.75 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
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-svgmin');
grunt.loadNpmTasks('grunt-svgstore');
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-contrib-clean');
var SRC = 'src/',
SRC_SKETCH = `${SRC}sketch/`,
SRC_SVG = `${SRC}svg/`;
var DIST = 'dist/',
DOC_SRC = 'doc/template/',
DOC_DEST = 'doc/build/';
var distPaths = {
DIST_JS: `${DIST}js/`,
DIST_WEB_SVG: `${DIST}svg/`,
DIST_ANDROID_SVG: `${DIST}svg/android/`,
DIST_WEB_OPTIMIZED: `${DIST}optimized/`,
DIST_ANDROID_OPTIMIZED: `${DIST}optimized/android/`,
DIST_SPRITE: `${DIST}sprite/`,
};
var DIST_PATHS_TO_CLEAN = Object.keys(distPaths)
.map(k => distPaths[k] + '*');
var svgminOptions = {
plugins: [
{ removeDesc: true },
{ collapseGroups: true },
{ removeEmptyAttrs: true },
{ removeUselessStrokeAndFill: true },
{ removeViewbox: false },
{
removeAttrs: {
attrs: ['fill']
}
}
]
};
var svgminOptionsAndroid = {plugins: svgminOptions['plugins'].concat([{ convertPathData: { floatPrecision: 2, makeArcs: false } }])};
grunt.initConfig({
package: grunt.file.readJSON('package.json'),
//
// Cleans `dist/` dir
//
'clean': {
contents: DIST_PATHS_TO_CLEAN
},
//
// SVG optimization step
// (writes to "optimized" distribution)
//
'svgmin': {
web: {
options: svgminOptions,
files: [{
expand: true,
cwd: distPaths.DIST_WEB_SVG,
src: ['*.svg'],
dest: distPaths.DIST_WEB_OPTIMIZED
}]
},
android:{
options: svgminOptionsAndroid,
files: [{
expand: true,
cwd: distPaths.DIST_ANDROID_SVG,
src: ['*.svg'],
dest: distPaths.DIST_ANDROID_OPTIMIZED
}]
}
},
//
// SVG sprite
// builds distribution for chapstick
//
'svgstore': {
options: {
prefix: 'icon-'
},
default: {
files: [{
src: [`${distPaths.DIST_WEB_OPTIMIZED}*.svg`],
dest: `${distPaths.DIST_SPRITE}sprite.inc`
}]
}
},
//
// DOCS via preprocess
// writes an html file to DOC_DEST
//
'preprocess': {
options: {
context: {
'VERSION': '<%= package.version %>',
'STYLESHEET_SQ': 'https://meetup.github.io/sassquatch2/bundle/sassquatch.css',
'STYLESHEET_FONT': 'https://secure.meetupstatic.com/fonts/graphik.css'
},
srcDir: distPaths.DIST_SPRITE // resovle @include directive to built sprite
},
docs: {
src: `${DOC_SRC}index.html`,
dest: `${DOC_DEST}index.html`
}
},
//
// LIVE DOCS
// gh-pages task to move built doc html
// to root dir of gh-pages branch
//
'gh-pages': {
options: {
base: DOC_DEST
},
src: ['**']
}
});
var platform = grunt.option('platform') || 'web';
grunt.registerTask('minifySvg', ['svgmin:' + platform]);
};