<commit_before>/*
 * This gruntfile is based on the project-gruntfile found at:
 *  https://github.com/Breinify/brein-javascript/tree/master/grunt/project-gruntfile.js
 *
 * The following dependencies have to be added:
 *  "grunt": "^0.4.5",
 *  "grunt-bower-install-simple": "^1.2.1",
 *  "grunt-contrib-clean": "^1.0.0",
 *  "grunt-contrib-concat": "^1.0.0",
 *  "grunt-contrib-connect": "^1.0.1",
 *  "grunt-contrib-copy": "^1.0.0",
 *  "grunt-contrib-jasmine": "^1.0.0",
 *  "grunt-contrib-uglify": "^1.0.1",
 *  "grunt-contrib-watch": "^1.0.0",
 *  "grunt-string-replace": "^1.2.1",
 *  "main-bower-files": "^2.11.1"
 *
 * Template Version: 1.0.2
 *
 * Change Log:
 *
 * 1.0.2
 *  - added possibility to define a port for the server
 *  - added replacement of placeholders in JavaScripts ({{PROJECT.VERSION}})
 *  - added a first taste of Jasmine
 *  - added a default-layout
 *
 * 1.0.1
 *  - added a file checking dependency for bower_components
 *  - added this header, i.e. versions without this header are based on 1.0.0
 *
 * 1.0.0
 *  - first release
 */
