Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var getBuildDir = function(grunt) {
  4.     return grunt.option('dir');    
  5. }
  6.  
  7. var getEditLess = function(grunt) {
  8.     return grunt.option('editLess');    
  9. }
  10.  
  11. var getPort = function(grunt) {
  12.     return grunt.option('port');    
  13. }
  14.  
  15. var getEnv = function(grunt) {
  16.     return grunt.option('env');    
  17. }
  18.  
  19. var getSSL = function(grunt) {
  20.     return grunt.option('ssl');    
  21. }
  22.  
  23. module.exports = function (grunt) {
  24.     require('time-grunt')(grunt);
  25.     require('jit-grunt')(grunt, {
  26.         sprite: 'grunt-spritesmith',
  27.         watch: 'grunt-contrib-watch-chokidar'
  28.     });
  29.     var gruntConfig = grunt.file.readJSON('gruntConfig.json');
  30.     var buildDir = '';
  31.     var editLess = false;
  32.     var production = false;
  33.     var mobile = false;
  34.     var ssl = false;
  35.    
  36.     if (getBuildDir(grunt)) {
  37.         buildDir = getBuildDir(grunt);
  38.     } else {
  39.         buildDir = gruntConfig.BUILD_PUBLIC_DIR;
  40.     }
  41.    
  42.     if (getPort(grunt)) {
  43.         var SERVER_PORT = getPort(grunt);
  44.     } else {
  45.         var SERVER_PORT = 3000;
  46.     }
  47.    
  48.     if (getEditLess(grunt)) {
  49.         editLess = true;
  50.     }
  51.    
  52.     if (getSSL(grunt)) {
  53.         ssl = true;
  54.     }
  55.    
  56.     if (getEnv(grunt) == 'prod') {
  57.         production = true;
  58.     }
  59.    
  60.     if (getEnv(grunt) == 'mobile') {
  61.         mobile = true;
  62.     }
  63.    
  64.     //js
  65.     var js = grunt.file.readJSON('static/js.json');
  66.    
  67.     // configurable paths
  68.     var yeomanConfig = {
  69.         sitename: gruntConfig.PROJECT_NAME,
  70.         tmp: '.',
  71.         dev: gruntConfig.LOCAL_CQ5_PROJECT_DIR,
  72.         igamingDev: gruntConfig.LOCAL_IGAMING_CQ5_PROJECT_DIR,
  73.         local: 'target',
  74.         build: buildDir,
  75.         releasePackage: 'baseline-alpha.zip',
  76.         cashierApp: gruntConfig.LOCAL_CASHIER_PROJECT_DIR,
  77.         TPApiKey: gruntConfig.TINYPNG_API_KEY,
  78.         devAssetsCQDirectory: 'ui/portal-app/src/main/content/jcr_root',
  79.         devAssetsPath: 'etc/designs/interactive/ilottery/common/home',
  80.         igamingDevAssetsCQDirectory: 'ui/portal-app/src/main/content/jcr_root',
  81.         igamingDevAssetsPath: 'etc/clientlibs/interactive/igaming/common/libs'
  82.     };
  83.  
  84.     var lessOptions = {
  85.         plugins: [
  86.             require('less-plugin-glob'),
  87.             new (require('less-plugin-autoprefix'))({browsers: ["last 2 versions"]})
  88.         ]
  89.     }
  90.    
  91.     grunt.initConfig({
  92.         yeoman: yeomanConfig,
  93.        
  94.         less: {
  95.             local: {
  96.                 options: lessOptions,
  97.                 files: {
  98.                     "<%= yeoman.local %>/static/portal.css": "static/less/portal/portal.less"
  99.                 }
  100.             },
  101.  
  102.             styleguide: {
  103.                 options: lessOptions,
  104.                 files: {
  105.                     "<%= yeoman.local %>/static/portal.css": "static/less/portal/portal.less",
  106.                     "<%= yeoman.local %>/static/styleguide.css": "static/less/styleguide/styleguide.less"
  107.                 }
  108.             },
  109.  
  110.             dev: {
  111.                 options: Object.assign({
  112.                     modifyVars: {
  113.                         'base-url': "'/content/dam/interactive/ilottery/images/'",
  114.                         // 'ilottery-base-url': "'/content/dam/interactive/ilottery/images/'",
  115.                         'igaming-base-url': "'/content/dam/interactive/igaming/'",
  116.                         'icon-font-path': "'/<%= yeoman.devAssetsPath %>/fonts/'",
  117.                         "sprite-image-path": "'/<%= yeoman.devAssetsPath %>/images/'",
  118.                         'fa-font-path': "'/<%= yeoman.devAssetsPath %>/fonts/font-awesome/fonts'"
  119.                     }
  120.                 }, lessOptions),
  121.                 files: {
  122.                     "<%= yeoman.dev %>/<%= yeoman.devAssetsCQDirectory %>/<%= yeoman.devAssetsPath %>/portal.css": "static/less/portal/portal.less",
  123.                     "<%= yeoman.dev %>/<%= yeoman.devAssetsCQDirectory %>/<%= yeoman.devAssetsPath %>/cq-components.css": "static/less/cq/cq-portal.less",
  124.                 }
  125.             },
  126.  
  127.             cashierLocal: {
  128.                 options: Object.assign({
  129.                     compress: true,
  130.                     sourceMap: true,
  131.                     sourceMapFileInline: true,
  132.                     sourceMapRootpath: "/"
  133.                 }, lessOptions),
  134.                 files: {
  135.                     "<%= yeoman.local %>/static/cashierapp/cashierapp-portal.css": "static/less/cashierapp/cashierapp-portal.less",
  136.                     "<%= yeoman.local %>/static/cashierapp/cashierapp-mobile.css": "static/less/cashierapp/cashierapp-mobile.less"
  137.                 }
  138.             },
  139.  
  140.             cashierDev: {
  141.                 options: Object.assign({
  142.                     modifyVars: {
  143.                         'base-url': "'images/'"
  144.                         , 'icon-font-path': "'../fonts/'"
  145.                     }
  146.                 }, lessOptions),
  147.                 files: {
  148.                     "<%= yeoman.cashierApp %>cashier-web/src/assets/styles/cashierapp-mobile.css": "static/less/cashierapp/cashierapp-mobile.less",
  149.                     "<%= yeoman.cashierApp %>cashier-web/src/assets/styles/cashierapp-portal.css": "static/less/cashierapp/cashierapp-portal.less"
  150.                 }
  151.             }
  152.         },
  153.        
  154.         // Temp: iGaming variables for components
  155.         // This will be removed once iGaming and iLottery become one instance in CQ
  156.         concat: {
  157.             dev: {
  158.                 src: ['static/less/portal/variables/*'],
  159.                 dest: '<%= yeoman.igamingDev %>/<%= yeoman.igamingDevAssetsCQDirectory %>/<%= yeoman.igamingDevAssetsPath %>/less/variables.less'
  160.             }
  161.         },
  162.        
  163.         sprite: {
  164.             global: {
  165.                 src: ['static/img/sprites/**/*.png'],
  166.                 retinaSrcFilter: ['static/img/sprites**/*@2x.png'],
  167.                 dest: 'static/img/spritesheet.png',
  168.                 imgPath: '@{sprite-image-path}spritesheet.png',
  169.                 // imgPath: '@{base-url}spritesheet.png'+ '?v' +  (new Date().getTime()),
  170.                 retinaDest: 'static/img/spritesheet@2x.png',
  171.                 retinaImgPath: '@{sprite-image-path}spritesheet@2x.png',
  172.                 // retinaImgPath: '@{base-url}spritesheet@2x.png'+ '?v' +  (new Date().getTime()),
  173.                 cssTemplate: 'static/handlebar-templates/sprites.less.handlebars',
  174.                 padding: 3,
  175.                 destCss: 'static/less/portal/sprites.less'
  176.             }
  177.         },
  178.  
  179.         sync: {
  180.             local: {
  181.                 files: [{
  182.                     cwd: '.',
  183.                     src: [
  184.                         'static/{,**/}*.{jpg,png,gif,jpeg,ttf,woff,woff2,eot,svg,js,html,css,pdf,less,json}',
  185.                         'bower_components/slick-carousel/slick/**/*.{jpg,png,gif,jpeg,ttf,woff,woff2,eot,svg,js,css}',
  186.                         'bower_components/bootstrap-daterangepicker/daterangepicker-bs3.css',
  187.                         "bower_components/underscore/underscore-min.js",
  188.                         "bower_components/bootstrap/dist/js/bootstrap.js",
  189.                         "bower_components/moment/moment.js",
  190.                         "bower_components/bootstrap-daterangepicker/daterangepicker.js",
  191.                         "bower_components/bootstrap-datepicker/js/bootstrap-datepicker.js",
  192.                         "bower_components/jquery-validation/dist/jquery.validate.js",
  193.                         "bower_components/matchHeight/jquery.matchHeight-min.js",
  194.                         "bower_components/picturefill/dist/picturefill.min.js",
  195.                         "bower_components/bootstrap-select/dist/js/bootstrap-select.js",
  196.                         "bower_components/slick-carousel/slick/slick.js",
  197.                         "bower_components/isotope/dist/isotope.pkgd.min.js",
  198.                         "bower_components/jquery.countdown/dist/jquery.countdown.js",
  199.                         "bower_components/screenfull/dist/screenfull.min.js",
  200.                         "bower_components/tablesorter/dist/js/jquery.tablesorter.combined.min.js",
  201.                         "bower_components/tablesorter/dist/js/extras/jquery.tablesorter.pager.min.js",
  202.                         "bower_components/photoswipe/dist/**/*",
  203.                         "bower_components/jquery/dist/**/*",
  204.                         '!node_modules/**/*',
  205.                         '!ui/**/*',
  206.                         '!Gruntfile.js'
  207.                     ],
  208.                     dest: '<%= yeoman.local %>'
  209.                 }]
  210.             }
  211.         },
  212.        
  213.         copy: {
  214.             cqfonts: {
  215.                 files: [{
  216.                     expand: true,
  217.                     // flatten: true,
  218.                     cwd: 'static/fonts/',
  219.                     src: '**',
  220.                     dest: '<%= yeoman.dev %>/<%= yeoman.devAssetsCQDirectory %>/<%= yeoman.devAssetsPath %>/fonts/',
  221.                     filter: 'isFile'
  222.                 }]
  223.             },
  224.            
  225.             cqless: {
  226.                 files: [{
  227.                     expand: true,
  228.                     // flatten: true,
  229.                     cwd: 'static/less/',
  230.                     src: [
  231.                         '**',
  232.                         '!styleguide/**/*'
  233.                     ],
  234.                     dest: '<%= yeoman.dev %>/<%= yeoman.devAssetsCQDirectory %>/<%= yeoman.devAssetsPath %>/less/portal/'
  235.                     // filter: 'isFile'
  236.                 }]
  237.             },
  238.  
  239.             build: {
  240.                 files: [{
  241.                     expand: true,
  242.                     // flatten: true,
  243.                     cwd: '<%= yeoman.local %>',
  244.                     src: [
  245.                         '**/*'
  246.                     ],
  247.                     dest: '<%= yeoman.build %>'
  248.                     // filter: 'isFile'
  249.                 }]
  250.             },
  251.  
  252.             tmp: {
  253.                 files: [{
  254.                     expand: true,
  255.                     // flatten: true,
  256.                     cwd: '.',
  257.                     src: [
  258.                         '**/*.{jpg,png,gif,jpeg,ttf,woff,woff2,eot,svg,js,html,css,pdf,map}',
  259.                         '!node_modules/**/*',
  260.                         '!bower_components/**/*',
  261.                         '!ui/**/*',
  262.                         '!Gruntfile.js'
  263.                     ],
  264.                     dest: 'tmp'
  265.                 }]
  266.             },
  267.  
  268.             local: {
  269.                 files: [{
  270.                     expand: true,
  271.                     // flatten: true,
  272.                     cwd: '.',
  273.                     src: [
  274.                         'static/{,**/}*.{jpg,png,gif,jpeg,ttf,woff,woff2,eot,svg,js,html,css,pdf,less,json}',
  275.                         'bower_components/slick-carousel/slick/**/*.{jpg,png,gif,jpeg,ttf,woff,woff2,eot,svg,js,css}',
  276.                         'bower_components/bootstrap-daterangepicker/daterangepicker-bs3.css',
  277.                         "bower_components/underscore/underscore-min.js",
  278.                         "bower_components/bootstrap/dist/js/bootstrap.js",
  279.                         "bower_components/moment/moment.js",
  280.                         "bower_components/bootstrap-daterangepicker/daterangepicker.js",
  281.                         "bower_components/bootstrap-datepicker/js/bootstrap-datepicker.js",
  282.                         "bower_components/jquery-validation/dist/jquery.validate.js",
  283.                         "bower_components/matchHeight/jquery.matchHeight-min.js",
  284.                         "bower_components/picturefill/dist/picturefill.min.js",
  285.                         "bower_components/bootstrap-select/dist/js/bootstrap-select.js",
  286.                         "bower_components/slick-carousel/slick/slick.js",
  287.                         "bower_components/isotope/dist/isotope.pkgd.min.js",
  288.                         "bower_components/jquery.countdown/dist/jquery.countdown.js",
  289.                         "bower_components/screenfull/dist/screenfull.min.js",
  290.                         "bower_components/tablesorter/dist/js/jquery.tablesorter.combined.min.js",
  291.                         "bower_components/tablesorter/dist/js/extras/jquery.tablesorter.pager.min.js",
  292.                         "bower_components/photoswipe/dist/**/*",
  293.                         "bower_components/jquery/dist/**/*",
  294.                         '!node_modules/**/*',
  295.                         '!ui/**/*',
  296.                         '!Gruntfile.js'
  297.                     ],
  298.                     dest: '<%= yeoman.local %>'
  299.                 }]
  300.             },
  301.  
  302.             fa: {
  303.                 files: [{
  304.                     expand: true,
  305.                     // flatten: true,
  306.                     cwd: 'bower_components/font-awesome/',
  307.                     src: '**',
  308.                     dest: 'static/fonts/font-awesome/',
  309.                     filter: 'isFile'
  310.                 }]
  311.             },
  312.         },
  313.        
  314.         bless: {
  315.             css: {
  316.                 options: {},
  317.                 files: {
  318.                     '<%= yeoman.local %>/static/ie-abovelimit.css': '<%= yeoman.local %>/static/portal.css'
  319.                 }
  320.             }
  321.         },
  322.  
  323.         clean: {
  324.             html:  ['<%= yeoman.local %>/*.html'],
  325.             tmp: {
  326.                 html:  ['<%= yeoman.tmp %>/*.html'],
  327.                 tmp: ['tmp'],
  328.             },
  329.             local: ['<%= yeoman.local %>'],
  330.             build: ['<%= yeoman.build %>']
  331.         },
  332.    
  333.         /* lets look at image compression */
  334.         imagemin: {
  335.             local: {
  336.                 files: [{
  337.                     expand: true,
  338.                     cwd: 'static/img',
  339.                     src: '{,*/}*.{png,jpg,jpeg,gif}',
  340.                     dest: '<%= yeoman.local %>/static/img'
  341.                 }]
  342.             }
  343.         },
  344.  
  345.         tinypng: {
  346.             options: {
  347.                 apiKey: '<%= yeoman.TPApiKey %>',
  348.                 summarize: true,
  349.                 summarizeOnError: true,
  350.                 showProgress: true
  351.             },
  352.             ssDev: {
  353.                 expand: true,
  354.                 cwd: 'static/img',
  355.                 src: [
  356.                     'spritesheet.png',
  357.                     'spritesheet@2x.png'
  358.                 ],
  359.                 dest: '<%= yeoman.dev %>/<%= yeoman.devAssetsCQDirectory %>/<%= yeoman.devAssetsPath %>/images/'
  360.             }
  361.         },
  362.  
  363.         svgmin: {
  364.             local: {
  365.                 files: [{
  366.                     expand: true,
  367.                     cwd: 'static/img',
  368.                     src: '{,**/}*.svg',
  369.                     dest: '<%= yeoman.local %>/static/img'
  370.                 }]
  371.             }
  372.         },
  373.  
  374.         uglify: {
  375.             options: {
  376.                 mangle: false
  377.             },
  378.             my_target: {
  379.                 files: {
  380.                     '<%= yeoman.local %>/static/js/all.js': js,
  381.                 }
  382.             }
  383.         },
  384.  
  385.         assemble: {
  386.             options: {
  387.                 editLessMode: editLess,
  388.                 assets: 'static',
  389.                 images: 'static/img/',
  390.                 igamingImages: 'static/img/igaming/',
  391.                 partials: 'ui/partials/**/*.hbs',
  392.                 layout: 'default.hbs',
  393.                 layoutdir: 'ui/layouts/',
  394.                 data: ['static/lang/language.json'],
  395.                 flatten: true,
  396.                 production: production,
  397.                 mobile: mobile,
  398.                 helpers: 'helpers/**/*.js'
  399.             },
  400.             pages: {
  401.                 files: {
  402.                     '<%= yeoman.tmp %>/': ['ui/pages/**/*.hbs']
  403.                 }
  404.             },
  405.             local: {
  406.                 files: {
  407.                     '<%= yeoman.local %>/': ['ui/pages/**/*.hbs']
  408.                 }
  409.             }
  410.         },
  411.  
  412.         watch: {
  413.             less: {
  414.                 files: ['static/**/*.less'],
  415.                 tasks: ['less:local']
  416.                 // tasks: ['less:cashierLocal', 'newer:copy:local']  
  417.             },
  418.             js: {
  419.                 files: ['static/{,**/}*.js'],
  420.                 tasks: ['newer:copy:local']
  421.             },
  422.             img: {
  423.                 files: ['static/**/*.{jpg,png,gif,jpeg,svg}'],
  424.                 tasks: ['sprite', 'newer:copy:local']
  425.             },
  426.             assemble: {
  427.                 files: ['ui/**/*.hbs', 'static/lang/language.json'],
  428.                 tasks: ['assemble:local']
  429.             }
  430.         },
  431.  
  432.         browserSync: {
  433.             bsFiles: {
  434.                 src: [
  435.                     '<%= yeoman.local %>/static/*.css',
  436.                     '<%= yeoman.local %>/*.html'
  437.                 ]
  438.             },
  439.             options: {
  440.                 https: ssl,
  441.                 watchTask: true,
  442.                 server: './<%= yeoman.local %>',
  443.                 port: SERVER_PORT
  444.             }
  445.         },
  446.  
  447.         asciify: {
  448.             banner: {
  449.                 text: '<%= yeoman.sitename %>',
  450.  
  451.                 // Add the awesome to the console, and use the best font.
  452.                 options: {
  453.                     font: 'big',
  454.                     log: true
  455.                 }
  456.             }
  457.         },
  458.  
  459.         //cssmin css for --prod
  460.         cssmin: {
  461.             portal: {
  462.                 files: {
  463.                     '<%= yeoman.local %>/static/all.css': [
  464.                         'bower_components/slick-carousel/slick/slick.css',
  465.                         'bower_components/bootstrap-daterangepicker/daterangepicker-bs3.css',
  466.                         'static/js/bootstrap-datepicker/css/datepicker.css',
  467.                         '<%= yeoman.local %>/static/portal.css'
  468.                     ]
  469.                 }
  470.             } ,
  471.             cashier: {
  472.                 files: {
  473.                     '<%= yeoman.cashierApp %>cashier-web/src/assets/styles/cashierapp-portal.min.css': '<%= yeoman.cashierApp %>cashier-web/src/assets/styles/cashierapp-portal.css',
  474.                     '<%= yeoman.cashierApp %>cashier-web/src/assets/styles/cashierapp-mobile.min.css': '<%= yeoman.cashierApp %>cashier-web/src/assets/styles/cashierapp-mobile.css'
  475.                 }
  476.             }
  477.         },
  478.  
  479.         compress: {
  480.             main: {
  481.                 options: {
  482.                     archive: 'build/<%= yeoman.releasePackage %>',
  483.                 },
  484.                 expand: true,
  485.                 cwd: '<%= yeoman.local %>/',
  486.                 src: ['**/*'],
  487.                 dest: '/'
  488.             }
  489.         },
  490.  
  491.         ssh: grunt.file.readJSON('ssh.json'),
  492.         /* example file
  493.         {  
  494.             'path': '//home/mypath',
  495.             'host': 'myhost',
  496.             'username': 'username',
  497.         } */
  498.  
  499.         sftp: {
  500.             deploy: {
  501.                 files: {
  502.                     "./": 'build/<%= yeoman.releasePackage %>'
  503.                 },
  504.                 options: {
  505.                     path: '<%= ssh.path %>',
  506.                     host: '<%= ssh.host %>',
  507.                     username: '<%= ssh.username %>',
  508.                     password: '<%= ssh.password %>',
  509.                     showProgress: true,
  510.                     createDirectories: true
  511.                 }
  512.             }
  513.         }
  514.     });
  515.  
  516.     grunt.registerTask('default', function () {
  517.         grunt.loadNpmTasks('assemble');
  518.  
  519.         if (production == true) {
  520.             return grunt.task.run(['sprite', 'newer:copy:fa', 'newer:copy:local', 'newer:imagemin', 'newer:svgmin', 'less:local', 'uglify', 'cssmin:portal', 'assemble:local']);
  521.         } else {
  522.             return grunt.task.run(['sprite', 'newer:copy:fa', 'newer:copy:local', 'newer:imagemin', 'newer:svgmin', 'less:local', 'assemble:local']);
  523.         }
  524.     });
  525.  
  526.     grunt.registerTask('images', ['tinypng']);
  527.     grunt.registerTask('serve', ['default', 'browserSync', 'asciify', 'watch']);
  528.     grunt.registerTask('cleanlocal', ['clean:local']);
  529.     grunt.registerTask('dev', ['less:dev', 'concat:dev', 'newer:copy:cqfonts', 'newer:copy:cqless']);
  530.     grunt.registerTask('devPng', ['less:dev', 'newer:copy:cqfonts', 'newer:copy:cqless', 'newer:tinypng']);
  531.     grunt.registerTask('cashier-local', ['less:cashierLocal', 'browserSync', 'watch']);
  532.     grunt.registerTask('cashier-dev', ['less:cashierDev', 'cssmin:cashier']);
  533.     grunt.registerTask('build', ['default', 'copy:build']);
  534.     grunt.registerTask('zip', ['default', 'compress']);
  535.     grunt.registerTask('deploy', ['default', 'compress', 'sftp']);
  536.     grunt.registerTask('cleanbuild', ['clean:build']);
  537. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement