-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
261 lines (236 loc) · 8.11 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'use strict';
var path = require('path');
// match one level down:
// e.g. 'bar/foo/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// e.g. 'bar/foo/**/*.js'
module.exports = function(grunt) {
'use strict';
// Project assets
// Loads project js files which will be concatenated and minified in one file
var projectJsfiles = grunt.file.readJSON('jsfiles.json').concatJsFiles;
// Name of the folder that contains project specific assets (scss, js, images, etc.)
// Rename this folder if needed
var projectAssetsFolder = "project";
// Check targets against which the grunt tasks are run - sitefinity, sitefinityBootstrap or project
// sitefinity - builds only Sitefinity assets
// sitefinityBootstrap - builds Sitefinity + Bootstrap assets
// project [default] - builds Sitefinity + Bootstrap + project assets
// var options,
// target = grunt.option("target");
// Options needed for webfont task.
// Starting code point for Sitefinity font icons.
var sfCodePoints = {
"file": 0xF001,
"no-image": 0xF002
}
var webFontOptions = {
destHtml: '',
engine: 'node',
font: 'sf-icon-font',
stylesheet: 'scss',
partialPrefix: true,
relativeFontPath: '../fonts/',
template: 'assets/src/sitefinity/sass/components/icons/feather-icons.css',
types: 'eot,woff,ttf,svg',
order: 'eot,woff,ttf,svg',
codepoints: sfCodePoints,
startCodepoint: 0x00b1,
normalize: true,
fontHeight: 4096,
ascent: 4096,
descent: 0,
autoHint: false
}
// if (target) {
// options = target.split(",");
// } else {
// options = ["project"];
// }
// Load all grunt tasks
require('load-grunt-tasks')(grunt);
// Show elapsed time at the end
require('time-grunt')(grunt);
// Init
grunt.initConfig({
timestamp: '<%= new Date().getTime() %>',
pkg: grunt.file.readJSON('package.json'),
src: {
path: 'assets/src',
sass: '**/*.{scss,sass}'
},
dist: {
path: 'assets/dist'
},
// Clean all generated files
clean: {
all: {
files: [{
src: [
'<%= dist.path %>/**/*.css',
'<%= dist.path %>/**/*.js',
'<%= dist.path %>/**/*.{png,jpg,gif,jpeg}',
'csslint_report'
]
}]
},
css: {
files: [{
src: [
'<%= dist.path %>/**/*.css',
]
}]
},
images: {
files: [{
src: [
'<%= dist.path %>/**/*.{png,jpg,gif,jpeg}'
]
}]
}
},
sass: {
options: {
outputStyle: 'nested',
includePaths: ['node_modules/foundation-sites/scss']
},
dist: {
files: [{
expand: true,
cwd: '<%= src.path %>/' + projectAssetsFolder + '/sass',
src: ['*.scss'],
dest: '<%= dist.path %>/css/',
ext: '.css'
}]
}
},
// use always with target e.g. `csslint:doc` or `csslint:dev`
// unfortunately there is no point to run csslint on compressed css so
// csslint runs once, when you use `grunt` and it lints on documentation's css
// csslint runs on every save when you use `grunt dev` and it lints the original file you are working on -> `style.css`
csslint: {
options: {
csslintrc: 'csslint.json',
quiet: true,
formatters: [{
id: 'csslint-xml',
dest: 'csslint_report/csslint.xml'
}]
},
dev: {
expand: true,
cwd: '<%= dist.path %>/css/',
src: ['*.css', '!*.min.css']
}
},
webfont: {
icons: {
src: ['assets/src/sitefinity/icons/*.svg', 'assets/src/project/icons/*.svg'],
dest: 'assets/dist/fonts/',
destCss: 'assets/src/sitefinity/sass/components/icons/',
options: webFontOptions
}
},
cssmin: {
minify: {
expand: true,
cwd: '<%= dist.path %>/css/',
src: ['*.css', '!*.min.css'],
dest: '<%= dist.path %>/css/',
ext: '.min.css',
extDot: 'last'
}
},
copy: {
dist: {
files: [
{ expand: true, src: ['node_modules/bootstrap-sass/assets/fonts/bootstrap/*'], dest: 'assets/dist/fonts/bootstrap/', flatten: true, filter: 'isFile' },
{ expand: true, cwd: 'assets/src/project/fonts', src: '**', dest: 'assets/dist/fonts/'}
]
}
},
// Concatenates & minifies js files
// Processes the files described in 'jsfiles.json' + bootstrap.js
uglify: {
options: {
report: 'gzip',
warnings: true,
mangle: true,
compress: false
},
dist: {
files: {
// Project assets
// Concatenates project files listed in jsfiles.json
'<%= dist.path %>/js/project.min.js': projectJsfiles
}
}
},
// Image Optimization
imagemin: {
dist: {
options: {
optimizationLevel: 4,
progressive: true
},
files: [
{expand: true, cwd: 'assets/src/sitefinity/images', src: ['**/*.{png,jpg,gif,jpeg,svg}', '!fonts/*', '!sprite/*.*'], dest: 'assets/dist/images'},
{expand: true, cwd: 'assets/src/' + projectAssetsFolder + '/images', src: ['**/*.{png,jpg,gif,jpeg,svg}', '!fonts/*', '!sprite/*.*'], dest: 'assets/dist/images'}
]
}
},
// Sprite generation
sprite: {
dist: {
src: ['assets/src/sitefinity/images/sprite/*.png', 'assets/src/project/images/sprite/*.png'],
dest: 'assets/src/sitefinity/images/sprite.png',
destCss: 'assets/src/sitefinity/sass/widgets/socialShare/_sf-sprite.scss',
imgPath: '../images/sprite.png',
cssTemplate: 'assets/src/sitefinity/sass/widgets/socialShare/sf-sprite.mustache'
}
},
watch: {
options: {
spawn: false
},
styles: {
files: ['<%= src.path %>/**/*.{scss,sass}'],
tasks: ['sass', 'csslint:dev', 'cssmin']
},
images: {
files: ['<%= src.path %>/**/*.{png,jpg,gif,jpeg}'],
tasks: ['clean:images', 'sprite', 'imagemin']
},
js: {
files: ['<%= src.path %>/**/*.js'],
tasks: ['uglify']
}
},
concurrent: {
dist: {
tasks: ['watch:styles', 'watch:js', 'watch:images'],
options: {
logConcurrentOutput: true
}
}
}
});
// Tasks
// Task to generate icon font
grunt.registerTask('iconfont', [
'webfont'
]);
// Default task
grunt.registerTask('default', ' ', function() {
grunt.task.run('clean:all');
grunt.task.run('newer:sprite');
grunt.task.run('webfont');
grunt.task.run('copy');
grunt.task.run('sass');
grunt.task.run('uglify');
grunt.task.run('csslint:dev');
grunt.task.run('cssmin');
grunt.task.run('newer:imagemin');
grunt.task.run('concurrent');
});
};