Guest User

Gruntfile.js

a guest
Mar 31st, 2013
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*global module:false*/
  2. module.exports = function(grunt) {
  3.  
  4.     // Project configuration.
  5.     grunt.initConfig({
  6.         // Metadata.
  7.         pkg: grunt.file.readJSON('package.json'),
  8.  
  9.         // Task configuration.
  10.         uglify: {
  11.             options: {
  12.                 banner: '<%= banner %>'
  13.             },
  14.             dist: {
  15.                 src: 'app/application.js',
  16.                 dest: 'dist/application.js'
  17.             }
  18.         },
  19.  
  20.         less: {
  21.             dev: {
  22.                 files: { 'app/css/styles.css': 'app/less/styles.less' },
  23.             },
  24.             prod: {
  25.                 files: { 'app/css/styles.css': 'app/less/styles.less' },
  26.                 options: { yuicompress: true }
  27.             }
  28.         },
  29.  
  30.         htmlmin: {
  31.             dist: {
  32.                 files: {'dist/index.html': 'app/index.html'},
  33.                 options: {
  34.                     removeComments: true,
  35.                     collapseWhitespace: true
  36.                 }
  37.             }
  38.         },
  39.  
  40.         imagemin: {
  41.             dist: {
  42.                 options: {
  43.                     optimizationLevel: 7,
  44.                     progressive: true
  45.                 },
  46.                 files: {
  47.                     'dist/imgs/': 'app/imgs/*',
  48.                     'dist/imgs/icons/': 'app/imgs/icons/*',
  49.                     'dist/css/cupertino/images/': 'app/css/jquery-ui/cupertino/images/*'
  50.                 }
  51.             }
  52.         },
  53.  
  54.         cssmin: {
  55.             dist: {
  56.                 files: {
  57.                     'dist/css/styles.css': [
  58.                         'app/css/jquery-ui/cupertino/jquery-ui.min.css',
  59.                         'app/css/styles.css'
  60.                     ]
  61.                 },
  62.                 options: {
  63.                     keepSpecialComments: 0,
  64.                     report: 'min'
  65.                 }
  66.             }
  67.         },
  68.  
  69.         clean: ['dist'],
  70.  
  71.         jasmine: {
  72.             test: {
  73.                 src: 'app/application.js',
  74.                 options: {
  75.                     specs: 'app/tests/*.js',
  76.                     styles: 'css/styles.css'
  77.                 }
  78.             }
  79.         },
  80.  
  81.         watch: {
  82.             js: {
  83.                 files: [
  84.                     'app/controllers/**',
  85.                     'app/less/**',
  86.                     'app/extras/**',
  87.                     'app/less/**',
  88.                     'app/models/**',
  89.                     'app/routes/**',
  90.                     'app/templates/**',
  91.                     'app/vendor/**',
  92.                     'app/views/**',
  93.                     'routes.js',
  94.                     'store.js',
  95.                     'app.js'
  96.                 ],
  97.                 tasks: ['build']
  98.             },
  99.             less: {
  100.                 files: ['app/less/*'],
  101.                 tasks: ['less:dev']
  102.             }
  103.         }
  104.     });
  105.  
  106.     // These plugins provide necessary tasks.
  107.     (function() {
  108.         grunt.loadNpmTasks('grunt-contrib-concat');
  109.         grunt.loadNpmTasks('grunt-contrib-uglify');
  110.         grunt.loadNpmTasks('grunt-contrib-htmlmin');
  111.         grunt.loadNpmTasks('grunt-contrib-imagemin');
  112.         grunt.loadNpmTasks('grunt-contrib-cssmin');
  113.         grunt.loadNpmTasks('grunt-contrib-less');
  114.         grunt.loadNpmTasks('grunt-contrib-jasmine');
  115.         grunt.loadNpmTasks('grunt-contrib-clean');
  116.         grunt.loadNpmTasks('grunt-contrib-watch');
  117.     })()
  118.  
  119.     grunt.registerTask('build', 'Runs ember-tools build command', function() {
  120.         var done = this.async();
  121.         grunt.util.spawn({ cmd: 'ember', args: ['build'] }, function(e, result) {
  122.             grunt.log.writeln(result);
  123.             done();
  124.         });
  125.     });
  126.  
  127.     grunt.registerTask('prepare-dist', 'Creates folders needed for distribution', function() {
  128.         var folders = ['dist/css/images', 'dist/imgs/icons'];
  129.         for (var i in folders) {
  130.             var done = this.async();
  131.             grunt.util.spawn({ cmd: 'mkdir', args: ['-p', folders[i]] }, function(e, result) {
  132.                 grunt.log.writeln('Folder created');
  133.                 done();
  134.             });
  135.         }
  136.     });
  137.  
  138.     grunt.registerTask('default', ['dist']);
  139.  
  140.     grunt.registerTask('dist', [
  141.         'clean',
  142.         'prepare-dist',
  143.         'build',
  144.         'compress',
  145.         'jasmine'
  146.     ]);
  147.  
  148.     grunt.registerTask('compress', [
  149.         'less:prod',
  150.         'htmlmin',
  151.         'imagemin',
  152.         'cssmin',
  153.         'uglify'
  154.     ]);
  155.  
  156.     grunt.registerTask('css', ['less:dev']);
  157.  
  158.     grunt.registerTask('css-prod', ['less:prod']);
  159.  
  160. };
Advertisement
Add Comment
Please, Sign In to add comment