-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
230 lines (215 loc) · 8.4 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-autoprefixer');
// Include these tasks if using PNG spirete sheets
//grunt.loadNpmTasks('grunt-spritesmith');
//grunt.loadNpmTasks('grunt-contrib-imagemin');
//grunt.loadNpmTasks('grunt-scss-image-helpers');
// Include this task if using SVG files
//grunt.loadNpmTasks('grunt-svgmin');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// -------------------- CSS -------------------- //
concat: {
dist: {
src: ['page*/*.scss'],
dest: '_tmp/style.scss',
}
},
sass: {
dist: {
options: {
outputStyle: 'compressed',
sourceMap: true,
},
files: { '_tmp/style.css': '_tmp/style.scss', }
//files: { '_tmp/home.css': 'pagehome/home.scss' }
//files: [{
// expand: true,
// //cwd: '/',
// flatten: true,
// src: ['page*/*.scss'],
// dest: '_tmp/css/',
// ext: '.css'
//}]
}
},
autoprefixer: {
options: {
map: true,
browsers: ['last 2 versions', '> 5%']
},
default: { src: '_tmp/style.css', dest: 'live/style.css' },
//default: {
// files: [{
// expand: true,
// flatten: true,
// src: '_tmp/css/*.css',
// dest: 'live/'
// }]
//}
},
// -------------------- HTML -------------------- //
handlebars: {
default: {
options: {
namespace: 'HBS',
processName: function(filePath) { // Only keep filename (remove folder and extension)
var pieces = filePath.split('/');
return pieces[pieces.length - 1].split('.')[0];
}
},
files: {
'_tmp/hbs-templates.js': ['_hbs/*.hbs'],
}
}
},
shell: { // Split handlebar templates using "save: myFilename.hbs" lines
handlebarsSplit: { // Note: On mac, change 'csplit' to 'gcsplit' and run "brew install coreutils" for it to work
// Linux use:
// command: "rm -f _hbs/*.hbs & for file in page*/*.hbs; do csplit -z -f \"_hbs/hbsSplit_$(basename $file)\" $file '/saveAs:/' '{*}'; done;"
command: "rm -f _hbs/*.hbs & for file in page*/*.hbs; do gcsplit -z -f \"_hbs/hbsSplit_$(basename $file)\" $file '/saveAs:/' '{*}'; done;"
},
handlebarsRename: { // Note: space is the delimeter
command: "for file in _hbs/hbsSplit_*; do mv $file _hbs/$(head -1 $file | cut -d ' ' -f 2); done;"
},
handlebarsDeleteFirstLine: { // Note: On mac put a space after -i in: sed -i '.del'
// Linux use:
// command: "rm -f _hbs/hbsSplit_* & for file in _hbs/*.hbs; do sed -i'.del' '1d' $file; rm ${file}.del 2> /dev/null; done;"
command: "rm -f _hbs/hbsSplit_* & for file in _hbs/*.hbs; do sed -i '.del' '1d' $file; rm ${file}.del 2> /dev/null; done;"
},
handlebarsDeleteCompiled: { // Clears the pre-compile cache
command: "rm -f _hbs/*.php;"
},
// -------------------- VERSIONING -------------------- //
// The file "_tmp/version.txt" should only contain a number, which is automatically incremented.
// Use the number in this file to indicate in PHP when the files have changed
gruntCount: {
command: "GRUNTCOUNT=$(cat _tmp/version.txt); GRUNTCOUNT=`expr $GRUNTCOUNT + 1`; echo $GRUNTCOUNT > _tmp/version.txt;"
},
},
// -------------------- JS -------------------- //
uglify: {
options: {
mangle: false, // Does not impact build speed really
screwIE8: true, // In 2015, there was a bug with v0.9.1 of uglify (this option had to be false)
sourceMap: true,
nameCache: '_tmp/grunt-uglify-cache.json',
//sourceMapIncludeSources: true,
},
default:{ files:{
'live/script.js': ['_tmp/*.js','source/*.js','page*/*.js'],
}}
},
/*
// -------------------- SVG -------------------- //
svgmin: {
options: {
plugins: [ // For options, see: https://github.com/svg/svgo
{ removeViewBox: false },
{ removeUselessStrokeAndFill: true },
{ cleanupIDs: false }, // Don't change the IDs so they can be interacted with
{ mergePaths: false }, // Had a negative preformance impact (converted 196 paths to 70-ish paths and the preformance was bad)
]
},
dist: {
files: {
'image-min/svg/world.svg': 'image-raw/svg/world.svg',
}
}
},
// -------------------- PNG -------------------- //
// Spritesmith
// NOTE: Change the image URLs to "...file.svg?v=2" to invalidate the cache
sprite:{
layout: {
padding: 10, // 1px padding prevents artifacts when doing CSS transforms
cssSpritesheetName: 'layout_x1',
cssRetinaSpritesheetName: 'layout_x2',
retinaSrcFilter: 'image-raw/layout/*_x2.png',
src: 'image-raw/layout/*.png',
dest: '_tmp/layout_x1.png',
retinaDest: '_tmp/layout_x2.png',
destCss: 'scss/_sprite-layout.scss',
imgPath: '/rg/image-min/layout_x1.png', // URL given in SASS
retinaImgPath: '/rg/image-min/layout_x2.png', // (starting slash is important in this case)
cssRetinaGroupsName: 'layout-groups', // Scss variable for all x1 and x2 grops
},
avatars17: {
padding: 10, // 1px padding prevents artifacts when doing CSS transforms
cssSpritesheetName: 'avatars17_x1',
cssRetinaSpritesheetName: 'avatars17_x2',
retinaSrcFilter: 'image-raw/avatars_17/*_x2.png',
src: 'image-raw/avatars_17/*.png',
dest: '_tmp/avatars17_x1.png',
retinaDest: '_tmp/avatars17_x2.png',
destCss: 'scss/_sprite-avatars17.scss',
imgPath: '/rg/image-min/avatars17_x1.png', // URL given in SASS
retinaImgPath: '/rg/image-min/avatars17_x2.png', // (starting slash is important in this case)
cssRetinaGroupsName: 'avatars17-groups', // Scss variable for all x1 and x2 grops
},
},
// Optimize PNG: Lossless, use for fullcolor and gradients etc. (No palette mode)
// Also accepts JPG, SVG, GIF files. Warning: Can make massive files
imagemin: {
default: {
options: {
optimizationLevel: 2, // Go no higher than 5. Use 2 or 3
},
files: [{
expand: true, // Compress spritesheets
cwd: '_tmp/',
src: '*.png',
dest: 'image-min/'
},{
expand: true, // Compress individual files
cwd: 'image-raw/solo/',
src: '*.png',
dest: 'image-min/solo/'
}]
}
},
// Export width/height variables for the solo images
scss_images: {
dist: {
options: {
imageRoot: 'image-min/solo/',
prefix: 'solo',
antiCache: false,
relativePath: '/rg/image-min/solo/'
},
files: {
'scss/_solo.scss': ['image-min/solo/*_x1.png']
}
}
},
*/
watch: {
reload: { files: 'Gruntfile.js', tasks: 'build', options: {reload: true} },
css: { files: 'page*/*.scss', tasks: 'build:css' },
html: { files: 'page*/*.hbs', tasks: 'build:html' },
js: { files: ['page*/*.js', 'source/*.js'], tasks: 'build:js'},
},
});
grunt.registerTask('snutiNote', function() {
grunt.log.writeln(['\nSnuti note:\nRememmber to hug your co-worker <3']);
});
grunt.registerTask('prepHandlebars', [
'shell:handlebarsDeleteCompiled',
'shell:handlebarsSplit',
'shell:handlebarsRename',
'shell:handlebarsDeleteFirstLine'
]);
grunt.registerTask('default', ['build','watch']);
grunt.registerTask('build', ['build:css','build:html']);
grunt.registerTask('build:css', ['shell:gruntCount','concat','sass','autoprefixer']);
grunt.registerTask('build:html', ['prepHandlebars','handlebars','build:js']);
grunt.registerTask('build:js', ['shell:gruntCount','uglify']);
//grunt.registerTask('build:img', ['shell:gruntCount','sprite','imagemin','scss_images', 'snutiNote']);
//grunt.registerTask('build:svg', ['svgmin']);
}