OSDN Git Service

GeorgeValergas/embrr
[embrj/master.git] / Gruntfile.js
1 // Generated on 2013-12-27 using generator-ember 0.8.0
2 'use strict';
3 var LIVERELOAD_PORT = 35729;
4 var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
5 var mountFolder = function (connect, dir) {
6     return connect.static(require('path').resolve(dir));
7 };
8
9 // # Globbing
10 // for performance reasons we're only matching one level down:
11 // 'test/spec/{,*/}*.js'
12 // use this if you want to match all subfolders:
13 // 'test/spec/**/*.js'
14
15 module.exports = function (grunt) {
16     // show elapsed time at the end
17     require('time-grunt')(grunt);
18     // load all grunt tasks
19     require('load-grunt-tasks')(grunt);
20
21     // configurable paths
22     var yeomanConfig = {
23         app: 'app',
24         dist: 'dist'
25     };
26
27     grunt.initConfig({
28         yeoman: yeomanConfig,
29         watch: {
30             emberTemplates: {
31                 files: '<%= yeoman.app %>/templates/**/*.hbs',
32                 tasks: ['emberTemplates']
33             },
34             compass: {
35                 files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
36                 tasks: ['compass:server']
37             },
38             neuter: {
39                 files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
40                 tasks: ['neuter']
41             },
42             livereload: {
43                 options: {
44                     livereload: LIVERELOAD_PORT
45                 },
46                 files: [
47                     '.tmp/scripts/*.js',
48                     '<%= yeoman.app %>/*.html',
49                     '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
50                     '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
51                 ]
52             }
53         },
54         connect: {
55             options: {
56                 port: 9000,
57                 // change this to '0.0.0.0' to access the server from outside
58                 hostname: 'localhost'
59             },
60             livereload: {
61                 options: {
62                     middleware: function (connect) {
63                         return [
64                             lrSnippet,
65                             mountFolder(connect, '.tmp'),
66                             mountFolder(connect, yeomanConfig.app)
67                         ];
68                     }
69                 }
70             },
71             test: {
72                 options: {
73                     middleware: function (connect) {
74                         return [
75                             mountFolder(connect, '.tmp'),
76                             mountFolder(connect, 'test')
77                         ];
78                     }
79                 }
80             },
81             dist: {
82                 options: {
83                     middleware: function (connect) {
84                         return [
85                             mountFolder(connect, yeomanConfig.dist)
86                         ];
87                     }
88                 }
89             }
90         },
91         open: {
92             server: {
93                 path: 'http://localhost:<%= connect.options.port %>'
94             }
95         },
96         clean: {
97             dist: {
98                 files: [{
99                     dot: true,
100                     src: [
101                         '.tmp',
102                         '<%= yeoman.dist %>/*',
103                         '!<%= yeoman.dist %>/.git*'
104                     ]
105                 }]
106             },
107             server: '.tmp'
108         },
109         jshint: {
110             options: {
111                 jshintrc: '.jshintrc',
112                 reporter: require('jshint-stylish')
113             },
114             all: [
115                 'Gruntfile.js',
116                 '<%= yeoman.app %>/scripts/{,*/}*.js',
117                 '!<%= yeoman.app %>/scripts/vendor/*',
118                 'test/spec/{,*/}*.js'
119             ]
120         },
121         mocha: {
122             all: {
123                 options: {
124                     run: true,
125                     urls: ['http://localhost:<%= connect.options.port %>/index.html']
126                 }
127             }
128         },
129         compass: {
130             options: {
131                 sassDir: '<%= yeoman.app %>/styles',
132                 cssDir: '.tmp/styles',
133                 generatedImagesDir: '.tmp/images/generated',
134                 imagesDir: '<%= yeoman.app %>/images',
135                 javascriptsDir: '<%= yeoman.app %>/scripts',
136                 fontsDir: '<%= yeoman.app %>/styles/fonts',
137                 importPath: 'app/bower_components',
138                 httpImagesPath: '/images',
139                 httpGeneratedImagesPath: '/images/generated',
140                 httpFontsPath: '/styles/fonts',
141                 relativeAssets: false
142             },
143             dist: {},
144             server: {
145                 options: {
146                     debugInfo: true
147                 }
148             }
149         },
150         // not used since Uglify task does concat,
151         // but still available if needed
152         /*concat: {
153             dist: {}
154         },*/
155         // not enabled since usemin task does concat and uglify
156         // check index.html to edit your build targets
157         // enable this task if you prefer defining your build targets here
158         /*uglify: {
159             dist: {}
160         },*/
161         rev: {
162             dist: {
163                 files: {
164                     src: [
165                         '<%= yeoman.dist %>/scripts/{,*/}*.js',
166                         '<%= yeoman.dist %>/styles/{,*/}*.css',
167                         '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
168                         '<%= yeoman.dist %>/styles/fonts/*'
169                     ]
170                 }
171             }
172         },
173         useminPrepare: {
174             html: '.tmp/index.html',
175             options: {
176                 dest: '<%= yeoman.dist %>'
177             }
178         },
179         usemin: {
180             html: ['<%= yeoman.dist %>/{,*/}*.html'],
181             css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
182             options: {
183                 dirs: ['<%= yeoman.dist %>']
184             }
185         },
186         imagemin: {
187             dist: {
188                 files: [{
189                     expand: true,
190                     cwd: '<%= yeoman.app %>/images',
191                     src: '{,*/}*.{png,jpg,jpeg}',
192                     dest: '<%= yeoman.dist %>/images'
193                 }]
194             }
195         },
196         svgmin: {
197             dist: {
198                 files: [{
199                     expand: true,
200                     cwd: '<%= yeoman.app %>/images',
201                     src: '{,*/}*.svg',
202                     dest: '<%= yeoman.dist %>/images'
203                 }]
204             }
205         },
206         cssmin: {
207             dist: {
208                 files: {
209                     '<%= yeoman.dist %>/styles/main.css': [
210                         '.tmp/styles/{,*/}*.css',
211                         '<%= yeoman.app %>/styles/{,*/}*.css'
212                     ]
213                 }
214             }
215         },
216         htmlmin: {
217             dist: {
218                 options: {
219                     /*removeCommentsFromCDATA: true,
220                     // https://github.com/yeoman/grunt-usemin/issues/44
221                     //collapseWhitespace: true,
222                     collapseBooleanAttributes: true,
223                     removeAttributeQuotes: true,
224                     removeRedundantAttributes: true,
225                     useShortDoctype: true,
226                     removeEmptyAttributes: true,
227                     removeOptionalTags: true*/
228                 },
229                 files: [{
230                     expand: true,
231                     cwd: '<%= yeoman.app %>',
232                     src: '*.html',
233                     dest: '<%= yeoman.dist %>'
234                 }]
235             }
236         },
237         replace: {
238           app: {
239             options: {
240               variables: {
241                 ember: 'bower_components/ember/ember.js',
242                 ember_data: 'bower_components/ember-data-shim/ember-data.js'
243               }
244             },
245             files: [
246               {src: '<%= yeoman.app %>/index.html', dest: '.tmp/index.html'}
247             ]
248           },
249           dist: {
250             options: {
251               variables: {
252                 ember: 'bower_components/ember/ember.prod.js',
253                 ember_data: 'bower_components/ember-data-shim/ember-data.prod.js'
254               }
255             },
256             files: [
257               {src: '<%= yeoman.app %>/index.html', dest: '.tmp/index.html'}
258             ]
259           }
260         },
261         // Put files not handled in other tasks here
262         copy: {
263             dist: {
264                 files: [{
265                     expand: true,
266                     dot: true,
267                     cwd: '<%= yeoman.app %>',
268                     dest: '<%= yeoman.dist %>',
269                     src: [
270                         '*.{ico,txt}',
271                         '.htaccess',
272                         'images/{,*/}*.{webp,gif}',
273                         'styles/fonts/*'
274                     ]
275                 }]
276             }
277         },
278         concurrent: {
279             server: [
280                 'emberTemplates',
281                 'compass:server'
282             ],
283             test: [
284                 'emberTemplates',
285                 'compass'
286             ],
287             dist: [
288                 'emberTemplates',
289                 'compass:dist',
290                 'imagemin',
291                 'svgmin',
292                 'htmlmin'
293             ]
294         },
295         emberTemplates: {
296             options: {
297                 templateName: function (sourceFile) {
298                     var templatePath = yeomanConfig.app + '/templates/';
299                     return sourceFile.replace(templatePath, '');
300                 }
301             },
302             dist: {
303                 files: {
304                     '.tmp/scripts/compiled-templates.js': '<%= yeoman.app %>/templates/{,*/}*.hbs'
305                 }
306             }
307         },
308         neuter: {
309             app: {
310                 options: {
311                     filepathTransform: function (filepath) {
312                         return 'app/' + filepath;
313                     }
314                 },
315                 src: '<%= yeoman.app %>/scripts/app.js',
316                 dest: '.tmp/scripts/combined-scripts.js'
317             }
318         }
319     });
320
321     grunt.registerTask('server', function (target) {
322         if (target === 'dist') {
323             return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
324         }
325
326         grunt.task.run([
327             'clean:server',
328             'replace:app',
329             'concurrent:server',
330             'neuter:app',
331             'connect:livereload',
332             'open',
333             'watch'
334         ]);
335     });
336
337     grunt.registerTask('test', [
338         'clean:server',
339         'replace:app',
340         'concurrent:test',
341         'connect:test',
342         'neuter:app',
343         'mocha'
344     ]);
345
346     grunt.registerTask('build', [
347         'clean:dist',
348         'replace:dist',
349         'useminPrepare',
350         'concurrent:dist',
351         'neuter:app',
352         'concat',
353         'cssmin',
354         'uglify',
355         'copy',
356         'rev',
357         'usemin'
358     ]);
359
360     grunt.registerTask('default', [
361         'jshint',
362         'test',
363         'build'
364     ]);
365 };