forked from SC5/grunt-boreless-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
181 lines (174 loc) · 4.95 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
/*global module:false*/
module.exports = function(grunt) {
// Bootstrap the extra tasks needed by Grunt
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
// Small-scale utility for processing templates
grunt.registerMultiTask('process', 'Process templates.', function() {
var data = this.data;
var context = data.context;
var src = grunt.template.process(data.src);
var dest = grunt.template.process(data.dest);
// Read file
var input = grunt.file.read(src);
// Process it
var output = grunt.template.process(input, { data: context });
// And write to a file
grunt.file.write(dest, output);
// Fail task if errors were logged.
if (this.errorCount) { return false; }
// Otherwise, print a success message.
grunt.log.writeln('File "' + dest + '" processed.');
});
// The real grunt config
var config = {
pkg: grunt.file.readJSON('package.json'),
defaults: {
source: {
/* Note: You also need to change RequireJS paths below */
dir: 'client'
},
debug: {
dir: 'staging'
},
release: {
dir: 'dist'
},
requirejs: {
/* Note: We build directly from the source directory to avoid copying of libs */
baseUrl: 'client/app',
mainConfigFile: 'client/app/main.js',
dir: 'temp/app',
optimize: 'none',
keepBuildDir: false,
paths: {
},
modules: [{ name: 'main' }]
}
},
/* Code quality related tasks */
jshint : {
files : {
src: '<%= defaults.source.dir %>/app/**/*.js'
},
options : {
curly : true, eqeqeq : true, immed : true, latedef : true,
newcap : true,noarg : true, sub : true, undef : true,
boss : true, eqnull : true, browser : true, devel : true,
globals : {
require : true,
define : true
}
}
},
qunit : {
files : 'tests/*.html'
},
/* Build & Optimization steps */
process: {
debug: {
src: '<%= defaults.source.dir %>/index.html',
dest: '<%= defaults.debug.dir %>/index.html',
context: {
stylesheetFile: 'css/styles.less',
stylesheetLanguage: 'stylesheet/less',
scriptFile: 'app/main.js',
scriptLoader: 'components/requirejs/require.js',
// This is an extra mechanism e.g. for injecting weinre, cordova & such
// things that we want to explicitly get to header
scripts: [ 'components/less.js/dist/less-1.3.3.js' ]
}
},
release: {
src: '<%= defaults.source.dir %>/index.html',
dest: 'temp/index.html',
context: {
stylesheetFile: 'css/styles-<%= pkg.version %>.css',
stylesheetLanguage: 'stylesheet',
scriptFile: 'app/main-<%= pkg.version %>.js',
scriptLoader: 'components/requirejs/require-<%= pkg.version %>.js',
scripts: []
}
}
},
requirejs : {
release : {
options: '<%= defaults.requirejs %>'
}
},
less : {
// Fill in manually afterwards to support our config style
debug : {
src: '<%= defaults.source.dir %>/css/styles.less',
dest: '<%= defaults.debug.dir %>/css/styles.css'
},
release : {
options : {
yuicompress : true
},
src: '<%= defaults.source.dir %>/css/styles.less',
dest: 'temp/css/styles-<%= pkg.version %>.css'
}
},
// Build JS into one monolith by JamJS/RequireJS
uglify : {
release : {
files: {
'<%= defaults.release.dir %>/app/main-<%= pkg.version %>.js': 'temp/app/main.js',
'<%= defaults.release.dir %>/components/requirejs/require-<%= pkg.version %>.js': '<%= defaults.source.dir %>/components/requirejs/require.js'
}
}
},
/* Helper tasks */
copy : {
release : {
files : [
/* Copy to temp directory first */
{
src: '*.html',
expand: true,
cwd: 'temp',
dest: '<%= defaults.release.dir %>'
},
/* Then the real thing */
{
src: [ '**/*.css' ],
expand: true,
cwd: 'temp',
dest: '<%= defaults.release.dir %>'
}
]
}
},
clean: {
all: [ 'temp', '<%= defaults.debug.dir %>', '<%= defaults.release.dir %>' ]
},
watch : {
client : {
files : [
'<%= defaults.source.dir %>/app/**/*.js',
'<%= defaults.source.dir %>/css/**/*.less',
'<%= defaults.source.dir %>/*.html'
],
tasks : 'debug'
},
tests : {
files : [ 'tests/*.html' ],
tasks : 'test'
}
}
};
// Project configuration.
grunt.initConfig(config);
// Define the 'external API' through task aliases; Override the defaults by platform specifics
grunt.registerTask('release', ['clean', 'process:release', 'less:release', 'requirejs:release', 'copy:release', 'uglify', 'test']);
grunt.registerTask('debug', ['clean', 'process:debug', 'less:debug', 'test', 'watch']);
grunt.registerTask('test', ['jshint'/*, 'qunit'*/]);
grunt.registerTask('default', ['release']);
};