@@ -30,6 +30,29 @@ module.exports = function (grunt) {
30
30
' */\n'
31
31
} ,
32
32
33
+ /**
34
+ * The directories to delete when `grunt clean` is executed.
35
+ */
36
+ clean : [
37
+ '<%= dist_dir %>'
38
+ ] ,
39
+
40
+ /* Copy all example into dist/examples */
41
+ copy : {
42
+ examples : {
43
+ src : 'examples/*' ,
44
+ dest : 'dist/'
45
+ } ,
46
+ nav : {
47
+ src : 'navbar.html' ,
48
+ dest : 'dist/'
49
+ } ,
50
+ example : {
51
+ src : 'examples.html' ,
52
+ dest : 'dist/'
53
+ }
54
+ } ,
55
+
33
56
concat : {
34
57
compile_js : {
35
58
options : {
@@ -39,6 +62,34 @@ module.exports = function (grunt) {
39
62
'app/**/*.js'
40
63
] ,
41
64
dest : '<%= dist_dir %>/<%= pkg.name %>.js'
65
+ } ,
66
+ compile_all_js : {
67
+ src : [
68
+ '<%= dist_dir %>/<%= pkg.name %>.min.js' ,
69
+ 'bower_components/momentjs/min/moment-with-locales.min.js' ,
70
+ 'bower_components/humanize-duration/humanize-duration.js'
71
+ ] ,
72
+ dest : '<%= dist_dir %>/assets/js/<%= pkg.name %>-all.min.js'
73
+ } ,
74
+ compile_bower_js : {
75
+ src : [
76
+ 'bower_components/angular/angular.min.js' ,
77
+ 'bower_components/jquery/jquery.min.js' ,
78
+ 'bower_components/bootstrap/docs/assets/js/bootstrap.min.js' ,
79
+ 'docs/docs.js' ,
80
+ 'docs/prettify.js' ,
81
+ 'docs/application.js'
82
+ ] ,
83
+ dest : '<%= dist_dir %>/assets/js/<%= pkg.name %>-bower.js'
84
+ } ,
85
+ compile_bower_css : {
86
+ src : [
87
+ 'bower_components/bootstrap/docs/assets/css/bootstrap.css' ,
88
+ 'bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css' ,
89
+ 'docs/css/docs.css' ,
90
+ 'docs/css/prettify.css'
91
+ ] ,
92
+ dest : '<%= dist_dir %>/assets/css/<%= pkg.name %>-bower.css'
42
93
}
43
94
} ,
44
95
@@ -70,6 +121,59 @@ module.exports = function (grunt) {
70
121
}
71
122
} ,
72
123
124
+ /**
125
+ * The `index` task compiles the `index.html` file as a Grunt template. CSS
126
+ * and JS files co-exist here but they get split apart later.
127
+ */
128
+ index : {
129
+ /**
130
+ * During development, we don't want to have wait for compilation,
131
+ * concatenation, minification, etc. So to avoid these steps, we simply
132
+ * add all script files directly to the `<head>` of `index.html`. The
133
+ * `src` property contains the list of included files.
134
+ */
135
+ build : {
136
+ dir : '' ,
137
+ src : [
138
+ 'bower_components/angular/angular.min.js' ,
139
+ 'app/**/*.js' ,
140
+ 'bower_components/momentjs/min/moment-with-locales.min.js' ,
141
+ 'bower_components/humanize-duration/humanize-duration.js' ,
142
+ 'docs/docs.js' ,
143
+ 'bower_components/jquery/jquery.min.js' ,
144
+ 'bower_components/bootstrap/docs/assets/js/bootstrap.min.js' ,
145
+ 'docs/prettify.js' ,
146
+ 'docs/application.js' ,
147
+ 'bower_components/bootstrap/docs/assets/css/bootstrap.css' ,
148
+ 'bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css' ,
149
+ 'docs/css/docs.css' ,
150
+ 'docs/css/prettify.css'
151
+ ]
152
+ } ,
153
+
154
+ /**
155
+ * When it is time to have a completely compiled application, we can
156
+ * alter the above to include only a single JavaScript and a single CSS
157
+ * file. Now we're back!
158
+ */
159
+ compile : {
160
+ dir : '<%= dist_dir %>/' ,
161
+ src : [
162
+ '<%= dist_dir %>/assets/js/<%= pkg.name %>-bower.js' ,
163
+ '<%= dist_dir %>/assets/js/<%= pkg.name %>-all.min.js' ,
164
+ '<%= dist_dir %>/assets/css/<%= pkg.name %>-bower.css'
165
+ ]
166
+ }
167
+ } ,
168
+
169
+ 'gh-pages' : {
170
+ options : {
171
+ base : 'dist' ,
172
+ message : 'Update gh-pages'
173
+ } ,
174
+ src : [ '**' ]
175
+ } ,
176
+
73
177
connect : {
74
178
server : {
75
179
options : {
@@ -83,7 +187,7 @@ module.exports = function (grunt) {
83
187
testserver : {
84
188
options : {
85
189
port : 3030 ,
86
- base : '. '
190
+ base : 'dist '
87
191
}
88
192
}
89
193
} ,
@@ -119,7 +223,52 @@ module.exports = function (grunt) {
119
223
grunt . registerTask ( 'tests' , [ 'connect:testserver' , 'build' , 'karma:unit' , 'karma:e2e' ] ) ;
120
224
121
225
grunt . registerTask ( 'build' , [
122
- 'jshint' , 'concat' , 'uglify'
226
+ 'clean' , ' jshint', 'concat:compile_js ' , 'uglify' , 'concat:compile_all_js' , 'concat:compile_bower_js' , 'concat:compile_bower_css' , 'copy:examples' , 'copy:nav' , 'copy:example' , 'index:compile' , 'index:build '
123
227
] ) ;
124
228
229
+ /**
230
+ * A utility function to get all app JavaScript sources.
231
+ */
232
+ function filterForJS ( files ) {
233
+ return files . filter ( function ( file ) {
234
+ return file . match ( / \. j s $ / ) ;
235
+ } ) ;
236
+ }
237
+
238
+ /**
239
+ * A utility function to get all app CSS sources.
240
+ */
241
+ function filterForCSS ( files ) {
242
+ return files . filter ( function ( file ) {
243
+ return file . match ( / \. c s s $ / ) ;
244
+ } ) ;
245
+ }
246
+
247
+ /**
248
+ * The index.html template includes the stylesheet and javascript sources
249
+ * based on dynamic names calculated in this Gruntfile. This task assembles
250
+ * the list into variables for the template to use and then runs the
251
+ * compilation.
252
+ */
253
+ grunt . registerMultiTask ( 'index' , 'Process index.html template' , function ( ) {
254
+ var dirRE = new RegExp ( '^(' + grunt . config ( 'build_dir' ) + '|' + grunt . config ( 'dist_dir' ) + ')\/' , 'g' ) ;
255
+ var jsFiles = filterForJS ( this . filesSrc ) . map ( function ( file ) {
256
+ return file . replace ( dirRE , '' ) ;
257
+ } ) ;
258
+ var cssFiles = filterForCSS ( this . filesSrc ) . map ( function ( file ) {
259
+ return file . replace ( dirRE , '' ) ;
260
+ } ) ;
261
+
262
+ grunt . file . copy ( 'index.tpl.html' , this . data . dir + 'index.html' , {
263
+ process : function ( contents , path ) {
264
+ return grunt . template . process ( contents , {
265
+ data : {
266
+ scripts : jsFiles ,
267
+ styles : cssFiles ,
268
+ version : grunt . config ( 'pkg.version' )
269
+ }
270
+ } ) ;
271
+ }
272
+ } ) ;
273
+ } ) ;
125
274
} ;
0 commit comments