-
Notifications
You must be signed in to change notification settings - Fork 1
/
gruntfile.js
180 lines (154 loc) · 6.29 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
// -----------------------------------------------------------------------
// For a quick introduction on GruntJS.
// http://www.smashingmagazine.com/2013/10/29/get-up-running-grunt/
// -----------------------------------------------------------------------
module.exports = function(grunt) {
// --------------------------------------------------------
// Loading all NPM tasks (plugins) into Grunt. Without the
// matchdep plugin this would have to be done manually.
// --------------------------------------------------------
require('load-grunt-tasks')(grunt);
// --------------------------------------------------------
// Project configuration.
// --------------------------------------------------------
grunt.initConfig({
// --------------------------------------------------------
// Variables.
// --------------------------------------------------------
pkg: grunt.file.readJSON('package.json'),
sourceFolder: 'source/',
staticFolder: 'static/',
// --------------------------------------------------------
// SASS compilation.
// https://github.com/gruntjs/grunt-contrib-sass
// --------------------------------------------------------
sass: {
options: {
require: "susy",
compass: true
},
build: {
files: {
'<%= staticFolder %>css/style.css': '<%= sourceFolder %>scss/import.scss'
}
}
},
// --------------------------------------------------------
// CSS minification.
// https://github.com/gruntjs/grunt-contrib-cssmin
// --------------------------------------------------------
cssmin: {
options: {
banner: '/* <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today(\'yyyy-mm-dd HH:MM:ss\') %> */'
},
build: {
files: {
'<%= staticFolder %>css/style.min.css': '<%= staticFolder %>css/style.css'
}
}
},
// --------------------------------------------------------
// CSS auto prefix browser vendors.
// https://github.com/nDmitry/grunt-autoprefixer
// --------------------------------------------------------
autoprefixer: {
options: {
map: true
},
multiple_files: {
expand: true,
flatten: true,
src: '<%= staticFolder %>css/*.css',
dest: '<%= staticFolder %>css'
}
},
// --------------------------------------------------------
// Validate JavaScript.
// https://github.com/sindresorhus/grunt-eslint
// --------------------------------------------------------
eslint: {
target: [
'<%= sourceFolder %>js/**/*.js'
],
options: {
config: 'eslint.json',
quiet: false
}
},
// --------------------------------------------------------
// Include dependencies and minify requirejs modules.
// https://github.com/asciidisco/grunt-requirejs
// --------------------------------------------------------
requirejs: {
compile: {
options: {
almond: true,
baseUrl: '',
name: '<%= sourceFolder %>js/project/main',
optimize: 'uglify',
out: '<%= staticFolder %>js/require.min.js',
mainConfigFile: '<%= sourceFolder %>js/project/config/require.js'
}
}
},
// --------------------------------------------------------
// Complexity - Calculate the cyclomatic complexity of
// JavaScript code.
// https://github.com/vigetlabs/grunt-complexity.
// --------------------------------------------------------
complexity: {
generic: {
src: [
'<%= sourceFolder %>js/**/*.js'
],
exclude: [
'<%= sourceFolder %>js/project/config/require.js',
'<%= sourceFolder %>js/boilerplate/**/*.js'
],
options: {
breakOnErrors: true,
errorsOnly: false,
cyclomatic: [5],
halstead: [15],
maintainability: 100,
hideComplexFunctions: false,
broadcast: false
}
}
},
// --------------------------------------------------------
// Watch tasks.
// https://github.com/gruntjs/grunt-contrib-watch
// --------------------------------------------------------
watch: {
sass: {
files: ['**/*.{scss, sass}'],
tasks: ['compile-css']
},
js: {
files: ['<%= eslint.target %>'],
tasks: ['analyse-js']
}
}
});
// --------------------------------------------------------
// Minify all CSS and JavaScript.
// --------------------------------------------------------
grunt.registerTask('compile-all', ['analyse-js', 'compile-requirejs', 'compile-css']);
// --------------------------------------------------------
// Complie CSS.
// --------------------------------------------------------
grunt.registerTask('compile-css', ['sass', 'autoprefixer', 'cssmin']);
// --------------------------------------------------------
// Minify RequireJS.
// --------------------------------------------------------
grunt.registerTask('compile-requirejs', ['requirejs']);
// --------------------------------------------------------
// Analyse JS.
// --------------------------------------------------------
grunt.registerTask('analyse-js', ['eslint', 'complexity']);
// --------------------------------------------------------
// The default Grunt task, this task is mandatory.
// --------------------------------------------------------
grunt.registerTask('default', ['compile-all']);
};