Gruntfile.js 6.8 KB
module.exports = function (grunt) {
    var uglifyFiles = {
        files: {
            'scripts/vendor/modernizr.js': 'components/modernizr/modernizr.js',
            'scripts/vendor/r.js': 'components/requirejs/require.js'
        }
    };
    grunt.initConfig(
        {
            // Watches for changes and runs tasks
            watch: {
                sass: {
                    files: ['styles/**/*.scss'],
                    tasks: ['sass:production']
                },
                js: {
                    files: ['scripts/**/*.js', '!scripts/optimized.min.js'],
                    tasks: ['jshint', 'requirejs:production']
                },
                php: {
                    files: ['**/*.php'],
                    tasks: []
                }
            },

            // JsHint your javascript
            jshint: {
                all: [
                    'scripts/*.js',
                    '!scripts/modernizr.js',
                    '!scripts/*.min.js',
                    '!scripts/vendor/**/*.js',
                    '!scripts/src/*.js'
                ],
                options: {
                    browser: true,
                    curly: false,
                    eqeqeq: false,
                    eqnull: true,
                    expr: true,
                    immed: true,
                    newcap: true,
                    noarg: true,
                    smarttabs: true,
                    sub: true,
                    undef: false
                }
            },

            // Dev and production build for sass
            sass: {
                production: {
                    files: [
                        {
                            src: ['**/*.scss', '!**/_*.scss'],
                            cwd: 'styles',
                            dest: 'styles',
                            ext: '.css',
                            expand: true
                        }
                    ],
                    options: {
                        style: 'compressed'
                    }
                },
                dev: {
                    files: [
                        {
                            src: ['**/*.scss', '!**/_*.scss'],
                            cwd: 'styles',
                            dest: 'styles',
                            ext: '.css',
                            expand: true
                        }
                    ],
                    options: {
                        style: 'expanded'
                    }
                }
            },

            browserSync: {
                dev: {
                    bsFiles: {
                        src: [
                            '**/*.css',
                            "**/*.php"
                        ]
                    },
                    options: {
                        proxy: "http://commonwell.test/",
                        port: 3200,
                        notify: true,
                        watchTask: true
                    }
                }
            },

            // Bower task sets up require config
            bower: {
                all: {
                    rjsConfig: 'scripts/global.js'
                }
            },

            // Require config
            requirejs: {
                production: {
                    options: {
                        name: 'global',
                        baseUrl: 'scripts',
                        mainConfigFile: 'scripts/global.js',
                        out: 'scripts/optimized.min.js'
                    }
                }
            },

            uglify: {
                dist: uglifyFiles
            },

            // Image min
            imagemin: {
                production: {
                    files: [
                        {
                            expand: true,
                            cwd: 'images',
                            src: '**/*.{png,jpg,jpeg}',
                            dest: 'images'
                        }
                    ]
                }
            },

            // SVG min
            svgmin: {
                production: {
                    files: [
                        {
                            expand: true,
                            cwd: 'images',
                            src: '**/*.svg',
                            dest: 'images'
                        }
                    ]
                }
            },

            tenon: {
                options: {
                    key: '396222b2a0eb802ac222d58feba8786e',
                    filter: [31, 54],
                    level: 'AA'
                },
                all: {
                    options: {
                        saveOutputIn: 'allHtml.json',
                        snippet: true,
                        asyncLim: 2
                    },
                    src: ['../../cache/page_enhanced/commonwell-corp.dev/**.html']
                },
                index: {
                    src: [
                        '../../cache/page_enhanced/commonwell-corp.dev/_index_ssl.html'
                    ]
                }
            }

        }
    );

    // Default task
    grunt.registerTask('default', ['browserSync', 'watch']);

    // tenon task
    grunt.registerTask('tenon', 'tenon');

    // Build task
    grunt.registerTask(
        'build', [
            'jshint',
            'sass:production',
            'imagemin:production',
            'svgmin:production',
            'requirejs:production',
            'uglify'
        ]
    );

    // Template Setup Task
    grunt.registerTask('setup', ['sass:dev', 'bower-install']);

    // Wtach Task
    grunt.registerTask('watch', ['regarde', 'requirejs:production']);

    // Load up tasks
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    // grunt.loadNpmTasks('grunt-contrib-livereload');
    grunt.loadNpmTasks('grunt-regarde');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-bower-requirejs');
    grunt.loadNpmTasks('grunt-contrib-requirejs');
    grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-svgmin');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-tenon-client');
    grunt.loadNpmTasks('grunt-browser-sync');

    // Run bower install
    grunt.registerTask(
        'bower-install', function () {
            var done = this.async();
            var bower = require('bower').commands;
            bower.install().on(
                'end', function (data) {
                    done();
                }
            ).on(
                'data', function (data) {
                    console.log(data);
                }
            ).on(
                'error', function (err) {
                    console.error(err);
                    done();
                }
            );
        }
    );

};