16/02/2014 Development / grunt

Essa semana eu fiz o arquivo que gera todas as tarefas do SIO, como:

Minificar e gerar o js;
Buildar todos os arquivos sass, minificar;
Gerar o pacote;

O arquivo ficou mais ou menos assim:

 module.exports = function(grunt) {

 // Project configuration.
 grunt.initConfig({
   pkg: grunt.file.readJSON('package.json'),

    /* 1- Minifica o js */
    /****************************************************************************/
    uglify: {
     options: {
       compress: true,
       banner: '/*! <%= pkg.name %> - <%= pkg.author %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n'
     },
     build: {
       src: 'Core/js/funcoes.js',
       dest: 'Core/js/funcoes.min.js'
     }
    },


    /* 2- Testa o js */
    /****************************************************************************/
    jshint: {
      ignore_warning: {
          options: {
              '-W061': true,
              '-W030': true
          },
          src: ['Core/js/funcoes.js'],
      }
    },   

    /* 3-  Gera e Minifica todos os css .scss */
    /****************************************************************************/
    sass: {
        dist: {
            options: {
                outputStyle: 'compressed'
            },
            files: [{
        expand: true,
        src: ['Core/**/*.scss'],
        ext: '.css'
        }]
      }
    },

    /* 4- Copia todos os arquivos pra pasta build target */
    /****************************************************************************/
    copy: {
        main: {
            expand: true,
            cwd: 'Core/',
            src: ['**'],
            dest: 'build/'
        },

        /* 4-2 Copia apenas a pasta do meu projeto em execucao para a pasta build */
        /****************************************************************************/
        my_build:{
            expand: true,
            cwd: 'Core/css/appThemes/' + grunt.option('target'),
            src: ['**'],
            dest: 'build/css/appThemes/' + grunt.option('target')
          }
    },

    /* Apaga os themas desnecessarios */
    /****************************************************************************/
    clean: {
      build : {
        src : ["build/css/appThemes","build/imagens/png","build/css/componentes","build/css/*.scss","build/js/funcoes.js"]
      },
      my_build : {
       src : ["build/css/appThemes/" + grunt.option('target') + "/css/estilo.scss"] 
      },
      init : {
       src : ["build"] 
      }
    },


    /* Fica escutando alteracoes nos arquivos */
    /****************************************************************************/
    watch: {
        options: {
            livereload: 1337,
        },
        scripts: {
            files: ['Core/**/*.js'],
            tasks: ['build']
        },
        css: {
            files: ['Core/**/*.css'],
            tasks: ['build']
        }
    }
 });

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');

 // Default task(s).
 grunt.registerTask('build', ['clean:init','uglify','jshint','sass','copy','clean:build','copy:my_build','clean:my_build']);
 grunt.registerTask('default', ['watch']);
};