Guest User

Untitled

a guest
Sep 25th, 2014
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var path = require('path');
  2. module.exports = function (grunt) {
  3.  
  4.     // configure the tasks
  5.     grunt.initConfig({
  6.  
  7.         useminPrepare: {
  8.             html: 'build/index.html',
  9.             options: {
  10.                 root: 'build',
  11.                 dest: 'build',
  12.                 flow: {
  13.                     steps: {
  14.                         js: [
  15.                             'concat',
  16.                             {
  17.                                 name: 'ngAnnotate',
  18.                                 createConfig: function (context, block) {
  19.                                     var cfg = {
  20.                                         files: []
  21.                                     };
  22.                                     context.outFiles = [];
  23.  
  24.                                     // Depending whether or not we're the last of the step we're not going to output the same thing:
  25.                                     // if we're the last one we must use the block dest file name for output
  26.                                     // otherwise uglify each input file into its given outputfile
  27.                                     if (context.last === true) {
  28.                                         var files = {};
  29.                                         var ofile = path.join(context.outDir, block.dest);
  30.                                         files.dest = ofile;
  31.                                         files.src = context.inFiles.map(function (fname) {
  32.                                             return path.join(context.inDir, fname);
  33.                                         });
  34.                                         // cfg[ofile] = context.inFiles.map(function (fname) { return path.join(context.inDir, fname);});
  35.                                         cfg.files.push(files);
  36.                                         context.outFiles.push(block.dest);
  37.                                     } else {
  38.                                         context.inFiles.forEach(function (fname) {
  39.                                             var file = path.join(context.inDir, fname);
  40.                                             var outfile = path.join(context.outDir, fname);
  41.                                             cfg.files.push({
  42.                                                 src: [file],
  43.                                                 dest: outfile
  44.                                             });
  45.                                             // cfg[outfile] = [file];
  46.                                             context.outFiles.push(fname);
  47.                                         });
  48.                                     }
  49.                                     return cfg;
  50.                                 }
  51.                             },
  52.                             'uglifyjs'
  53.                         ],
  54.                         css: [ 'concat', 'cssmin' ]
  55.                     },
  56.                     post: {
  57.                         js: [{
  58.                             name: 'uglify',
  59.                             createConfig: function (context) {
  60.                                 context.options.generated.options = {preserveComments: 'some'};
  61.                             }
  62.                         }, {
  63.                             name: 'ngAnnotate',
  64.                             createConfig: function (context) {
  65.                                 context.options.generated.options = {singleQuotes: true};
  66.                             }
  67.                         }]
  68.                     }
  69.                 }
  70.             }
  71.         },
  72.  
  73.         processhtml: {
  74.             build: {
  75.                 files: {
  76.                     'build/index.html': ['build/index.html']
  77.                 }
  78.             },
  79.             options: {
  80.                 data: {
  81.                     path: '/',
  82.                     gacode: 'UA-2328122-20'
  83.                 },
  84.                 commentMarker: 'process'
  85.             }
  86.         },
  87.  
  88.         usemin: {
  89.             html: 'build/index.html',
  90.             options: {
  91.                 root: 'build',
  92.                 dest: 'build'
  93.             }
  94.         },
  95.  
  96.         copy: {
  97.             build: {
  98.                 files: [
  99.                     {
  100.                         expand: true,
  101.                         cwd: 'client/bower_components/ckeditor',
  102.                         src: ['**'],
  103.                         dest: 'client/lib/ckeditor'
  104.                     },
  105.                     {
  106.                         expand: true,
  107.                         cwd: 'client/',
  108.                         src: [ '**' ],
  109.                         dest: 'build'
  110.                     },
  111.                     {
  112.                         expand: true,
  113.                         cwd: 'client/bower_components/bootstrap/dist',
  114.                         src: [ 'fonts', 'fonts/**' ],
  115.                         dest: 'build',
  116.                     }
  117.                 ]
  118.             }
  119.         },
  120.  
  121.         clean: {
  122.             build: {
  123.                 src: [ 'build' ]
  124.             },
  125.             stylesheets: {
  126.                 src: [ 'build/**/*.css', '!build/css/optimized.css', '!build/lib/**' ]
  127.             },
  128.             scripts: {
  129.                 src: [ 'build/js/controllers', 'build/js/services', 'build/js/directives', 'build/**/*.js', '!build/js/*-optimized.js', '!build/lib/**' ]
  130.             },
  131.             other: {
  132.                 src: [ 'build/bower_components', '.tmp', 'build/bower.json' ]
  133.             }
  134.         },
  135.  
  136.         loopback_angular: {
  137.             services: {
  138.                 options: {
  139.                     input: 'server/app.js',
  140.                     output: 'client/js/services/lb-services.js'
  141.                 }
  142.             }
  143.         },
  144.  
  145.         watch: {
  146.             assets: {
  147.                 files: [ 'client/**/*.css', 'client/**/*.js', 'client/index.html'],
  148.                 tasks: [ 'copy', 'processhtml', 'assets' ]
  149.             },
  150.  
  151.             services: {
  152.                 files: [ 'server/models.json', 'server/models/*.*' ],
  153.                 tasks: [ 'services' ]
  154.             },
  155.  
  156.             copy: {
  157.                 files: [ 'client/**', '!client/**/*.css', '!client/**/*.js', '!client/index.html' ],
  158.                 tasks: [ 'copy', 'processhtml' ]
  159.             }
  160.         }
  161.  
  162.     });
  163.  
  164.     // load the tasks
  165.     grunt.loadNpmTasks('grunt-contrib-copy');
  166.     grunt.loadNpmTasks('grunt-contrib-concat');
  167.     grunt.loadNpmTasks('grunt-contrib-clean');
  168.     grunt.loadNpmTasks('grunt-contrib-cssmin');
  169.     grunt.loadNpmTasks('grunt-contrib-uglify');
  170.     grunt.loadNpmTasks('grunt-contrib-watch');
  171.     grunt.loadNpmTasks('grunt-loopback-angular');
  172.     grunt.loadNpmTasks('grunt-usemin');
  173.     grunt.loadNpmTasks('grunt-processhtml');
  174.     grunt.loadNpmTasks('grunt-ng-annotate');
  175.  
  176.  
  177.     // define the tasks
  178.     grunt.registerTask(
  179.         'default',
  180.         'Watches the project for changes, automatically builds them.',
  181.         [ 'build', 'watch' ]
  182.     );
  183.  
  184.     grunt.registerTask(
  185.         'services',
  186.         [ 'loopback_angular' ]
  187.     );
  188.     grunt.registerTask(
  189.         'assets',
  190.         'Compiles the scripts stylesheets.',
  191.         [ 'useminPrepare', 'concat', 'cssmin', 'ngAnnotate', 'uglify', 'usemin', 'clean:other', 'clean:stylesheets', 'clean:scripts' ]
  192.     );
  193.  
  194.  
  195.     grunt.registerTask(
  196.         'build',
  197.         'Compiles all of the assets and copies the files to the build directory.',
  198.         [ 'services', 'clean:build', 'copy', 'processhtml', 'assets' ]
  199.     );
  200. };
Advertisement
Add Comment
Please, Sign In to add comment