module.exports = function (grunt) {

    /*
     * Configuration settings
     */
    var defaultPort = 20000;
    var banner = '/*\n' +
        ' * ' + '<%= pkg.name %>\n' +
        ' * ' + 'v<%= pkg.version %>\n' +
        ' **/\n';
    var bowerPaths = {
        bowerDirectory: 'bower_components',
        bowerrc: '.bowerrc',
        bowerJson: 'bower.json'
    };

    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('main-bower-files');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-copy');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-bower-install-simple');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-clean');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-connect');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-watch');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-concat');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-uglify');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-string-replace');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-sync-json');

    //noinspection JSUnresolvedFunction
    grunt.initConfig({

        /*
         * Store the project settings from the package.json file into the pkg property.
         * This allows us to refer to the values of properties within our package.json
         * file: <%= pkg.name %>.
         */
        pkg: grunt.file.readJSON('package.json'),

        'sync-json': {
            'options': {
                'indent': 2,
                'include': [
                    'name',
                    'description',
                    'version',
                    'author as authors'
                ]
            },
            bower: {
                files: {
                    'bower.json': 'package.json'
                }
            }
        },

        /*
         * For some tasks, we want to clean up a little.
         */
        clean: {

            /*
             * In the case of dependencies, we have to remove all the dependencies.
             * In addition, the important files will be copied to target/dep. Thus,
             * we clean this as well.
             */
            dep: [
                'target/dep',
                'bower_components'
            ],
            combine: [
                'target/replaced',
                'target/combined'
            ],
            /*
             * In the case of distribution, we have to remove the distributed stuff.
             */
            dist: [
                'target/combined',
                'dist'
            ],
            setup: [
                'target/root'
            ]
        },

        /*
         * The watch tasks observes changes on the file-system, which
         * allow us to see changes directly in the browser.
         */
        watch: {
            server: {
                options: {
                    livereload: true,

                    /*
                     * See documentation: Setting this option to false speeds
                     * up the reaction time of the watch (usually 500ms faster
                     * for most)
                     */
                    spawn: false
                },

                // define the task to run when a change happens
                tasks: ['setup'],

                // files to observe, can be an array
                files: ['src/**/*', 'sample/**/*']
            }
        },

        /*
         * The connect task starts a web server for us to see our results and
         * do some testing.
         */
        connect: {
            server: {
                options: {
                    port: '<%= server.port %>',
                    base: 'target/root'
                    // we don't need any livereload because we have watch
                    // livereload: true
                }
            }
        },

        /*
         * Task used to install bower dependencies.
         */
        'bower-install-simple': {
            dep: {
                options: {
                    production: false
                }
            }
        },

        /*
         * Modify the bower dependencies and move the needed files to the
         * target location.
         */
        bower: {
            dep: {
                options: {
                    includeDev: true,
                    checkExistence: true,
                    paths: bowerPaths,
                    overrides: {
                        'brein-util': {'main': 'common/dist/brein-util-common.js'},
                        'cryptojslib': {
                            'main': [
                                'components/core.js',

                                // base64 encoding
                                'components/enc-base64.js',

                                // 'rollups/md5.js',
                                'components/md5.js',

                                // 'rollups/hmac-sha256.js'
                                'components/sha256.js',
                                'components/hmac.js'
                            ]
                        },
                        'jstz': {'main': 'jstz.js'}
                    }
                },
                dest: 'target/dep'
            },
            setup: {
                options: {
                    includeDev: true,
                    checkExistence: true,
                    paths: bowerPaths,
                    overrides: {
                        'brein-util': {'main': 'grunt/default-layout/**/*'},
                        'cryptojslib': {'ignore': true},
                        'jquery': {'ignore': true},
                        'jstz': {'ignore': true}
                    }
                },
                base: bowerPaths.bowerDirectory + '/brein-util/grunt/default-layout',
                dest: 'target/root'
            }
        },

        /*
         * Task used to replace specific placeholders.
         */
        'string-replace': {
            combine: {
                files: [{
                    expand: true, cwd: 'src/', src: '**/*.js', dest: 'target/replaced'
                }],
                options: {
                    replacements: [
                        {pattern: '{{PROJECT.VERSION}}', replacement: '<%= pkg.version %>'}
                    ]
                }
            }
        },

        /*
         * Task is used to combine the source files and dependencies into one file.
         */
        concat: {
            combine: {
                options: {
                    separator: ';\n',
                    banner: banner
                },
                files: [{
                    src: [
                        'src/snippets/prefix-global.js.snippet',
                        'target/dep/jquery.js',

                        'target/dep/core.js',
                        'target/dep/enc-base64.js',
                        'target/dep/md5.js',
                        'target/dep/sha256.js',
                        'target/dep/hmac.js',

                        'target/dep/jstz.js',

                        'src/snippets/disable-global-jquery.js.snippet',
                        'src/snippets/prefix-replace-window.js.snippet',
                        'target/dep/**/*.js',
                        'src/snippets/suffix-replace-window.js.snippet',
                        'target/replaced/AttributeCollection.js',
                        'target/replaced/BreinifyUtil.js',
                        'target/replaced/BreinifyConfig.js',
                        'target/replaced/BreinifyUser.js',
                        'target/replaced/**/*.js',
                        'src/snippets/suffix-global.js.snippet'
                    ],
                    dest: 'target/combined/<%= pkg.name %>.js'
                }]
            }
        },

        /*
         * Task is used to uglify the combined file to create a single file.
         */
        uglify: {
            combine: {
                options: {
                    banner: banner
                },
                files: {
                    'target/combined/<%= pkg.name %>.min.js': 'target/combined/<%= pkg.name %>.js'
                }
            }
        },

        /*
         * Copies the files into the right location for the web server.
         */
        copy: {
            setup: {
                files: [
                    {expand: true, cwd: 'dist', src: '**/<%= pkg.name %>.js', dest: 'target/root/js'},
                    {expand: true, cwd: 'dist', src: '**/<%= pkg.name %>.min.js', dest: 'target/root/js'},
                    {expand: true, cwd: 'sample', src: '**', dest: 'target/root'}
                ]
            },
            dist: {
                files: [
                    {expand: true, cwd: 'target/combined', src: '**/*.js', dest: 'dist'}
                ]
            }
        },

        /*
         * Task to test stuff with Jasmine
         */
        jasmine: {
            test: {
                src: ['dist/<%= pkg.name %>.js'],
                options: {
                    specs: ['specs/**/*.js', '!specs/**/*.jquery.js']
                }
            },
            testWithJQuery: {
                src: ['dist/<%= pkg.name %>.js'],
                options: {
                    vendor: ['node_modules/jquery/dist/jquery.js', 'node_modules/jasmine-jquery/lib/jasmine-jquery.js'],
                    specs: 'specs/**/*.jquery.js'
                }
            }
        }
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('server', 'Start the web-server for fast debugging.', function (port) {
        port = typeof port === 'undefined' || port === null || isNaN(parseFloat(port)) || !isFinite(port) ? defaultPort : parseInt(port);

        grunt.config.set('server.port', port);
        grunt.log.writeln('Starting web server on port ' + port + '...');

        //noinspection JSUnresolvedVariable
        grunt.task.run('setup', 'connect:server', 'watch:server');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('createBowerDir', 'Creates the needed bower directory', function () {

        //noinspection JSUnresolvedFunction
        grunt.file.mkdir(bowerPaths.bowerDirectory);
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('dep', 'Resolves the dependencies used by bower.', function (clean) {
        clean = typeof clean === 'string' && 'true' === clean.toLowerCase();

        var tasks = [];
        if (clean) {
            tasks.push('clean:dep');
            tasks.push('createBowerDir');
        }
        tasks.push('sync-json:bower');
        tasks.push('bower-install-simple:dep');
        tasks.push('bower:dep');

        //noinspection JSUnresolvedVariable
        grunt.task.run(tasks);
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('combine', 'Combines the files (i.e., combines and uglifies)', function (uglify) {
        uglify = typeof uglify === 'string' && 'true' === uglify.toLowerCase();

        var tasks = [];
        tasks.push('dep:false');
        tasks.push('string-replace:combine');
        tasks.push('concat:combine');
        if (uglify) tasks.push('uglify:combine');

        //noinspection JSUnresolvedVariable
        grunt.task.run(tasks);
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('dist', 'Distributes the file for deployment', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('clean:combine', 'clean:dist', 'combine:true', 'copy:dist');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('setup', 'Updates the files for the web server', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('clean:setup', 'combine:false', 'createBowerDir', 'bower:setup', 'dist', 'copy:setup');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('test', 'Tests the files using Jasmine', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('dist', 'jasmine:test', 'jasmine:testWithJQuery');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('publish', 'Publishes the package to npm', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('dist', 'jasmine:test', 'jasmine:testWithJQuery');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('help', 'Help output regarding the tasks', function () {
        console.log('Usage:');
        console.log(' - grunt server<port> : to start a web server on the defined port (default: ' + defaultPort + '); auto refresh is enabled');
        console.log(' - grunt setup        : updates the current version of the web server');
        console.log(' - grunt dep:<bool>   : to resolve dependencies; true to clean up dependencies, otherwise false (default)');
        console.log(' - grunt dist:<bool>  : distributes the files of the project; true to uglify the files, otherwise false (default)');
        console.log(' - grunt test         : to run the defined tests');
    });

    /*
     * Notes when deploying new version:
     *  -> check version in package.json to be sure (you'll get a warning if it's wrong)
     *  -> grunt dist:true
     *  -> npm publish
     *  -> github (create a new release)
     */
};<commit_msg>removed common from gruntfile<commit_after>/*
 * This gruntfile is based on the project-gruntfile found at:
 *  https://github.com/Breinify/brein-javascript/tree/master/grunt/project-gruntfile.js
 *
 * The following dependencies have to be added:
 *  "grunt": "^0.4.5",
 *  "grunt-bower-install-simple": "^1.2.1",
 *  "grunt-contrib-clean": "^1.0.0",
 *  "grunt-contrib-concat": "^1.0.0",
 *  "grunt-contrib-connect": "^1.0.1",
 *  "grunt-contrib-copy": "^1.0.0",
 *  "grunt-contrib-jasmine": "^1.0.0",
 *  "grunt-contrib-uglify": "^1.0.1",
 *  "grunt-contrib-watch": "^1.0.0",
 *  "grunt-string-replace": "^1.2.1",
 *  "main-bower-files": "^2.11.1"
 *
 * Template Version: 1.0.2
 *
 * Change Log:
 *
 * 1.0.2
 *  - added possibility to define a port for the server
 *  - added replacement of placeholders in JavaScripts ({{PROJECT.VERSION}})
 *  - added a first taste of Jasmine
 *  - added a default-layout
 *
 * 1.0.1
 *  - added a file checking dependency for bower_components
 *  - added this header, i.e. versions without this header are based on 1.0.0
 *
 * 1.0.0
 *  - first release
 */
module.exports = function (grunt) {

    /*
     * Configuration settings
     */
    var defaultPort = 20000;
    var banner = '/*\n' +
        ' * ' + '<%= pkg.name %>\n' +
        ' * ' + 'v<%= pkg.version %>\n' +
        ' **/\n';
    var bowerPaths = {
        bowerDirectory: 'bower_components',
        bowerrc: '.bowerrc',
        bowerJson: 'bower.json'
    };

    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('main-bower-files');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-copy');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-bower-install-simple');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-clean');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-connect');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-watch');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-concat');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-uglify');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-string-replace');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    //noinspection JSUnresolvedFunction
    grunt.loadNpmTasks('grunt-sync-json');

    //noinspection JSUnresolvedFunction
    grunt.initConfig({

        /*
         * Store the project settings from the package.json file into the pkg property.
         * This allows us to refer to the values of properties within our package.json
         * file: <%= pkg.name %>.
         */
        pkg: grunt.file.readJSON('package.json'),

        'sync-json': {
            'options': {
                'indent': 2,
                'include': [
                    'name',
                    'description',
                    'version',
                    'author as authors'
                ]
            },
            bower: {
                files: {
                    'bower.json': 'package.json'
                }
            }
        },

        /*
         * For some tasks, we want to clean up a little.
         */
        clean: {

            /*
             * In the case of dependencies, we have to remove all the dependencies.
             * In addition, the important files will be copied to target/dep. Thus,
             * we clean this as well.
             */
            dep: [
                'target/dep',
                'bower_components'
            ],
            combine: [
                'target/replaced',
                'target/combined'
            ],
            /*
             * In the case of distribution, we have to remove the distributed stuff.
             */
            dist: [
                'target/combined',
                'dist'
            ],
            setup: [
                'target/root'
            ]
        },

        /*
         * The watch tasks observes changes on the file-system, which
         * allow us to see changes directly in the browser.
         */
        watch: {
            server: {
                options: {
                    livereload: true,

                    /*
                     * See documentation: Setting this option to false speeds
                     * up the reaction time of the watch (usually 500ms faster
                     * for most)
                     */
                    spawn: false
                },

                // define the task to run when a change happens
                tasks: ['setup'],

                // files to observe, can be an array
                files: ['src/**/*', 'sample/**/*']
            }
        },

        /*
         * The connect task starts a web server for us to see our results and
         * do some testing.
         */
        connect: {
            server: {
                options: {
                    port: '<%= server.port %>',
                    base: 'target/root'
                    // we don't need any livereload because we have watch
                    // livereload: true
                }
            }
        },

        /*
         * Task used to install bower dependencies.
         */
        'bower-install-simple': {
            dep: {
                options: {
                    production: false
                }
            }
        },

        /*
         * Modify the bower dependencies and move the needed files to the
         * target location.
         */
        bower: {
            dep: {
                options: {
                    includeDev: true,
                    checkExistence: true,
                    paths: bowerPaths,
                    overrides: {
                        'cryptojslib': {
                            'main': [
                                'components/core.js',

                                // base64 encoding
                                'components/enc-base64.js',

                                // 'rollups/md5.js',
                                'components/md5.js',

                                // 'rollups/hmac-sha256.js'
                                'components/sha256.js',
                                'components/hmac.js'
                            ]
                        },
                        'jstz': {'main': 'jstz.js'}
                    }
                },
                dest: 'target/dep'
            },
            setup: {
                options: {
                    includeDev: true,
                    checkExistence: true,
                    paths: bowerPaths,
                    overrides: {
                        'brein-util': {'main': 'grunt/default-layout/**/*'},
                        'cryptojslib': {'ignore': true},
                        'jquery': {'ignore': true},
                        'jstz': {'ignore': true}
                    }
                },
                base: bowerPaths.bowerDirectory + '/brein-util/grunt/default-layout',
                dest: 'target/root'
            }
        },

        /*
         * Task used to replace specific placeholders.
         */
        'string-replace': {
            combine: {
                files: [{
                    expand: true, cwd: 'src/', src: '**/*.js', dest: 'target/replaced'
                }],
                options: {
                    replacements: [
                        {pattern: '{{PROJECT.VERSION}}', replacement: '<%= pkg.version %>'}
                    ]
                }
            }
        },

        /*
         * Task is used to combine the source files and dependencies into one file.
         */
        concat: {
            combine: {
                options: {
                    separator: ';\n',
                    banner: banner
                },
                files: [{
                    src: [
                        'src/snippets/prefix-global.js.snippet',
                        'target/dep/jquery.js',

                        'target/dep/core.js',
                        'target/dep/enc-base64.js',
                        'target/dep/md5.js',
                        'target/dep/sha256.js',
                        'target/dep/hmac.js',

                        'target/dep/jstz.js',

                        'src/snippets/disable-global-jquery.js.snippet',
                        'src/snippets/prefix-replace-window.js.snippet',
                        'target/dep/**/*.js',
                        'src/snippets/suffix-replace-window.js.snippet',
                        'target/replaced/AttributeCollection.js',
                        'target/replaced/BreinifyUtil.js',
                        'target/replaced/BreinifyConfig.js',
                        'target/replaced/BreinifyUser.js',
                        'target/replaced/**/*.js',
                        'src/snippets/suffix-global.js.snippet'
                    ],
                    dest: 'target/combined/<%= pkg.name %>.js'
                }]
            }
        },

        /*
         * Task is used to uglify the combined file to create a single file.
         */
        uglify: {
            combine: {
                options: {
                    banner: banner
                },
                files: {
                    'target/combined/<%= pkg.name %>.min.js': 'target/combined/<%= pkg.name %>.js'
                }
            }
        },

        /*
         * Copies the files into the right location for the web server.
         */
        copy: {
            setup: {
                files: [
                    {expand: true, cwd: 'dist', src: '**/<%= pkg.name %>.js', dest: 'target/root/js'},
                    {expand: true, cwd: 'dist', src: '**/<%= pkg.name %>.min.js', dest: 'target/root/js'},
                    {expand: true, cwd: 'sample', src: '**', dest: 'target/root'}
                ]
            },
            dist: {
                files: [
                    {expand: true, cwd: 'target/combined', src: '**/*.js', dest: 'dist'}
                ]
            }
        },

        /*
         * Task to test stuff with Jasmine
         */
        jasmine: {
            test: {
                src: ['dist/<%= pkg.name %>.js'],
                options: {
                    specs: ['specs/**/*.js', '!specs/**/*.jquery.js']
                }
            },
            testWithJQuery: {
                src: ['dist/<%= pkg.name %>.js'],
                options: {
                    vendor: ['node_modules/jquery/dist/jquery.js', 'node_modules/jasmine-jquery/lib/jasmine-jquery.js'],
                    specs: 'specs/**/*.jquery.js'
                }
            }
        }
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('server', 'Start the web-server for fast debugging.', function (port) {
        port = typeof port === 'undefined' || port === null || isNaN(parseFloat(port)) || !isFinite(port) ? defaultPort : parseInt(port);

        grunt.config.set('server.port', port);
        grunt.log.writeln('Starting web server on port ' + port + '...');

        //noinspection JSUnresolvedVariable
        grunt.task.run('setup', 'connect:server', 'watch:server');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('createBowerDir', 'Creates the needed bower directory', function () {

        //noinspection JSUnresolvedFunction
        grunt.file.mkdir(bowerPaths.bowerDirectory);
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('dep', 'Resolves the dependencies used by bower.', function (clean) {
        clean = typeof clean === 'string' && 'true' === clean.toLowerCase();

        var tasks = [];
        if (clean) {
            tasks.push('clean:dep');
            tasks.push('createBowerDir');
        }
        tasks.push('sync-json:bower');
        tasks.push('bower-install-simple:dep');
        tasks.push('bower:dep');

        //noinspection JSUnresolvedVariable
        grunt.task.run(tasks);
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('combine', 'Combines the files (i.e., combines and uglifies)', function (uglify) {
        uglify = typeof uglify === 'string' && 'true' === uglify.toLowerCase();

        var tasks = [];
        tasks.push('dep:false');
        tasks.push('string-replace:combine');
        tasks.push('concat:combine');
        if (uglify) tasks.push('uglify:combine');

        //noinspection JSUnresolvedVariable
        grunt.task.run(tasks);
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('dist', 'Distributes the file for deployment', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('clean:combine', 'clean:dist', 'combine:true', 'copy:dist');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('setup', 'Updates the files for the web server', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('clean:setup', 'combine:false', 'createBowerDir', 'bower:setup', 'dist', 'copy:setup');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('test', 'Tests the files using Jasmine', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('dist', 'jasmine:test', 'jasmine:testWithJQuery');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('publish', 'Publishes the package to npm', function () {

        //noinspection JSUnresolvedVariable
        grunt.task.run('dist', 'jasmine:test', 'jasmine:testWithJQuery');
    });

    //noinspection JSUnresolvedFunction
    grunt.registerTask('help', 'Help output regarding the tasks', function () {
        console.log('Usage:');
        console.log(' - grunt server<port> : to start a web server on the defined port (default: ' + defaultPort + '); auto refresh is enabled');
        console.log(' - grunt setup        : updates the current version of the web server');
        console.log(' - grunt dep:<bool>   : to resolve dependencies; true to clean up dependencies, otherwise false (default)');
        console.log(' - grunt dist:<bool>  : distributes the files of the project; true to uglify the files, otherwise false (default)');
        console.log(' - grunt test         : to run the defined tests');
    });

    /*
     * Notes when deploying new version:
     *  -> check version in package.json to be sure (you'll get a warning if it's wrong)
     *  -> grunt dist:true
     *  -> npm publish
     *  -> github (create a new release)
     */
};<|endoftext|>


<commit_before>module.exports = function (grunt) {

  require('load-grunt-tasks')(grunt);
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    eslint: {
      target: ['Gruntfile.js', 'lib/**/*.js', 'routes/**/*/js', 'public/javascripts/*.js', 'test/**/*.js']
    },
    mochaTest: {
      test: {
        options: {
          reporter: 'spec'
        },
        src: ['test/**/*.js']
      }
    },
    shell: {
      options: {
        stderr: false
      },
      puglint: {
        command: './node_modules/pug-lint/bin/pug-lint ./views/*.pug ./views/client-side/*.pug'
      }
    }
  });

  grunt.registerTask('test', ['mochaTest']);
  grunt.registerTask('puglint', ['shell:puglint']);
  grunt.registerTask('eslint', ['eslint']);
  grunt.registerTask('default', ['puglint', 'eslint']);

};
<commit_msg>fix eslint<commit_after>module.exports = function (grunt) {

  require('load-grunt-tasks')(grunt);
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    eslint: {
      target: ['gruntfile.js', 'lib/**/*.js', 'routes/**/*.js', 'public/javascripts/*.js', 'test/**/*.js']
    },
    mochaTest: {
      test: {
        options: {
          reporter: 'spec'
        },
        src: ['test/**/*.js']
      }
    },
    shell: {
      options: {
        stderr: false
      },
      puglint: {
        command: './node_modules/pug-lint/bin/pug-lint ./views/*.pug ./views/client-side/*.pug'
      }
    }
  });

  grunt.registerTask('test', ['mochaTest']);
  grunt.registerTask('puglint', ['shell:puglint']);
  grunt.registerTask('default', ['puglint', 'eslint']);
};
<|endoftext|>


<commit_before>"use strict";
/*jshint node: true*/
/*eslint-env node*/
/*eslint-disable no-sync*/

// https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md#2017-10-24-version-880-current-mylesborins
process.env.NODE_NO_HTTP2 = 1; //eslint-disable-line no-process-env

module.exports = function (grunt) {

    require("time-grunt")(grunt);

    // Since the tasks are split using load-grunt-config, a global object contains the configuration
    /*global configFile, configuration*/
    var ConfigFile = require("./make/configFile.js");
    global.configFile = new ConfigFile(true);
    global.configuration = Object.create(configFile.content);
    if (configFile.isNew()) {
        require("fs").readdirSync("./grunt/config").forEach(function (fileName) {
            grunt.registerTask(fileName.split(".")[0], require("./grunt/config/" + fileName)(grunt));
        });
        return;
    }

    // Amend the configuration with internal settings
    configuration.pkg = grunt.file.readJSON("./package.json");

    // As well as known path
    configuration.path = {
        plato: "tmp/plato/"
    };

    require("load-grunt-config")(grunt);
    grunt.task.loadTasks("grunt/tasks");

};
<commit_msg>no-magic-numbers (#280)<commit_after>"use strict";
/*jshint node: true*/
/*eslint-env node*/
/*eslint-disable no-sync*/

// https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md#2017-10-24-version-880-current-mylesborins
process.env.NODE_NO_HTTP2 = 1; //eslint-disable-line no-process-env

module.exports = function (grunt) {

    require("time-grunt")(grunt);

    // Since the tasks are split using load-grunt-config, a global object contains the configuration
    /*global configFile, configuration*/
    var ConfigFile = require("./make/configFile.js");
    global.configFile = new ConfigFile(true);
    global.configuration = Object.create(configFile.content);
    if (configFile.isNew()) {
        require("fs").readdirSync("./grunt/config").forEach(function (fileName) {
            var from = 0,
                to = fileName.lastIndexOf(".");
            grunt.registerTask(fileName.substring(from, to), require("./grunt/config/" + fileName)(grunt));
        });
        return;
    }

    // Amend the configuration with internal settings
    configuration.pkg = grunt.file.readJSON("./package.json");

    // As well as known path
    configuration.path = {
        plato: "tmp/plato/"
    };

    require("load-grunt-config")(grunt);
    grunt.task.loadTasks("grunt/tasks");

};
<|endoftext|>


<commit_before>//  gruntfile.js
//
// Author: blinklv <blinklv@icloud.com>
// Create Time: 2017-03-22
// Maintainer: blinklv <blinklv@icloud.com>
// Last Change: 2018-06-05
//
// The gruntfile.js for my Web development.  Many settings are personalized for me, but
// how it works I will explain in README.md file.  So If you like it, you can copy this
// file (grunfile.js) and package.json file to your project. I left many tips in comments,
// which can help me to configure this file :)

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        // Project metadata is imported into the Grunt config from the project's package.json.
        pkg: grunt.file.readJSON("package.json"),

        // Configure task-named properties. When a task is run, Grunt looks for
        // its configuration under a property of the same name.
        // NOTE: This anonymous object may contain any arbitrary data. As long as
        // properties don't conflict with properties the tasks require, they will
        // be otherwise ignored.

        copy: {
            // Multi-tasks can hae multiple configurations. The copy task
            // has devel and release targets. Specifying both a task and
            // target like 'grunt copy:devel' or 'grunt copy:release' will
            // process just the specified target's configuration, while
            // running 'grunt copy' will iterate over all targets.
            devel: {
                // Copy files from the working directory and its subdirectory to build/devel
                // directory. (build is a subdirectory of your working directory)
            },
            release: {
            }
        },

        responsive_images: {
            // An options property may be specified to override built-in defaults.
            // In addition, each target may have an options property which is specific
            // to that target. Target-level options will override task-level options.
            options: {
                // Chooses which graphics engine to use when resizing images. To use
                // GraphicsMagick, set this to 'gm'. To use ImageMagick, set this to
                // 'im'.
                engine: "im",

                // Only process files that do not already exist in the destination directory.
                newFilesOnly: true,

                // An array of objects containing the sizes and settings we want to resize
                // our image to.
                sizes: [{
                    // If a name is specified, then the file will be suffixed with this name.
                    // eg: my-image-s.jpg, your-image-xl.png.
                    name: "s",
                    width: 320,

                    // JPEG format only. The quality of the image, 100 being the highest
                    // quality and 1 being the lowest.
                    quality: 70
                },{
                    name: "m",
                    width: 480,
                    quality: 70
                },{
                    name: "l",
                    width: 720,
                    quality: 70
                },{
                    name: "xl",
                    width: 1024,
                    quality: 70
                },{
                    name: "xxl",
                    width: 1440,
                    quality: 70
                }]
            },

            files: {
                // Handle all specified format images in the 'img/' subdirectory and all
                // of its subdirectories. Move the results to 'build/devel/img/' dir.
                src: ["img/**/*.{jpg,jpeg,png,gif,webp}"],
                dest: "build/devel/img/"
            }
        },
    });

    grunt.loadNpmTasks("grunt-contrib-copy");
    grunt.loadNpmTasks("grunt-responsive-images");
};

<commit_msg>Update copy:devel.<commit_after>//  gruntfile.js
//
// Author: blinklv <blinklv@icloud.com>
// Create Time: 2017-03-22
// Maintainer: blinklv <blinklv@icloud.com>
// Last Change: 2018-06-05
//
// The gruntfile.js for my Web development.  Many settings are personalized for me, but
// how it works I will explain in README.md file.  So If you like it, you can copy this
// file (grunfile.js) and package.json file to your project. I left many tips in comments,
// which can help me to configure this file :)

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        // Project metadata is imported into the Grunt config from the project's package.json.
        pkg: grunt.file.readJSON("package.json"),

        // Configure task-named properties. When a task is run, Grunt looks for
        // its configuration under a property of the same name.
        // NOTE: This anonymous object may contain any arbitrary data. As long as
        // properties don't conflict with properties the tasks require, they will
        // be otherwise ignored.

        copy: {
            // Multi-tasks can hae multiple configurations. The copy task
            // has devel and release targets. Specifying both a task and
            // target like 'grunt copy:devel' or 'grunt copy:release' will
            // process just the specified target's configuration, while
            // running 'grunt copy' will iterate over all targets.
            devel: {
                // Copy files from the working directory and its subdirectory to build/devel
                // directory. (build is a subdirectory of your working directory)
                src: [
                    "index.html", "html/**/*.html",
                    "css/**/*.{css,css.map}", "!css/**/*.min.css",
                    "js/**/*.js", "!js/**/*.min.js",
                    "font/**/*.{woff,woff2,eot,ttf,otf,svg}",
                    // For bitmap, we need to resize and compress them. But for vector
                    // images, we copy them to the destination directory directly.
                    "img/**/*.svg",

                    // Because the vendor directory contains third party resources. It's
                    // hard to control their content, so the current strategy is copying
                    // almost all files (except for some compress files) to the dest.
                    "vendor/**", "!vendor/**/*.min.*"
                ],
                dest: "build/devel/"
            },
            release: {
            }
        },

        responsive_images: {
            // An options property may be specified to override built-in defaults.
            // In addition, each target may have an options property which is specific
            // to that target. Target-level options will override task-level options.
            options: {
                // Chooses which graphics engine to use when resizing images. To use
                // GraphicsMagick, set this to 'gm'. To use ImageMagick, set this to
                // 'im'.
                engine: "im",

                // Only process files that do not already exist in the destination directory.
                newFilesOnly: true,

                // An array of objects containing the sizes and settings we want to resize
                // our image to.
                sizes: [{
                    // If a name is specified, then the file will be suffixed with this name.
                    // eg: my-image-s.jpg, your-image-xl.png.
                    name: "s",
                    width: 320,

                    // JPEG format only. The quality of the image, 100 being the highest
                    // quality and 1 being the lowest.
                    quality: 70
                },{
                    name: "m",
                    width: 480,
                    quality: 70
                },{
                    name: "l",
                    width: 720,
                    quality: 70
                },{
                    name: "xl",
                    width: 1024,
                    quality: 70
                },{
                    name: "xxl",
                    width: 1440,
                    quality: 70
                }]
            },

            files: {
                // Handle all specified format images in the 'img/' subdirectory and all
                // of its subdirectories. Move the results to 'build/devel/img/' dir.
                src: "img/**/*.{jpg,jpeg,png,gif,webp}",
                dest: "build/devel/"
            }
        },
    });

    grunt.loadNpmTasks("grunt-contrib-copy");
    grunt.loadNpmTasks("grunt-responsive-images");
};

<|endoftext|>


<commit_before>module.exports = function(grunt) {

	// To support SASS/SCSS or Stylus, just install
	// the appropriate grunt package and it will be automatically included
	// in the build process, Sass is included by default:
	//
	// * for SASS/SCSS support, run `npm install --save-dev grunt-contrib-sass`
	// * for Stylus/Nib support, `npm install --save-dev grunt-contrib-stylus`

	var npmDependencies = require('./package.json').devDependencies;
	var hasSass = npmDependencies['grunt-sass'] !== undefined;
	var environment = "james";

	if (environment == "james") {
		grunt.initConfig({

			path: {
				assets: 'assets',
				src: 'src',
				dist: 'dist',
				sass: '<%= path.assets %>/css',
				js: '<%= path.assets %>/js',
				images: '<%= path.assets %>/images',
				fonts: '<%= path.assets %>/fonts',
			},

			// Watches for changes and runs tasks
			watch : {
				sass : {
					files : ['assets/css/**/*.scss'],
					tasks : (hasSass) ? ['sass:dev', 'autoprefixer'] : null,
					options : {
						livereload : true
					}
				},
				js : {
					files : ['assets/js/**/*.js'],
					tasks : ['jshint'],
					options : {
						livereload : true
					}
				},
				php : {
					files : ['**/*.php'],
					options : {
						livereload : true
					}
				}
			},

			// JsHint your javascript
			jshint : {
				all : ['js/*.js', '!js/modernizr.js', '!js/*.min.js', '!js/vendor/**/*.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 : 'assets/css',
							dest : 'dist/css',
							ext : '.css',
							expand : true
						}
					],
					options : {
						style : 'compressed'
					}
				},
				dev : {
					files : [
						{
							src : ['**/*.scss', '!**/_*.scss'],
							cwd : 'assets/css',
							dest : 'dist/css',
							ext : '.css',
							expand : true
						}
					],
					options : {
						style : 'expanded'
					}
				}
			},

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

			// SVG min
			svgmin: {
				options: {
					plugins: [{
						removeViewBox: false
					}]
				},
				dist: {
					files: [{
						expand: true,
						cwd: '<%= path.images %>',
						src: ['*.svg'],
						dest: '<%= path.dist %>/images',
						ext: '.svg'
					}]
				}
			},

			grunticon: {
				icons: {
					files: [{
						expand: true,
						cwd: '<%= path.images %>',
						src : ['*.svg'],
						dest: '<%= path.dist %>/images'
					}],
					options: {
						cssprefix: '.icon--'
					}
				}
			},

			// Minify JS
			uglify: {
				js: {
					files: [
					{
						expand:true,
						cwd: 'assets/js',
						src: ['**/*.js'],
						dest: 'dist/js'
					}]
				}
			},

			// Concat JS
			concat: {
				dist: {
					src: ['dist/js/!(global).js'],
					dest: 'dist/js/global.js',
				}
			},

			// Autoprefixer
			autoprefixer: {
				single_file: {
					flatten : true,
					src: 'dist/css/style.css',
					dest: 'dist/css/style.css'
				}
			},

			// Modernizr build
			modernizr: {

			    dist: {
			        // [REQUIRED] Path to the build you're using for development.
			        "devFile" : "bower_components/modernizr/modernizr.js",

			        // Path to save out the built file.
			        "outputFile" : "assets/js/modernizr-custom.js",

			        // Based on default settings on http://modernizr.com/download/
			        "extra" : {
			            "shiv" : true,
			            "printshiv" : false,
			            "load" : true,
			            "mq" : true,
			            "cssclasses" : true
			        },

			        // Based on default settings on http://modernizr.com/download/
			        "extensibility" : {
			            "addtest" : false,
			            "prefixed" : false,
			            "teststyles" : false,
			            "testprops" : false,
			            "testallprops" : false,
			            "hasevents" : false,
			            "prefixes" : false,
			            "domprefixes" : false,
			            "cssclassprefix": ""
			        },

			        // By default, source is uglified before saving
			        "uglify" : true,

			        // Define any tests you want to implicitly include.
			        "tests" : [],

			        // By default, this task will crawl your project for references to Modernizr tests.
			        // Set to false to disable.
			        "parseFiles" : true,

			        // When parseFiles = true, this task will crawl all *.js, *.css, *.scss and *.sass files,
			        // except files that are in node_modules/.
			        // You can override this by defining a "files" array below.
			        // "files" : {
			            // "src": []
			        // },

			        // This handler will be passed an array of all the test names passed to the Modernizr API, and will run after the API call has returned
			        // "handler": function (tests) {},

			        // When parseFiles = true, matchCommunityTests = true will attempt to
			        // match user-contributed tests.
			        "matchCommunityTests" : false,

			        // Have custom Modernizr tests? Add paths to their location here.
			        "customTests" : []
			    }
			},

			// Move bower components to desired directories
			bowercopy: {
			  options: {
			    srcPrefix: 'bower_components'
			  },
			  scripts: {
			    options: {
			      destPrefix: 'assets'
			    },
			    files: {
			      'js/modernizr.js': 'modernizr/modernizr.js',
			      'css/compass': 'compass-mixins/lib'
			    }
			  }
			}

		});

		// Uglify and concat
		grunt.registerTask("uglicat", ["uglify", "concat"])

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

		// Build task
		grunt.registerTask('build', function() {
			var arr = ['jshint'];

			if (hasSass) {
				arr.push('sass:production');
			}

			if (hasStylus) {
				arr.push('stylus:production');
			}

			arr.push('autoprefixer', 'imagemin:production', 'svgmin:production', 'requirejs:production', 'uglify', 'concat', 'modernizr:dist');

			return arr;
		});

		// Template Setup Task
		grunt.registerTask('setup', function() {
			var arr = [];

			if (hasSass) {
				arr.push['sass:dev'];
			}

			if (hasStylus) {
				arr.push('stylus:dev');
			}

			arr.push('bower-install');
		});

		// Load up tasks
		grunt.loadNpmTasks('grunt-sass');
		grunt.loadNpmTasks('grunt-contrib-jshint');
		grunt.loadNpmTasks('grunt-contrib-watch');
		grunt.loadNpmTasks('grunt-contrib-uglify');
		grunt.loadNpmTasks('grunt-contrib-concat');
		grunt.loadNpmTasks('grunt-contrib-imagemin');
		grunt.loadNpmTasks('grunt-svgmin');
		grunt.loadNpmTasks('grunt-autoprefixer');
		grunt.loadNpmTasks("grunt-modernizr");
		grunt.loadNpmTasks('grunt-bowercopy');
		grunt.loadNpmTasks('grunt-grunticon');

		// 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();
			});
		});

	}

	else if (environment == "steve") {

	}

};<commit_msg>Added cssmin to build task due to bug with minifying via libsass<commit_after>module.exports = function(grunt) {

	// To support SASS/SCSS or Stylus, just install
	// the appropriate grunt package and it will be automatically included
	// in the build process, Sass is included by default:
	//
	// * for SASS/SCSS support, run `npm install --save-dev grunt-contrib-sass`
	// * for Stylus/Nib support, `npm install --save-dev grunt-contrib-stylus`

	var npmDependencies = require('./package.json').devDependencies;
	var hasSass = npmDependencies['grunt-sass'] !== undefined;
	var environment = "james";

	if (environment == "james") {
		grunt.initConfig({

			path: {
				assets: 'assets',
				src: 'src',
				dist: 'dist',
				sass: '<%= path.assets %>/css',
				js: '<%= path.assets %>/js',
				images: '<%= path.assets %>/images',
				fonts: '<%= path.assets %>/fonts',
			},

			// Watches for changes and runs tasks
			watch : {
				sass : {
					files : ['<%= path.sass %>/*.scss', '<%= path.sass %>/**/*.scss'],
					tasks : (hasSass) ? ['sass:dev', 'autoprefixer'] : null,
					options : {
						livereload : true,
						sourceMap : true
					}
				},
				js : {
					files : ['assets/js/**/*.js'],
					tasks : ['jshint', 'uglicat'],
					options : {
						livereload : true
					}
				},
				php : {
					files : ['**/*.php'],
					options : {
						livereload : true
					}
				}
			},

			// JsHint your javascript
			jshint : {
				all : ['js/*.js', '!js/modernizr.js', '!js/*.min.js', '!js/vendor/**/*.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 : 'assets/css',
							dest : 'dist/css',
							ext : '.css',
							expand : true
						}
					],
					options : {
						style : 'compressed'
					}
				},
				dev : {
					files : [
						{
							src : ['**/*.scss', '!**/_*.scss'],
							cwd : 'assets/css',
							dest : 'dist/css',
							ext : '.css',
							expand : true
						}
					],
					options : {
						style : 'expanded'
					}
				}
			},

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

			// SVG min
			svgmin: {
				options: {
					plugins: [{
						removeViewBox: false,
						collapseGroups: false
					}, {
						removeUnknownsAndDefaults: false
					}]
				},
				dist: {
					files: [{
						expand: true,
						cwd: '<%= path.images %>',
						src: ['*.svg'],
						dest: '<%= path.dist %>/images',
						ext: '.svg'
					}]
				}
			},

			grunticon: {
				icons: {
					files: [{
						expand: true,
						cwd: '<%= path.images %>',
						src : ['*.svg'],
						dest: '<%= path.dist %>/images'
					}],
					options: {
						cssprefix: '.icon--'
					}
				}
			},

			// Minify JS
			uglify: {
				js: {
					files: [
					{
						expand:true,
						cwd: 'assets/js',
						src: ['**/*.js'],
						dest: 'dist/js'
					}]
				}
			},

			// Concat JS
			concat: {
				dist: {
					src: ['dist/js/!(global).js'],
					dest: 'dist/js/global.js',
				}
			},

			// Autoprefixer
			autoprefixer: {
				single_file: {
					flatten : true,
					src: 'dist/css/style.css',
					dest: 'dist/css/style.css'
				}
			},

			cssmin: {
			  options: {
			    shorthandCompacting: false,
			    roundingPrecision: -1
			  },
			  target: {
			    files: {
			      'dist/css/style.css': ['dist/css/style.css']
			    }
			  }
			},

			// Modernizr build
			modernizr: {

			    dist: {
			        // [REQUIRED] Path to the build you're using for development.
			        "devFile" : "bower_components/modernizr/modernizr.js",

			        // Path to save out the built file.
			        "outputFile" : "assets/js/modernizr-custom.js",

			        // Based on default settings on http://modernizr.com/download/
			        "extra" : {
			            "shiv" : true,
			            "printshiv" : false,
			            "load" : true,
			            "mq" : true,
			            "cssclasses" : true
			        },

			        // Based on default settings on http://modernizr.com/download/
			        "extensibility" : {
			            "addtest" : false,
			            "prefixed" : false,
			            "teststyles" : false,
			            "testprops" : false,
			            "testallprops" : false,
			            "hasevents" : false,
			            "prefixes" : false,
			            "domprefixes" : false,
			            "cssclassprefix": ""
			        },

			        // By default, source is uglified before saving
			        "uglify" : true,

			        // Define any tests you want to implicitly include.
			        "tests" : [],

			        // By default, this task will crawl your project for references to Modernizr tests.
			        // Set to false to disable.
			        "parseFiles" : true,

			        // When parseFiles = true, this task will crawl all *.js, *.css, *.scss and *.sass files,
			        // except files that are in node_modules/.
			        // You can override this by defining a "files" array below.
			        // "files" : {
			            // "src": []
			        // },

			        // This handler will be passed an array of all the test names passed to the Modernizr API, and will run after the API call has returned
			        // "handler": function (tests) {},

			        // When parseFiles = true, matchCommunityTests = true will attempt to
			        // match user-contributed tests.
			        "matchCommunityTests" : false,

			        // Have custom Modernizr tests? Add paths to their location here.
			        "customTests" : []
			    }
			},

			// Move bower components to desired directories
			bowercopy: {
			  options: {
			    srcPrefix: 'bower_components'
			  },
			  scripts: {
			    options: {
			      destPrefix: 'assets'
			    },
			    files: {
			      'js/modernizr.js': 'modernizr/modernizr.js',
			      'css/compass': 'compass-mixins/lib'
			    }
			  }
			}

		});

		// Uglify and concat
		grunt.registerTask("uglicat", ["uglify", "concat"])

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

		// Build task
		grunt.registerTask('build', function() {
			var arr = ['jshint'];

			if (hasSass) {
				arr.push('sass:production');
			}

			if (hasStylus) {
				arr.push('stylus:production');
			}

			arr.push('autoprefixer', 'cssmin', 'imagemin:production', 'svgmin:production', 'requirejs:production', 'uglify', 'concat', 'modernizr:dist');

			return arr;
		});

		// Template Setup Task
		grunt.registerTask('setup', function() {
			var arr = [];

			if (hasSass) {
				arr.push['sass:dev'];
			}

			if (hasStylus) {
				arr.push('stylus:dev');
			}

			arr.push('bower-install');
		});

		// Load up tasks
		grunt.loadNpmTasks('grunt-sass');
		grunt.loadNpmTasks('grunt-contrib-cssmin');
		grunt.loadNpmTasks('grunt-contrib-jshint');
		grunt.loadNpmTasks('grunt-contrib-watch');
		grunt.loadNpmTasks('grunt-contrib-uglify');
		grunt.loadNpmTasks('grunt-contrib-concat');
		grunt.loadNpmTasks('grunt-contrib-imagemin');
		grunt.loadNpmTasks('grunt-svgmin');
		grunt.loadNpmTasks('grunt-autoprefixer');
		grunt.loadNpmTasks("grunt-modernizr");
		grunt.loadNpmTasks('grunt-bowercopy');
		grunt.loadNpmTasks('grunt-grunticon');

		// 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();
			});
		});

	}

	else if (environment == "steve") {

	}

};<|endoftext|>


<commit_before>'use strict';

module.exports = function(grunt) {
	// Unified Watch Object
	//var watchFiles = {
	//	serverViews: ['app/views/**/*.*'],
	//	serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'],
	//	clientViews: ['public/modules/**/views/**/*.html'],
	//	clientJS: ['public/js/*.js', 'public/modules/**/*.js'],
	//	clientCSS: ['public/modules/**/*.css'],
	//	mochaTests: ['app/tests/**/*.js']
	//};

	var watchFiles = {};

	// Project Configuration
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		watch: {
			serverViews: {
				files: watchFiles.serverViews,
				options: {
					livereload: true
				}
			},
			serverJS: {
				files: watchFiles.serverJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientViews: {
				files: watchFiles.clientViews,
				options: {
					livereload: true,
				}
			},
			clientJS: {
				files: watchFiles.clientJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientCSS: {
				files: watchFiles.clientCSS,
				tasks: ['csslint'],
				options: {
					livereload: true
				}
			}
		},
		jshint: {
			all: {
				src: watchFiles.clientJS.concat(watchFiles.serverJS),
				options: {
					jshintrc: true
				}
			}
		},
		csslint: {
			options: {
				csslintrc: '.csslintrc',
			},
			all: {
				src: watchFiles.clientCSS
			}
		},
		uglify: {
			production: {
				options: {
					mangle: false
				},
				files: {
					'public/dist/application.min.js': 'public/dist/application.js'
				}
			}
		},
		cssmin: {
			combine: {
				files: {
					'public/dist/application.min.css': '<%= applicationCSSFiles %>'
				}
			}
		},
		nodemon: {
			dev: {
				script: 'server.js',
				options: {
					nodeArgs: ['--debug'],
					ext: 'js,html',
					watch: watchFiles.serverViews.concat(watchFiles.serverJS)
				}
			}
		},
		'node-inspector': {
			custom: {
				options: {
					'web-port': 1337,
					'web-host': 'localhost',
					'debug-port': 5858,
					'save-live-edit': true,
					'no-preload': true,
					'stack-trace-limit': 50,
					'hidden': []
				}
			}
		},
		ngAnnotate: {
			production: {
				files: {
					'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
				}
			}
		},
		concurrent: {
			default: ['nodemon', 'watch'],
			debug: ['nodemon', 'watch', 'node-inspector'],
			options: {
				logConcurrentOutput: true,
				limit: 10
			}
		},
		env: {
			test: {
				NODE_ENV: 'test'
			},
			secure: {
				NODE_ENV: 'secure'
			}
		},
		mochaTest: {
			src: watchFiles.mochaTests,
			options: {
				reporter: 'spec',
				require: 'server.js'
			}
		},
		karma: {
			unit: {
				configFile: 'karma.conf.js'
			}
		}
	});

	// Load NPM tasks
	require('load-grunt-tasks')(grunt);

	// Making grunt default to force in order not to break the project.
	grunt.option('force', true);

	// A Task for loading the configuration object
	grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
		var init = require('./config/init')();
		var config = require('./config/config');

		grunt.config.set('applicationJavaScriptFiles', config.assets.js);
		grunt.config.set('applicationCSSFiles', config.assets.css);
	});

	// Default task(s).
	grunt.registerTask('default', ['lint', 'concurrent:default']);

	// Debug task.
	grunt.registerTask('debug', ['lint', 'concurrent:debug']);

	// Secure task(s).
	grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']);

	// Lint task(s).
	grunt.registerTask('lint', ['jshint', 'csslint']);

	// Build task(s).
	grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);

	// Test task.
	grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};
