-
Notifications
You must be signed in to change notification settings - Fork 65
/
Gruntfile.js
executable file
·246 lines (199 loc) · 7.12 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
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt, {
pattern: ['grunt-*'],
scope: 'devDependencies'
});
grunt.initConfig({
// A reference to data defined inside of this project's package.json
pkg: grunt.file.readJSON('package.json'),
/* Nearly every task defined below follows the convention:
*
* taskname: {
*
* // Default options that will be applied to every target.
* options: { }
*
* // Every task has to have at least one target. If the task is
* // run without specifying the target the every target will run.
*
* target: {
* // Special actions that should be run depending on the
* // environment.
* }
*
* For more information: http://gruntjs.com/configuring-tasks
*/
// Remove artificats from a previous build.
clean: {
prod: ['_SpecRunner.html'],
dev: ['_SpecRunner.html', 'index.html']
},
// Build index.html from index.hbs
'compile-handlebars': {
prod: {
template: 'build/index.hbs',
templateData: {
main: 'js/main',
src: 'js/<%= pkg.name %>.min.js'
},
output: 'dist/index.html'
},
dev: {
template: 'build/index.hbs',
templateData: {
main: 'js/init',
src: 'js/vendor/require.js',
// Add scripts to .grunt.config.json
scripts: []
},
output: 'index.html'
}
},
handlebars: {
options: {
namespace: 'Handlebars.templates',
processName: function(filePath) {
var path = filePath.split('/');
var name = path[path.length - 1];
return name.slice(0, name.length - 4);
},
extension: 'hbs'
},
guide: {
files: {
'style_guide/build/js/sg-templates.js': 'style_guide/templates/*.hbs'
}
}
},
// Copy over any build artificats that need to belong in the dist
// folder that are not managed by RequireJS or SASS.
copy: {
prod: {
files: [{
expand: true,
src: ['images/**'],
dest: 'dist/'
},{
expand: true,
src: ['icons/**'],
dest: 'dist/'
},
{
src: 'js/vendor/modernizr.js',
dest: 'dist/js/vendor/modernizr.js'
},
{
src: 'js/vendor/ZeroClipboard.swf',
dest: 'dist/js/ZeroClipboard.swf'
},
{
expand: true,
src: ['fonts/**'],
dest: 'dist/'
},]
}
},
// Concat and compile the SCSS files and output result to a location
// on the filesystem that is reachable (different for prod/dev).
sass: {
options: {
style: 'expanded'
},
prod: {
files: [{
expand: true,
cwd: 'css',
src: ['**/style.scss'],
dest: 'dist/css/',
ext: '.min.css'
}]
},
dev: {
files: [{
expand: true,
cwd: 'css',
src: ['**/style.scss'],
dest: 'css/',
ext: '.css'
}]
}
},
autoprefixer: {
prod: {
src: 'css/style.css',
dest: 'dist/css/style.css'
},
dev: {
src: 'css/style.css',
dest: 'css/style.min.css'
}
},
cssmin: {
target: {
files: {
'dist/css/style.min.css': ['dist/css/style.css']
}
}
},
// Concat and uglify the code the JS code and output the result to the
// dist folder.
requirejs: {
options: {
mainConfigFile: 'js/init.js',
baseUrl: 'js',
name: 'main',
out: 'dist/js/<%= pkg.name %>.min.js',
include: 'requireLib'
},
prod: {}
},
// Run these tasks concurrently.
concurrent: {
options: {
logConcurrentOutput: true
},
prod: {
tasks: ['build:styles', 'requirejs:prod']
},
dev: {
tasks: ['watch:rebuild']
}
},
watch: {
// When the files change compile the sass and reload the browser.
rebuild: {
files: ['templates/**/*.hbs', 'js/**/*.js', 'css/**/*.scss'],
tasks: ['sass:dev', 'autoprefixer:dev'],
options: {
}
},
guide: {
files: ['css/**/*.scss', 'style_guide/**/*.hbs', 'style_guide/**/*.css'],
tasks: ['sass:dev', 'handlebars:guide']
}
},
defaultTask: function() {
var text = "\nThe default task has not been configured.\n\n" +
"You can override the default task as well any other attribute\n" +
"in Grunt.config.init by creating '.grunt.config.json' in the\n" +
"root of this project.\n\n" +
"For example, if you want to override this task (defaultTask)\n" +
"with 'watch:rebuild' add the following to .grunt.config.json:\n\n" +
"{ 'defaultTask': ['watch:rebuild'] }\n\n" +
"Note: .grunt.config.json has been added to .gitignore.";
grunt.log.writeln(grunt.util.normalizelf(text));
grunt.task.run('build:dev');
}
});
// If local config exists, use it to override values defined above
if(grunt.file.exists('.grunt.config.json')) {
grunt.config.merge(grunt.file.readJSON('.grunt.config.json'));
}
// Tasks run on the build server for integration and production.
grunt.registerTask('build', ['clean:prod', 'compile-handlebars:prod', 'copy:prod', 'concurrent:prod']);
grunt.registerTask('build:styles', ['sass:prod', 'autoprefixer:prod', 'cssmin']);
// Tasks to run in local development environment.
grunt.registerTask('build:dev', ['clean:dev', 'compile-handlebars:dev', 'sass:dev', 'autoprefixer:dev']);
grunt.registerTask('guide', ['sass:dev', 'handlebars:guide', 'connect']);
grunt.registerTask('default', 'The default task', grunt.config.get('defaultTask'));
};