<commit_msg>commented out file watching in gruntfile.js<commit_after>'use strict';

module.exports = function(grunt) {
	// Unified Watch Object
	var watchFiles = {
		serverViews: ['app/views/**/*.*'],
		serverJS: ['gruntfile.js'],
		clientViews: ['public/modules/**/views/**/*.html'],
		clientJS: ['public/js/*.js'],
		clientCSS: ['public/modules/**/*.css'],
		mochaTests: ['app/tests/**/*.js']
	};

	// Project Configuration
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		watch: {
			serverViews: {
				files: watchFiles.serverViews,
				options: {
					livereload: true
				}
			},
			serverJS: {
				files: watchFiles.serverJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientViews: {
				files: watchFiles.clientViews,
				options: {
					livereload: true,
				}
			},
			clientJS: {
				files: watchFiles.clientJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientCSS: {
				files: watchFiles.clientCSS,
				tasks: ['csslint'],
				options: {
					livereload: true
				}
			}
		},
		jshint: {
			all: {
				src: watchFiles.clientJS.concat(watchFiles.serverJS),
				options: {
					jshintrc: true
				}
			}
		},
		csslint: {
			options: {
				csslintrc: '.csslintrc',
			},
			all: {
				src: watchFiles.clientCSS
			}
		},
		uglify: {
			production: {
				options: {
					mangle: false
				},
				files: {
					'public/dist/application.min.js': 'public/dist/application.js'
				}
			}
		},
		cssmin: {
			combine: {
				files: {
					'public/dist/application.min.css': '<%= applicationCSSFiles %>'
				}
			}
		},
		nodemon: {
			dev: {
				script: 'server.js',
				options: {
					nodeArgs: ['--debug'],
					ext: 'js,html',
					watch: watchFiles.serverViews.concat(watchFiles.serverJS)
				}
			}
		},
		'node-inspector': {
			custom: {
				options: {
					'web-port': 1337,
					'web-host': 'localhost',
					'debug-port': 5858,
					'save-live-edit': true,
					'no-preload': true,
					'stack-trace-limit': 50,
					'hidden': []
				}
			}
		},
		ngAnnotate: {
			production: {
				files: {
					'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
				}
			}
		},
		concurrent: {
			default: ['nodemon', 'watch'],
			debug: ['nodemon', 'watch', 'node-inspector'],
			options: {
				logConcurrentOutput: true,
				limit: 10
			}
		},
		env: {
			test: {
				NODE_ENV: 'test'
			},
			secure: {
				NODE_ENV: 'secure'
			}
		},
		mochaTest: {
			src: watchFiles.mochaTests,
			options: {
				reporter: 'spec',
				require: 'server.js'
			}
		},
		karma: {
			unit: {
				configFile: 'karma.conf.js'
			}
		}
	});

	// Load NPM tasks
	require('load-grunt-tasks')(grunt);

	// Making grunt default to force in order not to break the project.
	grunt.option('force', true);

	// A Task for loading the configuration object
	grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
		var init = require('./config/init')();
		var config = require('./config/config');

		grunt.config.set('applicationJavaScriptFiles', config.assets.js);
		grunt.config.set('applicationCSSFiles', config.assets.css);
	});

	// Default task(s).
	grunt.registerTask('default', ['lint', 'concurrent:default']);

	// Debug task.
	grunt.registerTask('debug', ['lint', 'concurrent:debug']);

	// Secure task(s).
	grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']);

	// Lint task(s).
	grunt.registerTask('lint', ['jshint', 'csslint']);

	// Build task(s).
	grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);

	// Test task.
	grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};
<|endoftext|>


<commit_before>module.exports = function (grunt) {
    "use strict";
    /*eslint-env node*/

    // This will measure the time spent in each task
    require("time-grunt")(grunt);

    /**
     * Force grunt to continue after failing a task
     * ** IT IS NOT RECOMMENDED TO USE THIS **
     * I just want to make sure that all tasks are evaluated whatever happens
     */
    grunt.option("force", true);

    //region copy implementation

    var path = require("path"),
        fs = require("fs");

    function copyFile (from, name) {
        name += ".js";
        fs.writeFileSync("src/" + name, fs.readFileSync(from + "/" + name).toString());
    }

    function copy (ref) {
        ref = "ref/" + ref;
        var stats;
        try {
            stats = fs.statSync(ref);
        } catch (e) {
            return false;
        }
        if (!stats.isDirectory()) {
            return false;
        }
        copyFile(ref, "sinon");
        copyFile(ref, "test");
        return true;
    }

    //endregion

    // This is used to pre-allocate empty configurations (note that each object must be unique, hence the function)
    function genEmptyNotifyConfig () {
        return {
            options: {
                message: ""
            }
        };
    }

    var analyzeInProgress = false;

    // This will configure each task individually
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        // https://www.npmjs.com/package/grunt-serve
        connect: {
            server: {
                options: {
                    port: 9000,
                    open: true,
                    middleware: function (connect, options, middlewares) {

                        middlewares.unshift(
                            // Hello world ! example
                            function (req, res, next) {
                                if (req.url !== "/hello") {
                                    return next();
                                }
                                res.end("Hello world !");
                            },
                            // Copy handler
                            function (req, res, next) {
                                if (0 === req.url.indexOf("/copy?")) {
                                    res.end(JSON.stringify(copy(req.url.substr(6)).toString()));
                                }
                                return next();
                            },
                            // Info handler
                            function (req, res, next) {
                                if (req.url !== "/info") {
                                    return next();
                                }
                                if (analyzeInProgress) {
                                    res.end(JSON.stringify({pending: true}));
                                } else {
                                    res.end(JSON.stringify({
                                        pending: false,
                                        eslint: grunt.file.readJSON("tmp/eslint.json"),
                                        mochaTest: grunt.file.readJSON("tmp/mochaTest.json"),
                                        coverage: grunt.file.readJSON("tmp/coverage.json")
                                    }));
                                }
                            }
                        );

                        return middlewares;
                    }
                }
            }
        },

        // https://www.npmjs.com/package/grunt-eslint
        eslint: {
            json: {
                options: {
                    format: "json",
                    outputFile: "tmp/eslint.json",
                    quiet: true
                },
                files: {
                    src: ["src/*.js"]
                }
            },
            target: {
                files: {
                    src: ["src/*.js"]
                }
            }
        },

        // https://www.npmjs.com/package/grunt-mocha-test
        mochaTest: {
            testJSON: {
                options: {
                    quiet: true,
                    reporter: "json",
                    captureFile: "tmp/mochaTest.json",
                    require: [
                        "node.js"
                    ]
                },
                src: "src/test.js"
            },
            coverage: {
                options: {
                    quiet: true,
                    reporter: "html-cov",
                    captureFile: "tmp/coverage.html"
                },
                src: "src/test.js"
            },
            coverageJSON: {
                options: {
                    reporter: "json-cov",
                    quiet: true,
                    captureFile: "tmp/coverage.json"
                },
                src: "src/test.js"
            }
        },

        // https://www.npmjs.com/package/grunt-notify
        "notify_hooks": {
            options: {
                enabled: false, // Turned off to control when notify is used
                title: "training-functions-stub",
                duration: 3
            }
        },
        notify: {
            "eslint-sinon.js": genEmptyNotifyConfig(),
            "eslint-test.js": genEmptyNotifyConfig(),
            mochaTest: genEmptyNotifyConfig(),
            coverage: genEmptyNotifyConfig()
        },

        // https://www.npmjs.com/package/grunt-contrib-watch
        watch: {
            scripts: {
                files: ["src/*.js"],
                tasks: "analyze",
                options: {
                    spawn: true
                }
            }
        }

    });

    // Load the packages that adds features to grunt
    [
        "grunt-contrib-connect",
        "grunt-contrib-watch",
        "grunt-eslint",
        "grunt-mocha-test",
        "grunt-notify"
    ].forEach(function (packageName) {
        grunt.loadNpmTasks(packageName);
    });
    grunt.task.run("notify_hooks");

    // Register named tasks as aliases or custom implementation (using functions)
    (function (aliases) {
        Object.keys(aliases).forEach(function (name) {
            grunt.registerTask(name, aliases[name]);
        });
    }({
        analyze: [
            "analyzeFlag:true",
            "eslint",
            "notifySetEslint",
            "notify:eslint-sinon",
            "notify:eslint-test",
            "mochaTest",
            "notifySetMochaTest",
            "notify:mochaTest",
            "updateCoverage",
            "notifySetCoverage",
            "notify:coverage",
            "analyzeFlag:false"
        ],

        // Set eslint message for notification
        notifySetEslint: function () {
            // Reset messages
            grunt.config.set("notify.eslint-sinon.options.message", "sinon.js: linting OK");
            grunt.config.set("notify.eslint-test.options.message", "test.js: linting OK");
            var eslintData = grunt.file.readJSON("tmp/eslint.json");
            eslintData.forEach(function (fileData) {
                var fileName = path.basename(fileData.filePath, ".js").toLowerCase(),
                    errorCount = fileData.messages.filter(function (message) {
                        return 2 === message.severity;
                    }).length;
                grunt.config.set("notify.eslint-" + fileName + ".options.message",
                    fileName + ".js: " + errorCount + " linting errors");
            });
        },

        // Set mochaTest message for notification
        notifySetMochaTest: function () {
            var mochaTestData = grunt.file.readJSON("tmp/mochaTest.json"),
                stats = mochaTestData.stats,
                message;
            if (0 === stats.failures) {
                message = "Tests OK";
                if (0 < stats.pending) {
                    message += " (" + stats.pending + " pending)";
                }
            } else {
                message = "Tests KO: " + stats.passes + "/" + (stats.tests - stats.pending);
            }
            grunt.config.set("notify.mochaTest.options.message", message);
        },

        // Append fix-coverage to the generated coverage file
        updateCoverage: function () {
            fs.writeFileSync("tmp/coverage.html", fs.readFileSync("tmp/coverage.html").toString()
                + fs.readFileSync("fix-coverage.html").toString());
        },

        // Set coverage message for notification
        notifySetCoverage: function () {
            var coverageData = grunt.file.readJSON("tmp/coverage.json"),
                message = "coverage: ";
            if (coverageData.sloc) {
                message += Math.floor(1000 * coverageData.hits / coverageData.sloc) / 10 + "%";
            } else {
                message += "N/A";
            }
            grunt.config.set("notify.coverage.options.message", message);
        },

        copy: copy,

        // Analyze flag update
        analyzeFlag: function (value) {
            analyzeInProgress = value === "true";
        },

        // Default task
        "default": [
            "connect:server",
            "analyze",
            "watch"
        ]
    }));

};
<commit_msg>Synchronization using file system<commit_after>module.exports = function (grunt) {
    "use strict";
    /*eslint-env node*/

    // This will measure the time spent in each task
    require("time-grunt")(grunt);

    /**
     * Force grunt to continue after failing a task
     * ** IT IS NOT RECOMMENDED TO USE THIS **
     * I just want to make sure that all tasks are evaluated whatever happens
     */
    grunt.option("force", true);

    //region copy implementation

    var path = require("path"),
        fs = require("fs");

    function copyFile (from, name) {
        name += ".js";
        fs.writeFileSync("src/" + name, fs.readFileSync(from + "/" + name).toString());
    }

    function copy (ref) {
        ref = "ref/" + ref;
        var stats;
        try {
            stats = fs.statSync(ref);
        } catch (e) {
            return false;
        }
        if (!stats.isDirectory()) {
            return false;
        }
        copyFile(ref, "sinon");
        copyFile(ref, "test");
        return true;
    }

    //endregion

    // This is used to pre-allocate empty configurations (note that each object must be unique, hence the function)
    function genEmptyNotifyConfig () {
        return {
            options: {
                message: ""
            }
        };
    }

    function cleanInfo () {
        try {
            fs.unlinkSync("tmp/info.json");
        } catch (e) {
            // ignore
            grunt.log.write(e);
        }
    }

    // This will configure each task individually
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        // https://www.npmjs.com/package/grunt-serve
        connect: {
            server: {
                options: {
                    port: 9000,
                    open: true,
                    middleware: function (connect, options, middlewares) {

                        middlewares.unshift(
                            // Hello world ! example
                            function (req, res, next) {
                                if (req.url !== "/hello") {
                                    return next();
                                }
                                res.end("Hello world !");
                            },
                            // Copy handler
                            function (req, res, next) {
                                if (0 === req.url.indexOf("/copy?")) {
                                    cleanInfo();
                                    res.end(copy(req.url.substr(6)).toString().toString());
                                }
                                return next();
                            },
                            // Info handler
                            function (req, res, next) {
                                if (req.url !== "/info") {
                                    return next();
                                }
                                fs.readFile("tmp/info.json", function (err, data) {
                                    if (err) {
                                        grunt.warn(err);
                                        res.end(JSON.stringify({pending: true}));
                                    } else {
                                        res.end(data.toString());
                                    }
                                });
                            }
                        );

                        return middlewares;
                    }
                }
            }
        },

        // https://www.npmjs.com/package/grunt-eslint
        eslint: {
            json: {
                options: {
                    format: "json",
                    outputFile: "tmp/eslint.json",
                    quiet: true
                },
                files: {
                    src: ["src/*.js"]
                }
            },
            target: {
                files: {
                    src: ["src/*.js"]
                }
            }
        },

        // https://www.npmjs.com/package/grunt-mocha-test
        mochaTest: {
            testJSON: {
                options: {
                    quiet: true,
                    reporter: "json",
                    captureFile: "tmp/mochaTest.json",
                    require: [
                        "node.js"
                    ]
                },
                src: "src/test.js"
            },
            coverage: {
                options: {
                    quiet: true,
                    reporter: "html-cov",
                    captureFile: "tmp/coverage.html"
                },
                src: "src/test.js"
            },
            coverageJSON: {
                options: {
                    reporter: "json-cov",
                    quiet: true,
                    captureFile: "tmp/coverage.json"
                },
                src: "src/test.js"
            }
        },

        // https://www.npmjs.com/package/grunt-notify
        "notify_hooks": {
            options: {
                enabled: false, // Turned off to control when notify is used
                title: "training-functions-stub",
                duration: 3
            }
        },
        notify: {
            "eslint-sinon.js": genEmptyNotifyConfig(),
            "eslint-test.js": genEmptyNotifyConfig(),
            mochaTest: genEmptyNotifyConfig(),
            coverage: genEmptyNotifyConfig()
        },

        // https://www.npmjs.com/package/grunt-contrib-watch
        watch: {
            scripts: {
                files: ["src/*.js"],
                tasks: "analyze",
                options: {
                    spawn: true
                }
            }
        }

    });

    // Load the packages that adds features to grunt
    [
        "grunt-contrib-connect",
        "grunt-contrib-watch",
        "grunt-eslint",
        "grunt-mocha-test",
        "grunt-notify"
    ].forEach(function (packageName) {
        grunt.loadNpmTasks(packageName);
    });
    grunt.task.run("notify_hooks");

    // Register named tasks as aliases or custom implementation (using functions)
    (function (aliases) {
        Object.keys(aliases).forEach(function (name) {
            grunt.registerTask(name, aliases[name]);
        });
    }({
        analyze: [
            "cleanInfo",
            "eslint",
            "notifySetEslint",
            "notify:eslint-sinon",
            "notify:eslint-test",
            "mochaTest",
            "notifySetMochaTest",
            "notify:mochaTest",
            "updateCoverage",
            "notifySetCoverage",
            "notify:coverage",
            "buildInfo"
        ],

        // Set eslint message for notification
        notifySetEslint: function () {
            // Reset messages
            grunt.config.set("notify.eslint-sinon.options.message", "sinon.js: linting OK");
            grunt.config.set("notify.eslint-test.options.message", "test.js: linting OK");
            var eslintData = grunt.file.readJSON("tmp/eslint.json");
            eslintData.forEach(function (fileData) {
                var fileName = path.basename(fileData.filePath, ".js").toLowerCase(),
                    errorCount = fileData.messages.filter(function (message) {
                        return 2 === message.severity;
                    }).length;
                grunt.config.set("notify.eslint-" + fileName + ".options.message",
                    fileName + ".js: " + errorCount + " linting errors");
            });
        },

        // Set mochaTest message for notification
        notifySetMochaTest: function () {
            var mochaTestData = grunt.file.readJSON("tmp/mochaTest.json"),
                stats = mochaTestData.stats,
                message;
            if (0 === stats.failures) {
                message = "Tests OK";
                if (0 < stats.pending) {
                    message += " (" + stats.pending + " pending)";
                }
            } else {
                message = "Tests KO: " + stats.passes + "/" + (stats.tests - stats.pending);
            }
            grunt.config.set("notify.mochaTest.options.message", message);
        },

        // Append fix-coverage to the generated coverage file
        updateCoverage: function () {
            fs.writeFileSync("tmp/coverage.html", fs.readFileSync("tmp/coverage.html").toString()
                + fs.readFileSync("fix-coverage.html").toString());
        },

        // Set coverage message for notification
        notifySetCoverage: function () {
            var coverageData = grunt.file.readJSON("tmp/coverage.json"),
                message = "coverage: ";
            if (coverageData.sloc) {
                message += Math.floor(1000 * coverageData.hits / coverageData.sloc) / 10 + "%";
            } else {
                message += "N/A";
            }
            grunt.config.set("notify.coverage.options.message", message);
        },

        copy: copy,

        cleanInfo: cleanInfo,

        buildInfo: function () {
            fs.writeFileSync("tmp/info.json", JSON.stringify({
                pending: false,
                eslint: grunt.file.readJSON("tmp/eslint.json"),
                mochaTest: grunt.file.readJSON("tmp/mochaTest.json"),
                coverage: grunt.file.readJSON("tmp/coverage.json")
            }));
        },

        // Default task
        "default": [
            "connect:server",
            "analyze",
            "watch"
        ]
    }));

};
<|endoftext|>