<commit_before>/*
 * (C) Copyright 2014 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */

module.exports = function(grunt)
{
  var DIST_DIR = 'dist';

  var pkg = grunt.file.readJSON('package.json');

  var bower =
  {
    TOKEN:      process.env.TOKEN,
    repository: 'git://github.com/Kurento/<%= pkg.name %>-bower.git'
  };

  // Project configuration.
  grunt.initConfig(
  {
    pkg:   pkg,
    bower: bower,

    // Plugins configuration
    clean:
    {
      generated_code: [DIST_DIR, 'src'],

      generated_doc: '<%= jsdoc.all.dest %>'
    },

    // Generate documentation
    jsdoc:
    {
      all:
      {
        src: ['README.md', 'lib/**/*.js', 'test/*.js'],
        dest: 'doc/jsdoc'
      }
    },

    curl:
    {
      'shims/sockjs-0.3.js': 'http://cdn.sockjs.org/sockjs-0.3.js'
    },

    // Generate browser versions and mapping debug file
    browserify:
    {
      require:
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>_require.js'
      },

      standalone:
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>.js',

        options:
        {
          bundleOptions: {
            standalone: 'KwsMedia'
          }
        }
      },

      'require minified':
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>_require.min.js',

        options:
        {
          debug: true,
          plugin: [
            ['minifyify',
             {
               compressPath: DIST_DIR,
               map: '<%= pkg.name %>.map'
             }]
          ]
        }
      },

      'standalone minified':
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>.min.js',

        options:
        {
          debug: true,
          bundleOptions: {
            standalone: 'KwsMedia'
          },
          plugin: [
            ['minifyify',
             {
               compressPath: DIST_DIR,
               map: '<%= pkg.name %>.map',
               output: DIST_DIR+'/<%= pkg.name %>.map'
             }]
          ]
        }
      }
    },

    // Generate bower.json file from package.json data
    sync:
    {
      bower:
      {
        options:
        {
          sync: [
            'name', 'description', 'license', 'keywords', 'homepage',
            'repository'
          ],
          overrides: {
            authors: (pkg.author ? [pkg.author] : []).concat(pkg.contributors || [])
          }
        }
      }
    },

    // Publish / update package info in Bower
    shell:
    {
      bower: {
        command: [
          'curl -X DELETE "https://bower.herokuapp.com/packages/<%= pkg.name %>?auth_token=<%= bower.TOKEN %>"',
          'node_modules/.bin/bower register <%= pkg.name %> <%= bower.repository %>',
          'node_modules/.bin/bower cache clean'
        ].join('&&')
      }
    }
  });

  // Load plugins
  grunt.loadNpmTasks('grunt-browserify');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-curl');
  grunt.loadNpmTasks('grunt-jsdoc');
  grunt.loadNpmTasks('grunt-npm2bower-sync');
  grunt.loadNpmTasks('grunt-shell');

  // Alias tasks
  grunt.registerTask('default', ['clean', 'jsdoc', 'curl', 'browserify']);
  grunt.registerTask('bower',   ['sync:bower', 'shell:bower']);
};
<commit_msg>Set main field on bower.json<commit_after>/*
 * (C) Copyright 2014 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */

module.exports = function(grunt)
{
  var DIST_DIR = 'dist';

  var pkg = grunt.file.readJSON('package.json');

  var bower =
  {
    TOKEN:      process.env.TOKEN,
    repository: 'git://github.com/Kurento/<%= pkg.name %>-bower.git'
  };

  // Project configuration.
  grunt.initConfig(
  {
    pkg:   pkg,
    bower: bower,

    // Plugins configuration
    clean:
    {
      generated_code: [DIST_DIR, 'src'],

      generated_doc: '<%= jsdoc.all.dest %>'
    },

    // Generate documentation
    jsdoc:
    {
      all:
      {
        src: ['README.md', 'lib/**/*.js', 'test/*.js'],
        dest: 'doc/jsdoc'
      }
    },

    curl:
    {
      'shims/sockjs-0.3.js': 'http://cdn.sockjs.org/sockjs-0.3.js'
    },

    // Generate browser versions and mapping debug file
    browserify:
    {
      require:
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>_require.js'
      },

      standalone:
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>.js',

        options:
        {
          bundleOptions: {
            standalone: 'KwsMedia'
          }
        }
      },

      'require minified':
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>_require.min.js',

        options:
        {
          debug: true,
          plugin: [
            ['minifyify',
             {
               compressPath: DIST_DIR,
               map: '<%= pkg.name %>.map'
             }]
          ]
        }
      },

      'standalone minified':
      {
        src:  '<%= pkg.main %>',
        dest: DIST_DIR+'/<%= pkg.name %>.min.js',

        options:
        {
          debug: true,
          bundleOptions: {
            standalone: 'KwsMedia'
          },
          plugin: [
            ['minifyify',
             {
               compressPath: DIST_DIR,
               map: '<%= pkg.name %>.map',
               output: DIST_DIR+'/<%= pkg.name %>.map'
             }]
          ]
        }
      }
    },

    // Generate bower.json file from package.json data
    sync:
    {
      bower:
      {
        options:
        {
          sync: [
            'name', 'description', 'license', 'keywords', 'homepage',
            'repository'
          ],
          overrides: {
            authors: (pkg.author ? [pkg.author] : []).concat(pkg.contributors || []),
            main: 'js/<%= pkg.name %>.js'
          }
        }
      }
    },

    // Publish / update package info in Bower
    shell:
    {
      bower: {
        command: [
          'curl -X DELETE "https://bower.herokuapp.com/packages/<%= pkg.name %>?auth_token=<%= bower.TOKEN %>"',
          'node_modules/.bin/bower register <%= pkg.name %> <%= bower.repository %>',
          'node_modules/.bin/bower cache clean'
        ].join('&&')
      }
    }
  });

  // Load plugins
  grunt.loadNpmTasks('grunt-browserify');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-curl');
  grunt.loadNpmTasks('grunt-jsdoc');
  grunt.loadNpmTasks('grunt-npm2bower-sync');
  grunt.loadNpmTasks('grunt-shell');

  // Alias tasks
  grunt.registerTask('default', ['clean', 'jsdoc', 'curl', 'browserify']);
  grunt.registerTask('bower',   ['sync:bower', 'shell:bower']);
};
<|endoftext|>


<commit_before>require([
    'jquery', 'hammerjs', 'jquery-hammerjs', 'materialize',
], function($) {
    $(".button-collapse").sideNav({
       menuWidth: 310,
    });
    $('.collapsible').collapsible();
    $('.datepicker').pickadate({
        onOpen: function() {
            var _this = this.$node;
            var select = this.get('select');
            if (select === null) {
              this.set('select', new Date(_this.data('initial')));
            }
            var start = $('.datepicker#start-date');
            var end = $('.datepicker#end-date');
            var min = start.val() ? start.val() : start.data('initial');
            var max = end.val() ? end.val() : end.data('initial');
            if (_this.is('#start-date')) {
                this.set('max', new Date(max));
            } else if (_this.is('#end-date')) {
                this.set('min', new Date(min));
            }
        },
        onClose: function() {
            $(document.activeElement).blur();
        },
        min: new Date($('.datepicker#start-date').data('initial')),
        max: new Date($('.datepicker#end-date').data('initial')),
        today: false,
        selectYears: 20,
        selectMonths: true,
        format: 'mmmm d, yyyy',
        container: 'body'
    });
});
<commit_msg>initialized tabs<commit_after>require([
    'jquery', 'hammerjs', 'jquery-hammerjs', 'materialize',
], function($) {
    $('ul.tabs').tabs();
    $(".button-collapse").sideNav({
       menuWidth: 310,
    });
    $('.collapsible').collapsible();
    $('.datepicker').pickadate({
        onOpen: function() {
            var _this = this.$node;
            var select = this.get('select');
            if (select === null) {
              this.set('select', new Date(_this.data('initial')));
            }
            var start = $('.datepicker#start-date');
            var end = $('.datepicker#end-date');
            var min = start.val() ? start.val() : start.data('initial');
            var max = end.val() ? end.val() : end.data('initial');
            if (_this.is('#start-date')) {
                this.set('max', new Date(max));
            } else if (_this.is('#end-date')) {
                this.set('min', new Date(min));
            }
        },
        onClose: function() {
            $(document.activeElement).blur();
        },
        min: new Date($('.datepicker#start-date').data('initial')),
        max: new Date($('.datepicker#end-date').data('initial')),
        today: false,
        selectYears: 20,
        selectMonths: true,
        format: 'mmmm d, yyyy',
        container: 'body'
    });
});
<|endoftext|>


<commit_before>/*global module:false*/
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({

    // Metadata.
    pkg: grunt.file.readJSON('package.json'),
    banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
      '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
      '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
      '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
      ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',

    // Custome Paths
    srcFiles: ['src/js/thbarjs.js'], // source files
    componentsDir: 'src/js/components', // bower components
    testFiles: ['spec/*.spec.js'], // test files (jasmine specs)

    // Task configuration.
    jshint: { // check javascript syntax and errors
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        unused: true,
        boss: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true, $: true, viewerjs: true, X: true, dicomParser: true, console: true,
          alert: true, require: true, describe: true, it: true, expect: true, beforeEach: true,
          afterEach: true, define: true
        }
      },
      source: {
        src: '<%= srcFiles %>'
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      test: {
        src: '<%= testFiles %>'
      }
    },

    jasmine: { // run tests
      test: {
        //src: '<%= jshint.source.src %>', this line must be commented when using the define function within the specs files
        options: {
          specs: '<%= jshint.test.src %>',
          template: require('grunt-template-jasmine-requirejs'),
          templateOptions: {
            version: '<%= componentsDir %>/requirejs/require.js',
            requireConfigFile: 'src/main.js', // requireJS's config file
            requireConfig: {
              baseUrl: '<%= componentsDir %>' // change base url to execute tests from local FS
            }
          }
        }
      }
    },

    requirejs: { // concat and minimize AMD modules
      compile: {
        options: {
          baseUrl: '<%= componentsDir %>',
          paths: {
            jquery: 'empty:', // does not include jquery in the output
            jquery_ui: 'empty:', // does not include jquery_ui in the output
          },
          name: 'thbarjs',
          mainConfigFile: 'src/main.js',
          out: 'dist/js/<%= pkg.name %>.min.js'
        }
      }
    },

    cssmin: { // concat and minimize css
      dist: {
        files: {
          'dist/styles/thbarjs.css': ['src/styles/**/*.css']
        }
      }
    },

    copy: {
      components: { // copy requiered bower components which were not concatenated
        files: [
          { expand: true,
            cwd: '<%= componentsDir %>',
            src: ['requirejs/require.js', 'jquery/dist/jquery.min.js',
              'jquery-ui/jquery-ui.min.js', 'jquery-ui/themes/smoothness/**'],
            dest: 'dist/js/components' }]
      }
    },

    watch: {
      source: {
        files: '<%= jshint.source.src %>',
        tasks: ['jshint:source']
      },
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      test: {
        files: '<%= jshint.test.src %>',
        tasks: ['jshint:test', 'jasmine']
      }
    }

  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-requirejs');

  grunt.registerTask('watch', ['watch']);
  // Test task.
  grunt.registerTask('test', ['jshint', 'jasmine']);
  // Build task.
  grunt.registerTask('build', ['cssmin', 'jshint', 'jasmine', 'requirejs', 'copy']);
  // Default task.
  grunt.registerTask('default', ['build']);

};
<commit_msg>Standardize Gruntfile<commit_after>/*global module:false*/
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({

    // Metadata.
    pkg: grunt.file.readJSON('package.json'),
    banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
      '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
      '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
      '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
      ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',

    // Custome Paths
    srcFiles: ['src/js/*.js'], // source files
    componentsDir: 'src/js/components', // bower components
    testFiles: ['spec/*.spec.js'], // test files (jasmine specs)

    // Task configuration.
    jshint: { // check javascript syntax and errors
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        unused: true,
        boss: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true, $: true, viewerjs: true, X: true, dicomParser: true, console: true,
          alert: true, require: true, describe: true, it: true, expect: true, beforeEach: true,
          afterEach: true, define: true
        }
      },
      source: {
        src: '<%= srcFiles %>'
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      test: {
        src: '<%= testFiles %>'
      }
    },

    jasmine: { // run tests
      test: {
        //src: '<%= jshint.source.src %>', this line must be commented when using the define function within the specs files
        options: {
          specs: '<%= jshint.test.src %>',
          template: require('grunt-template-jasmine-requirejs'),
          templateOptions: {
            version: '<%= componentsDir %>/requirejs/require.js',
            requireConfigFile: 'src/main.js', // requireJS's config file
            requireConfig: {
              baseUrl: '<%= componentsDir %>' // change base url to execute tests from local FS
            }
          }
        }
      }
    },

    requirejs: { // concat and minimize AMD modules
      compile: {
        options: {
          baseUrl: '<%= componentsDir %>',
          paths: {
            jquery: 'empty:', // does not include jquery in the output
            jquery_ui: 'empty:', // does not include jquery_ui in the output
          },
          name: '<%= pkg.name %>',
          mainConfigFile: 'src/main.js',
          out: 'dist/js/<%= pkg.name %>.min.js'
        }
      }
    },

    cssmin: { // concat and minimize css
      dist: {
        files: {
          'dist/styles/<%= pkg.name %>.css': ['src/styles/**/*.css']
        }
      }
    },

    copy: {
      components: { // copy requiered bower components which were not concatenated
        files: [
          { expand: true,
            cwd: '<%= componentsDir %>',
            src: ['requirejs/require.js', 'jquery/dist/jquery.min.js',
              'jquery-ui/jquery-ui.min.js', 'jquery-ui/themes/smoothness/**'],
            dest: 'dist/js/components' }]
      }
    },

    watch: {
      source: {
        files: '<%= jshint.source.src %>',
        tasks: ['jshint:source']
      },
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      test: {
        files: '<%= jshint.test.src %>',
        tasks: ['jshint:test', 'jasmine']
      }
    }

  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-requirejs');

  grunt.registerTask('watch', ['watch']);
  // Test task.
  grunt.registerTask('test', ['jshint', 'jasmine']);
  // Build task.
  grunt.registerTask('build', ['cssmin', 'jshint', 'jasmine', 'requirejs', 'copy']);
  // Default task.
  grunt.registerTask('default', ['build']);

};
<|endoftext|>


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

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

    // SASS is all about stylesheets
    sass: {
      dist: {
        options: {
          style: 'compressed'
        },
        files: {
          'source/css/style.min.css': 'source/css/style.scss'
        }
      },
      dev: {
        options: {
          style: 'expanded'
        },
        files: {
          'source/css/style.css': 'source/css/style.scss'
        }
      }
    },

    // Patternlab is build with the terminal
    shell: {
      buildPatternLab: {
        command: 'php core/builder.php -g'
      },
      buildStyleguide: {
        command: 'kss-node source/css styleguide --css source/css/style.css'
      }
    },

    // Publish the public folder using gh-pages
    'gh-pages': {
      options: {
        base: 'public'
      },
      src: ['**']
    }

  });

  // Load the plugin that provides the "sass" task.
  grunt.loadNpmTasks('grunt-contrib-sass');
  // Load the plugin that provides the "shell" task.
  grunt.loadNpmTasks('grunt-shell');
  // Load the plugin that provides the "gh-pages" task.
  grunt.loadNpmTasks('grunt-gh-pages');

  // Default task(s).
  grunt.registerTask('default', ['sass:dev', 'shell']);

  // Build the dist an publish it
  grunt.registerTask('dist', ['sass', 'shell', 'gh-pages']);

};
<commit_msg>generate KSS styleguide with github like template<commit_after>module.exports = function(grunt) {

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

    // SASS is all about stylesheets
    sass: {
      dist: {
        options: {
          style: 'compressed'
        },
        files: {
          'source/css/style.min.css': 'source/css/style.scss'
        }
      },
      dev: {
        options: {
          style: 'expanded'
        },
        files: {
          'source/css/style.css': 'source/css/style.scss'
        }
      }
    },

    // Patternlab is build with the terminal
    shell: {
      buildPatternLab: {
        command: 'php core/builder.php -g'
      },
      buildStyleguide: {
        // The following command need `https://github.com/1026/kss-node-template-such-as-github` template in `~/Documents/Developpement/`
        command: 'kss-node source/css styleguide --css source/css/style.css --template ~/Documents/Developpement/kss-node-template-such-as-github/template'
        // Default template
        //command: 'kss-node source/css styleguide --css source/css/style.css'
      }
    },

    // Publish the public folder using gh-pages
    'gh-pages': {
      options: {
        base: 'public'
      },
      src: ['**']
    }

  });

  // Load the plugin that provides the "sass" task.
  grunt.loadNpmTasks('grunt-contrib-sass');
  // Load the plugin that provides the "shell" task.
  grunt.loadNpmTasks('grunt-shell');
  // Load the plugin that provides the "gh-pages" task.
  grunt.loadNpmTasks('grunt-gh-pages');

  // Default task(s).
  grunt.registerTask('default', ['sass:dev', 'shell']);

  // Build the dist an publish it
  grunt.registerTask('dist', ['sass', 'shell', 'gh-pages']);

};
<|endoftext|>


<commit_before>/* jshint node: true */
module.exports = function(grunt) {

  var NW_VERSION = '0.8.3';

  // linudev.so.0 workaround, see README.md
  process.env.LD_LIBRARY_PATH = '.:' + process.env.LD_LIBRARY_PATH;

  grunt.initConfig({

    run: {
      options: {
        nwArgs: ['.'],
        downloadDir: 'node-webkit',
        runtimeVersion: NW_VERSION,
        forceDownload: false,
        forceExtract: false
      }
    },

    build: {
      options: {
        downloadDir: 'node-webkit',
        runtimeVersion: NW_VERSION,
        forceDownload: false,
        forceExtract: false,
        linux_ia32: true,
        linux_x64: true,
        win: true,
        osx: false,
        packageOverride: {
          window: {
            toolbar: false
          }
        }
      }
    }

  });

  grunt.loadTasks('tasks');

};<commit_msg>Bump node-webkit version<commit_after>/* jshint node: true */
module.exports = function(grunt) {

  var NW_VERSION = '0.9.2';

  // linudev.so.0 workaround, see README.md
  process.env.LD_LIBRARY_PATH = '.:' + process.env.LD_LIBRARY_PATH;

  grunt.initConfig({

    run: {
      options: {
        nwArgs: ['.'],
        downloadDir: 'node-webkit',
        runtimeVersion: NW_VERSION,
        forceDownload: false,
        forceExtract: false
      }
    },

    build: {
      options: {
        downloadDir: 'node-webkit',
        runtimeVersion: NW_VERSION,
        forceDownload: false,
        forceExtract: false,
        linux_ia32: true,
        linux_x64: true,
        win: true,
        osx: false,
        packageOverride: {
          window: {
            toolbar: false
          }
        }
      }
    }

  });

  grunt.loadTasks('tasks');

};<|endoftext|>


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

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      dist: {
        src: [ 'node_modules/marked/lib/marked.js', 'src/jquery.gh-readme.js' ],
        dest: 'dist/jquery.gh-readme.full.js'
      }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> v<%= pkg.version %> */\n'
      },
      build: {
        src: 'dist/jquery.gh-readme.full.js',
        dest: 'dist/jquery.gh-readme.min.js'
      }
    },
    mocha: {
      test: {
        src: [ 'tests/**/*.html' ],
        options: {
          run: true
        }
      }
    },
    jshint: {
      files: ['gruntfile.js', 'src/*.js', 'tests/**/*.js'],
      options: {
        globals: {
          jQuery: true,
          console: true,
          module: true
        }
      }
    },
    bump: {
      options: {
        files: [ 'package.json', 'bower.json' ],
        commit: true,
        commitMessage: 'increment version to %VERSION%',
        commitFiles: [ 'package.json', 'bower.json' ],
        createTag: true,
        push: true,
        pushTo: 'master'
      }
    }
  });

  // Load the plugins
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-mocha');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-bump');

  // Default tasks
  grunt.registerTask('default', ['concat', 'uglify', 'mocha', 'jshint']);

};<commit_msg>update pushTo option for bump<commit_after>module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      dist: {
        src: [ 'node_modules/marked/lib/marked.js', 'src/jquery.gh-readme.js' ],
        dest: 'dist/jquery.gh-readme.full.js'
      }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> v<%= pkg.version %> */\n'
      },
      build: {
        src: 'dist/jquery.gh-readme.full.js',
        dest: 'dist/jquery.gh-readme.min.js'
      }
    },
    mocha: {
      test: {
        src: [ 'tests/**/*.html' ],
        options: {
          run: true
        }
      }
    },
    jshint: {
      files: ['gruntfile.js', 'src/*.js', 'tests/**/*.js'],
      options: {
        globals: {
          jQuery: true,
          console: true,
          module: true
        }
      }
    },
    bump: {
      options: {
        files: [ 'package.json', 'bower.json' ],
        commit: true,
        commitMessage: 'increment version to %VERSION%',
        commitFiles: [ 'package.json', 'bower.json' ],
        createTag: true,
        push: true,
        pushTo: 'origin'
      }
    }
  });

  // Load the plugins
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-mocha');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-bump');

  // Default tasks
  grunt.registerTask('default', ['concat', 'uglify', 'mocha', 'jshint']);

};<|endoftext|>


<commit_before>/*jslint node: true */
'use strict';

var pkg = require('./package.json');

//Using exclusion patterns slows down Grunt significantly
//instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**'
//this method is used to create a set of inclusive patterns for all subdirectories
//skipping node_modules, bower_components, dist, and any .dirs
//This enables users to create any directory structure they desire.
var createFolderGlobs = function(fileTypePatterns) {
  fileTypePatterns = Array.isArray(fileTypePatterns) ? fileTypePatterns : [fileTypePatterns];
  var ignore = ['node_modules','bower_components','dist','temp'];
  var fs = require('fs');
  return fs.readdirSync(process.cwd())
          .map(function(file){
            if (ignore.indexOf(file) !== -1 ||
                file.indexOf('.') === 0 ||
                !fs.lstatSync(file).isDirectory()) {
              return null;
            } else {
              return fileTypePatterns.map(function(pattern) {
                return file + '/**/' + pattern;
              });
            }
          })
          .filter(function(patterns){
            return patterns;
          })
          .concat(fileTypePatterns);
};

module.exports = function (grunt) {

  // load all grunt tasks
  require('load-grunt-tasks')(grunt);

  // Project configuration.
  grunt.initConfig({
    connect: {
      main: {
        options: {
          port: 9001
        }
      }
    },
    watch: {
      main: {
        options: {
            livereload: true,
            livereloadOnError: false,
            spawn: false
        },
        files: [createFolderGlobs(['*.js','*.less','*.html']),'!_SpecRunner.html','!.grunt'],
        tasks: [] //all the tasks are run dynamically during the watch event handler
      }
    },
    jshint: {
      main: {
        options: {
            jshintrc: '.jshintrc'
        },
        src: createFolderGlobs('*.js')
      }
    },
    clean: {
      before:{
        src:['dist','temp']
      },
      after: {
        src:['temp']
      }
    },
    less: {
      production: {
        options: {
        },
        files: {
          'temp/app.css': 'app.less'
        }
      }
    },
    autoprefixer: {
      options: {
        browsers: ['ie >= 8', 'ff > 4', 'last 8 versions']
      },
      main: {
        src: 'temp/app.css'
      }
    },
    ngtemplates: {
      main: {
        options: {
            module: pkg.name,
            htmlmin:'<%= htmlmin.main.options %>'
        },
        src: [createFolderGlobs('*.html'),'!index.html','!_SpecRunner.html'],
        dest: 'temp/templates.js'
      }
    },
    copy: {
      main: {
        files: [
          {src: ['img/**'], dest: 'dist/'},
          {src: ['temp_data/**'], dest: 'dist/'},
          {
            expand: true,
            cwd: 'bower_components/bootstrap/fonts/',
            src: ['**'],
            dest: 'dist/fonts/'
          },
          {
            expand: true,
            cwd: 'bower_components/bootstrap/fonts/',
            src: ['**'],
            dest: 'dist/fonts/'
          },
          {
            src: ['locales/**'],
            dest: 'dist/'
          },
//           {src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/',filter:'isFile',expand:true}
          //{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
          //{src: ['bower_components/select2/*.png','bower_components/select2/*.gif'], dest:'dist/css/',flatten:true,expand:true},
          //{src: ['bower_components/angular-mocks/angular-mocks.js'], dest: 'dist/'}
        ]
      }
    },
    dom_munger:{
      read: {
        options: {
          read:[
            {selector:'script[class="libnocompat"]',attribute:'src',writeto:'libnocompatjs'},
            {selector:'script[class="lib"]',attribute:'src',writeto:'libjs'},
            {selector:'script[class="app"]',attribute:'src',writeto:'appjs'},
            {selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
          ]
        },
        src: 'index.html'
      },
      update: {
        options: {
          remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
          append: [
            {selector:'body',html:'<!--[if lte IE 8]><script src="libcompat-v1.0.4.min.js"></script><![endif]--><!--[if gte IE 9]><script src="libnocompat-v1.0.4.min.js"></script><![endif]--><!--[if !IE]><!--><script src="libnocompat-v1.0.4.min.js"></script><!--<![endif]-->'},
            {selector:'body',html:'<script src="lib-v1.0.4.min.js"></script>'},
            {selector:'body',html:'<script src="avConfig-v1.0.4.js"></script>'},
            {selector:'body',html:'<script src="app-v1.0.4.min.js"></script>'},
            {selector:'head',html:'<link rel="stylesheet" href="app-v1.0.4.full.min.css">'}
          ]
        },
        src:'index.html',
        dest: 'dist/index.html'
      }
    },
    cssmin: {
      main: {
        src:['temp/app.css','<%= dom_munger.data.appcss %>'],
        dest:'dist/app-v1.0.4.full.min.css'
      },
    },
    concat: {
      main: {
        files: {
          'temp/libcompat.js': [
             'vendor/jquery.compat/jquery-1.11.1.js',
             'vendor/json3/json-v3.3.2.js',
             'vendor/crypto/unsupportedBrowser.js'
          ],
          'temp/libnocompat.js': ['<%= dom_munger.data.libnocompatjs %>'],
          'temp/lib.js': ['<%= dom_munger.data.libjs %>'],
          'temp/app.js': ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
          'dist/avConfig-v1.0.4.js': ['avConfig.js']
        }
      }
    },
    ngAnnotate: {
      main: {
        files: {
        'temp/app.js':['temp/app.js'],
        'temp/lib.js': ['temp/lib.js'],
        'temp/libnocompat.js': ['temp/libnocompat.js'],
        'temp/libcompat.js': ['temp/libcompat.js']
        }
      }
    },
    uglify: {
      main: {
        /*options:{
          mangle: false,
          compress: false,
          beautify: true
        },*/
        files: {
          'dist/app-v1.0.4.min.js': 'temp/app.js',
          'dist/lib-v1.0.4.min.js': 'temp/lib.js',
          'dist/libnocompat-v1.0.4.min.js': 'temp/libnocompat.js',
          'dist/libcompat-v1.0.4.min.js': 'temp/libcompat.js'
        }
      }
    },
    htmlmin: {
      main: {
        options: {
          collapseBooleanAttributes: true,
          collapseWhitespace: true,
          removeAttributeQuotes: false,
          removeComments: false,
          removeEmptyAttributes: true,
          removeScriptTypeAttributes: true,
          removeStyleLinkTypeAttributes: true
        },
        files: {
          'dist/index.html': 'dist/index.html'
        }
      }
    },
    imagemin: {
      main:{
        files: [{
          expand: true, cwd:'dist/',
          src:['**/{*.png,*.jpg}'],
          dest: 'dist/'
        }]
      }
    },
    karma: {
      options: {
        frameworks: ['jasmine'],
        files: [  //this files data is also updated in the watch handler, if updated change there too
          '<%= dom_munger.data.libnocompatjs %>',
          '<%= dom_munger.data.libjs %>',
          'avConfig.js',
          '<%= dom_munger.data.appjs %>',
          '<%= ngtemplates.main.dest %>',
          'bower_components/angular-mocks/angular-mocks.js',
          createFolderGlobs('*-spec.js')
        ],
        logLevel:'ERROR',
        reporters:['mocha'],
        autoWatch: false, //watching is handled by grunt-contrib-watch
        singleRun: true
      },
      all_tests: {
        browsers: ['PhantomJS','Chrome','Firefox']
      },
      during_watch: {
        browsers: ['PhantomJS']
      },
    },
    protractor: {
      options: {
        configFile: "node_modules/protractor/referenceConf.js", // Default config file
        keepAlive: true, // If false, the grunt process stops when the test fails.
        noColor: false, // If true, protractor will not use colors in its output.
        args: {
        // Arguments passed to the command
      }
    },
    //your_target: {   // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
      all: {
      options: {
        configFile: "e2e.conf.js", // Target-specific config file
        args: {} // Target-specific arguments
      }
    },
  },

  });

  grunt.registerTask('build',['jshint','clean:before','less','autoprefixer','dom_munger','ngtemplates','cssmin','concat','ngAnnotate','uglify','copy','htmlmin','imagemin','clean:after']);
  grunt.registerTask('serve', ['dom_munger:read','jshint','connect', 'watch']);
  grunt.registerTask('test',['dom_munger:read','karma:all_tests']);

  grunt.event.on('watch', function(action, filepath) {
    //https://github.com/gruntjs/grunt-contrib-watch/issues/156

    var tasksToRun = [];

    if ((filepath.lastIndexOf('.json') !== -1 && filepath.lastIndexOf('.json') === filepath.length - 5) ||
        (filepath.lastIndexOf('.js') !== -1 && filepath.lastIndexOf('.js') === filepath.length - 3)) {

      //lint the changed js file
      grunt.config('jshint.main.src', filepath);
      tasksToRun.push('jshint');

      //find the appropriate unit t est for the changed file
      var spec = filepath;
      if (filepath.lastIndexOf('-spec.js') === -1 || filepath.lastIndexOf('-spec.js') !== filepath.length - 8) {
        spec = filepath.substring(0,filepath.length - 3) + '-spec.js';
      }

      //if the spec exists then lets run it
      if (grunt.file.exists(spec)) {
        var files = [].concat(grunt.config('dom_munger.data.libnocompatjs'));
        files.concat(grunt.config('dom_munger.data.libjs'));
        files.push('bower_components/angular-mocks/angular-mocks.js');
        files.push('avConfig.js');
        files.concat(grunt.config('dom_munger.data.appjs'));
        files.concat(grunt.config('ngtemplates.main.dest'));
        files.push(spec);
        grunt.config('karma.options.files', files);
        tasksToRun.push('karma:during_watch');
      }
    }

    //if index.html changed, we need to reread the <script> tags so our next run of karma
    //will have the correct environment
    if (filepath === 'index.html') {
      tasksToRun.push('dom_munger:read');
    }

    grunt.config('watch.main.tasks',tasksToRun);

  });

  grunt.loadNpmTasks('grunt-protractor-runner');
};
<commit_msg>bump version<commit_after>/*jslint node: true */
'use strict';

var pkg = require('./package.json');

//Using exclusion patterns slows down Grunt significantly
//instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**'
//this method is used to create a set of inclusive patterns for all subdirectories
//skipping node_modules, bower_components, dist, and any .dirs
//This enables users to create any directory structure they desire.
var createFolderGlobs = function(fileTypePatterns) {
  fileTypePatterns = Array.isArray(fileTypePatterns) ? fileTypePatterns : [fileTypePatterns];
  var ignore = ['node_modules','bower_components','dist','temp'];
  var fs = require('fs');
  return fs.readdirSync(process.cwd())
          .map(function(file){
            if (ignore.indexOf(file) !== -1 ||
                file.indexOf('.') === 0 ||
                !fs.lstatSync(file).isDirectory()) {
              return null;
            } else {
              return fileTypePatterns.map(function(pattern) {
                return file + '/**/' + pattern;
              });
            }
          })
          .filter(function(patterns){
            return patterns;
          })
          .concat(fileTypePatterns);
};

module.exports = function (grunt) {

  // load all grunt tasks
  require('load-grunt-tasks')(grunt);

  // Project configuration.
  grunt.initConfig({
    connect: {
      main: {
        options: {
          port: 9001
        }
      }
    },
    watch: {
      main: {
        options: {
            livereload: true,
            livereloadOnError: false,
            spawn: false
        },
        files: [createFolderGlobs(['*.js','*.less','*.html']),'!_SpecRunner.html','!.grunt'],
        tasks: [] //all the tasks are run dynamically during the watch event handler
      }
    },
    jshint: {
      main: {
        options: {
            jshintrc: '.jshintrc'
        },
        src: createFolderGlobs('*.js')
      }
    },
    clean: {
      before:{
        src:['dist','temp']
      },
      after: {
        src:['temp']
      }
    },
    less: {
      production: {
        options: {
        },
        files: {
          'temp/app.css': 'app.less'
        }
      }
    },
    autoprefixer: {
      options: {
        browsers: ['ie >= 8', 'ff > 4', 'last 8 versions']
      },
      main: {
        src: 'temp/app.css'
      }
    },
    ngtemplates: {
      main: {
        options: {
            module: pkg.name,
            htmlmin:'<%= htmlmin.main.options %>'
        },
        src: [createFolderGlobs('*.html'),'!index.html','!_SpecRunner.html'],
        dest: 'temp/templates.js'
      }
    },
    copy: {
      main: {
        files: [
          {src: ['img/**'], dest: 'dist/'},
          {src: ['temp_data/**'], dest: 'dist/'},
          {
            expand: true,
            cwd: 'bower_components/bootstrap/fonts/',
            src: ['**'],
            dest: 'dist/fonts/'
          },
          {
            expand: true,
            cwd: 'bower_components/bootstrap/fonts/',
            src: ['**'],
            dest: 'dist/fonts/'
          },
          {
            src: ['locales/**'],
            dest: 'dist/'
          },
//           {src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/',filter:'isFile',expand:true}
          //{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
          //{src: ['bower_components/select2/*.png','bower_components/select2/*.gif'], dest:'dist/css/',flatten:true,expand:true},
          //{src: ['bower_components/angular-mocks/angular-mocks.js'], dest: 'dist/'}
        ]
      }
    },
    dom_munger:{
      read: {
        options: {
          read:[
            {selector:'script[class="libnocompat"]',attribute:'src',writeto:'libnocompatjs'},
            {selector:'script[class="lib"]',attribute:'src',writeto:'libjs'},
            {selector:'script[class="app"]',attribute:'src',writeto:'appjs'},
            {selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
          ]
        },
        src: 'index.html'
      },
      update: {
        options: {
          remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
          append: [
            {selector:'body',html:'<!--[if lte IE 8]><script src="libcompat-v1.0.5.min.js"></script><![endif]--><!--[if gte IE 9]><script src="libnocompat-v1.0.5.min.js"></script><![endif]--><!--[if !IE]><!--><script src="libnocompat-v1.0.5.min.js"></script><!--<![endif]-->'},
            {selector:'body',html:'<script src="lib-v1.0.5.min.js"></script>'},
            {selector:'body',html:'<script src="avConfig-v1.0.5.js"></script>'},
            {selector:'body',html:'<script src="app-v1.0.5.min.js"></script>'},
            {selector:'head',html:'<link rel="stylesheet" href="app-v1.0.5.full.min.css">'}
          ]
        },
        src:'index.html',
        dest: 'dist/index.html'
      }
    },
    cssmin: {
      main: {
        src:['temp/app.css','<%= dom_munger.data.appcss %>'],
        dest:'dist/app-v1.0.5.full.min.css'
      },
    },
    concat: {
      main: {
        files: {
          'temp/libcompat.js': [
             'vendor/jquery.compat/jquery-1.11.1.js',
             'vendor/json3/json-v3.3.2.js',
             'vendor/crypto/unsupportedBrowser.js'
          ],
          'temp/libnocompat.js': ['<%= dom_munger.data.libnocompatjs %>'],
          'temp/lib.js': ['<%= dom_munger.data.libjs %>'],
          'temp/app.js': ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
          'dist/avConfig-v1.0.5.js': ['avConfig.js']
        }
      }
    },
    ngAnnotate: {
      main: {
        files: {
        'temp/app.js':['temp/app.js'],
        'temp/lib.js': ['temp/lib.js'],
        'temp/libnocompat.js': ['temp/libnocompat.js'],
        'temp/libcompat.js': ['temp/libcompat.js']
        }
      }
    },
    uglify: {
      main: {
        /*options:{
          mangle: false,
          compress: false,
          beautify: true
        },*/
        files: {
          'dist/app-v1.0.5.min.js': 'temp/app.js',
          'dist/lib-v1.0.5.min.js': 'temp/lib.js',
          'dist/libnocompat-v1.0.5.min.js': 'temp/libnocompat.js',
          'dist/libcompat-v1.0.5.min.js': 'temp/libcompat.js'
        }
      }
    },
    htmlmin: {
      main: {
        options: {
          collapseBooleanAttributes: true,
          collapseWhitespace: true,
          removeAttributeQuotes: false,
          removeComments: false,
          removeEmptyAttributes: true,
          removeScriptTypeAttributes: true,
          removeStyleLinkTypeAttributes: true
        },
        files: {
          'dist/index.html': 'dist/index.html'
        }
      }
    },
    imagemin: {
      main:{
        files: [{
          expand: true, cwd:'dist/',
          src:['**/{*.png,*.jpg}'],
          dest: 'dist/'
        }]
      }
    },
    karma: {
      options: {
        frameworks: ['jasmine'],
        files: [  //this files data is also updated in the watch handler, if updated change there too
          '<%= dom_munger.data.libnocompatjs %>',
          '<%= dom_munger.data.libjs %>',
          'avConfig.js',
          '<%= dom_munger.data.appjs %>',
          '<%= ngtemplates.main.dest %>',
          'bower_components/angular-mocks/angular-mocks.js',
          createFolderGlobs('*-spec.js')
        ],
        logLevel:'ERROR',
        reporters:['mocha'],
        autoWatch: false, //watching is handled by grunt-contrib-watch
        singleRun: true
      },
      all_tests: {
        browsers: ['PhantomJS','Chrome','Firefox']
      },
      during_watch: {
        browsers: ['PhantomJS']
      },
    },
    protractor: {
      options: {
        configFile: "node_modules/protractor/referenceConf.js", // Default config file
        keepAlive: true, // If false, the grunt process stops when the test fails.
        noColor: false, // If true, protractor will not use colors in its output.
        args: {
        // Arguments passed to the command
      }
    },
    //your_target: {   // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
      all: {
      options: {
        configFile: "e2e.conf.js", // Target-specific config file
        args: {} // Target-specific arguments
      }
    },
  },

  });

  grunt.registerTask('build',['jshint','clean:before','less','autoprefixer','dom_munger','ngtemplates','cssmin','concat','ngAnnotate','uglify','copy','htmlmin','imagemin','clean:after']);
  grunt.registerTask('serve', ['dom_munger:read','jshint','connect', 'watch']);
  grunt.registerTask('test',['dom_munger:read','karma:all_tests']);

  grunt.event.on('watch', function(action, filepath) {
    //https://github.com/gruntjs/grunt-contrib-watch/issues/156

    var tasksToRun = [];

    if ((filepath.lastIndexOf('.json') !== -1 && filepath.lastIndexOf('.json') === filepath.length - 5) ||
        (filepath.lastIndexOf('.js') !== -1 && filepath.lastIndexOf('.js') === filepath.length - 3)) {

      //lint the changed js file
      grunt.config('jshint.main.src', filepath);
      tasksToRun.push('jshint');

      //find the appropriate unit t est for the changed file
      var spec = filepath;
      if (filepath.lastIndexOf('-spec.js') === -1 || filepath.lastIndexOf('-spec.js') !== filepath.length - 8) {
        spec = filepath.substring(0,filepath.length - 3) + '-spec.js';
      }

      //if the spec exists then lets run it
      if (grunt.file.exists(spec)) {
        var files = [].concat(grunt.config('dom_munger.data.libnocompatjs'));
        files.concat(grunt.config('dom_munger.data.libjs'));
        files.push('bower_components/angular-mocks/angular-mocks.js');
        files.push('avConfig.js');
        files.concat(grunt.config('dom_munger.data.appjs'));
        files.concat(grunt.config('ngtemplates.main.dest'));
        files.push(spec);
        grunt.config('karma.options.files', files);
        tasksToRun.push('karma:during_watch');
      }
    }

    //if index.html changed, we need to reread the <script> tags so our next run of karma
    //will have the correct environment
    if (filepath === 'index.html') {
      tasksToRun.push('dom_munger:read');
    }

    grunt.config('watch.main.tasks',tasksToRun);

  });

  grunt.loadNpmTasks('grunt-protractor-runner');
};
<|endoftext|>


<commit_before>'use strict';

module.exports = function (grunt) {

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

        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            gruntfile: {
                src: 'Gruntfile.js'
            },
            lib: {
                src: ['app/**/*.js', 'lib/**/*.js']
            },
            test: {
                src: ['test/**/*.js']
            }
        },

        jscs: {
            main: ['app/**/*.js', 'lib/**/*.js', 'test/**/*.js'],
            options: {
                config: ".jscsrc"
            }
        },

        watch: {
            all: {
                files: ['app/**/*.js', 'lib/**/*.js', 'test/**/*.js', 'config/*.js'],
                tasks: ['lint', 'buster:unit']
            }
        },

        buster: {
            unit: {
            }
        },
        nodemon: {
            dev: {
                options: {
                    file: 'app/app.js',
                    args: ['-c', 'config/config-dist.js']
                },
                tasks: ['lint', 'buster:unit']
            }
        },
        shell: {
            multiple: {
                command: [
                    'rm -rf artifact',
                    'mkdir -p artifact',
                    'mv node_modules ../node_modules2',
                    'npm install --production',
                    'tar -zcf artifact/node-boilerplate.tar.gz .',
                    'rm -rf node_modules',
                    'mv ../node_modules2 node_modules'
                ].join('&&')
            }
        }
    });

    // These plugins provide necessary tasks.
    grunt.loadNpmTasks('grunt-contrib-nodeunit');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-nodemon');
    grunt.loadNpmTasks('grunt-shell');
    grunt.loadNpmTasks('grunt-buster');
    grunt.loadNpmTasks("grunt-jscs");

    // Default task.
    grunt.registerTask( "lint", [ "jshint", "jscs" ] );
    grunt.registerTask('default', ['lint', 'buster:unit']);
    grunt.registerTask('test', 'buster:unit');
    grunt.registerTask('check', ['watch']);
    grunt.registerTask('run', ['buster:unit', 'nodemon:dev']);
    grunt.registerTask('artifact', ['shell']);

};
<commit_msg>Added coveralls.<commit_after>'use strict';

module.exports = function (grunt) {

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

        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            gruntfile: {
                src: 'Gruntfile.js'
            },
            lib: {
                src: ['app/**/*.js', 'lib/**/*.js']
            },
            test: {
                src: ['test/**/*.js']
            }
        },

        jscs: {
            main: ['app/**/*.js', 'lib/**/*.js', 'test/**/*.js'],
            options: {
                config: ".jscsrc"
            }
        },

        watch: {
            all: {
                files: ['app/**/*.js', 'lib/**/*.js', 'test/**/*.js', 'config/*.js'],
                tasks: ['lint', 'buster:unit']
            }
        },

        buster: {
            unit: {
            }
        },
        nodemon: {
            dev: {
                options: {
                    file: 'app/app.js',
                    args: ['-c', 'config/config-dist.js']
                },
                tasks: ['lint', 'buster:unit']
            }
        },
        shell: {
            multiple: {
                command: [
                    'rm -rf artifact',
                    'mkdir -p artifact',
                    'mv node_modules ../node_modules2',
                    'npm install --production',
                    'tar -zcf artifact/node-boilerplate.tar.gz .',
                    'rm -rf node_modules',
                    'mv ../node_modules2 node_modules'
                ].join('&&')
            }
        },
        coveralls: {
            real_coverage: {
                src: 'coverage/lcov.info'
            }
        }
    });

    // These plugins provide necessary tasks.
    grunt.loadNpmTasks('grunt-contrib-nodeunit');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-nodemon');
    grunt.loadNpmTasks('grunt-shell');
    grunt.loadNpmTasks('grunt-buster');
    grunt.loadNpmTasks("grunt-jscs");
    grunt.loadNpmTasks('grunt-coveralls');

    // Default task.
    grunt.registerTask( "lint", [ "jshint", "jscs" ] );
    grunt.registerTask('default', ['lint', 'buster:unit']);
    grunt.registerTask('test', 'buster:unit');
    grunt.registerTask('check', ['watch']);
    grunt.registerTask('run', ['buster:unit', 'nodemon:dev']);
    grunt.registerTask('artifact', ['shell', 'coveralls:real_coverage']);

};
<|endoftext|>


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

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %>#<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */'
            },
            build: {
                files: {
                    'vendor/sy/framework.min.js': [
                        'vendor/sy/src/functions.js',
                        'vendor/sy/src/Lib/Generator/Interface.js',
                        'vendor/sy/src/Lib/Generator/UUID.js',
                        'vendor/sy/src/Lib/Logger/Handler/Interface.js',
                        'vendor/sy/src/Lib/Logger/Handler/Console.js',
                        'vendor/sy/src/Lib/Logger/Interface.js',
                        'vendor/sy/src/Lib/Logger/CoreLogger.js',
                        'vendor/sy/src/Lib/Mediator.js',
                        'vendor/sy/src/HTTP/RequestInterface.js',
                        'vendor/sy/src/HTTP/Request.js',
                        'vendor/sy/src/HTTP/HTMLRequest.js',
                        'vendor/sy/src/HTTP/JSONRequest.js',
                        'vendor/sy/src/HTTP/ResponseInterface.js',
                        'vendor/sy/src/HTTP/Response.js',
                        'vendor/sy/src/HTTP/HTMLResponse.js',
                        'vendor/sy/src/HTTP/JSONResponse.js',
                        'vendor/sy/src/HTTP/HeaderParser.js',
                        'vendor/sy/src/HTTP/Manager.js',
                        'vendor/sy/src/HTTP/REST.js',
                        'vendor/sy/src/Storage/Core.js',
                        'vendor/sy/src/Storage/EngineInterface.js',
                        'vendor/sy/src/Storage/EngineFactory.js',
                        'vendor/sy/src/Storage/Engine/IndexedDB.js',
                        'vendor/sy/src/Storage/Engine/Localstorage.js',
                        'vendor/sy/src/Storage/Engine/Rest.js',
                        'vendor/sy/src/Storage/Manager.js',
                        'vendor/sy/src/Storage/ManagerFactory.js',
                        'vendor/sy/src/Storage/RepositoryInterface.js',
                        'vendor/sy/src/Storage/Repository.js',
                        'vendor/sy/src/Storage/RepositoryFactory.js',
                        'vendor/sy/src/ConfiguratorInterface.js',
                        'vendor/sy/src/Configurator.js',
                        'vendor/sy/src/ControllerInterface.js',
                        'vendor/sy/src/Controller.js',
                        'vendor/sy/src/EntityInterface.js',
                        'vendor/sy/src/Entity.js',
                        'vendor/sy/src/FactoryInterface.js',
                        'vendor/sy/src/QueueInterface.js',
                        'vendor/sy/src/Queue.js',
                        'vendor/sy/src/RegistryInterface.js',
                        'vendor/sy/src/Registry.js',
                        'vendor/sy/src/ServiceContainerInterface.js',
                        'vendor/sy/src/ServiceContainer.js',
                        'vendor/sy/src/ServiceInterface.js',
                        'vendor/sy/bootstrap.js'
                    ]
                }
            }
        },
        'bower-install': {
            target: {
                html: 'index.html',
                jsPattern: '<script src="{{filePath}}"></script>'
            }
        },
        shell: {
            syTests: {
                command: function (pkg) {
                    var path;

                    switch (pkg) {
                        case 'lib':
                            path = 'lib/';
                            break;
                        case 'storage':
                            path = 'storage/';
                            break;
                        case 'topLevel':
                            path = [
                                'entity.js',
                                'functions.js',
                                'queue.js',
                                'registry.js',
                                'registryfactory.js',
                                'queuefactory.js',
                                'servicecontainer.js',
                            ].join(',vendor/sy/tests/');
                            break;
                    }

                    return 'venus run -t vendor/sy/tests/' + path + ' -n';
                },
                options: {
                    stdout: true
                }
            }
        },
        watch: {
            js: {
                files: ['vendor/sy/src/*.js'],
                tasks: [],
                options: {
                    livereload: true
                }
            }
        },
        jscs: {
            src: 'vendor/sy/src/**/*.js',
            options: {
                requireCurlyBraces: [
                    'if',
                    'else',
                    'for',
                    'do',
                    'while',
                    'try',
                    'catch',
                ],
                requireSpaceAfterKeywords: [
                    'if',
                    'else',
                    'for',
                    'do',
                    'while',
                    'switch',
                    'try',
                    'catch'
                ],
                requireParenthesesAroundIIFE: true,
                requireSpacesInFunctionExpression: {
                    beforeOpeningRoundBrace: true,
                    beforeOpeningCurlyBrace: true
                },
                disallowSpacesInsideObjectBrackets: true,
                disallowSpacesInsideArrayBrackets: true,
                disallowSpacesInsideParentheses: true,
                disallowQuotedKeysInObjects: true,
                disallowSpaceAfterObjectKeys: true,
                requireCommaBeforeLineBreak: true,
                requireOperatorBeforeLineBreak: [
                    '?',
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!==',
                    '>',
                    '>=',
                    '<',
                    '<='
                ],
                disallowLeftStickedOperators: [
                    '?',
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!==',
                    '>',
                    '>=',
                    '<',
                    '<='
                ],
                requireRightStickedOperators: ['!'],
                disallowRightStickedOperators: [
                    '?',
                    '+',
                    '/',
                    '*',
                    ':',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!==',
                    '>',
                    '>=',
                    '<',
                    '<='
                ],
                requireLeftStickedOperators: [','],
                disallowSpaceAfterPrefixUnaryOperators: [
                    '++',
                    '--',
                    '+',
                    '-',
                    '~',
                    '!'
                ],
                disallowSpaceBeforePostfixUnaryOperators: [
                    '++',
                    '--'
                ],
                requireSpaceBeforeBinaryOperators: [
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!=='
                ],
                requireSpaceAfterBinaryOperators: [
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!=='
                ],
                requireCamelCaseOrUpperCaseIdentifiers: true,
                disallowKeywords: ["with"],
                disallowMultipleLineBreaks: true,
                validateQuoteMarks: '\'',
                disallowMixedSpacesAndTabs: true,
                disallowTrailingWhitespace: true,
                disallowKeywordsOnNewLine: ['else'],
                requireDotNotation: true,
                validateJSDoc: {
                    checkParamNames: true,
                    checkRedundantParams: true,
                    requireParamTypes: true
                }
            }
        }
    });

    require('load-grunt-tasks')(grunt);

    grunt.registerTask('default', ['bower-install']);
    grunt.registerTask('test', [
        'jscs',
        'shell:syTests:lib',
        'shell:syTests:storage',
        'shell:syTests:topLevel'
    ]);

};
<commit_msg>#16 translator added to tests suites<commit_after>module.exports = function (grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %>#<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */'
            },
            build: {
                files: {
                    'vendor/sy/framework.min.js': [
                        'vendor/sy/src/functions.js',
                        'vendor/sy/src/Lib/Generator/Interface.js',
                        'vendor/sy/src/Lib/Generator/UUID.js',
                        'vendor/sy/src/Lib/Logger/Handler/Interface.js',
                        'vendor/sy/src/Lib/Logger/Handler/Console.js',
                        'vendor/sy/src/Lib/Logger/Interface.js',
                        'vendor/sy/src/Lib/Logger/CoreLogger.js',
                        'vendor/sy/src/Lib/Mediator.js',
                        'vendor/sy/src/HTTP/RequestInterface.js',
                        'vendor/sy/src/HTTP/Request.js',
                        'vendor/sy/src/HTTP/HTMLRequest.js',
                        'vendor/sy/src/HTTP/JSONRequest.js',
                        'vendor/sy/src/HTTP/ResponseInterface.js',
                        'vendor/sy/src/HTTP/Response.js',
                        'vendor/sy/src/HTTP/HTMLResponse.js',
                        'vendor/sy/src/HTTP/JSONResponse.js',
                        'vendor/sy/src/HTTP/HeaderParser.js',
                        'vendor/sy/src/HTTP/Manager.js',
                        'vendor/sy/src/HTTP/REST.js',
                        'vendor/sy/src/Storage/Core.js',
                        'vendor/sy/src/Storage/EngineInterface.js',
                        'vendor/sy/src/Storage/EngineFactory.js',
                        'vendor/sy/src/Storage/Engine/IndexedDB.js',
                        'vendor/sy/src/Storage/Engine/Localstorage.js',
                        'vendor/sy/src/Storage/Engine/Rest.js',
                        'vendor/sy/src/Storage/Manager.js',
                        'vendor/sy/src/Storage/ManagerFactory.js',
                        'vendor/sy/src/Storage/RepositoryInterface.js',
                        'vendor/sy/src/Storage/Repository.js',
                        'vendor/sy/src/Storage/RepositoryFactory.js',
                        'vendor/sy/src/ConfiguratorInterface.js',
                        'vendor/sy/src/Configurator.js',
                        'vendor/sy/src/ControllerInterface.js',
                        'vendor/sy/src/Controller.js',
                        'vendor/sy/src/EntityInterface.js',
                        'vendor/sy/src/Entity.js',
                        'vendor/sy/src/FactoryInterface.js',
                        'vendor/sy/src/QueueInterface.js',
                        'vendor/sy/src/Queue.js',
                        'vendor/sy/src/RegistryInterface.js',
                        'vendor/sy/src/Registry.js',
                        'vendor/sy/src/ServiceContainerInterface.js',
                        'vendor/sy/src/ServiceContainer.js',
                        'vendor/sy/src/ServiceInterface.js',
                        'vendor/sy/bootstrap.js'
                    ]
                }
            }
        },
        'bower-install': {
            target: {
                html: 'index.html',
                jsPattern: '<script src="{{filePath}}"></script>'
            }
        },
        shell: {
            syTests: {
                command: function (pkg) {
                    var path;

                    switch (pkg) {
                        case 'lib':
                            path = 'lib/';
                            break;
                        case 'storage':
                            path = 'storage/';
                            break;
                        case 'topLevel':
                            path = [
                                'entity.js',
                                'functions.js',
                                'queue.js',
                                'registry.js',
                                'registryfactory.js',
                                'queuefactory.js',
                                'servicecontainer.js',
                                'translator.js',
                            ].join(',vendor/sy/tests/');
                            break;
                    }

                    return 'venus run -t vendor/sy/tests/' + path + ' -n';
                },
                options: {
                    stdout: true
                }
            }
        },
        watch: {
            js: {
                files: ['vendor/sy/src/*.js'],
                tasks: [],
                options: {
                    livereload: true
                }
            }
        },
        jscs: {
            src: 'vendor/sy/src/**/*.js',
            options: {
                requireCurlyBraces: [
                    'if',
                    'else',
                    'for',
                    'do',
                    'while',
                    'try',
                    'catch',
                ],
                requireSpaceAfterKeywords: [
                    'if',
                    'else',
                    'for',
                    'do',
                    'while',
                    'switch',
                    'try',
                    'catch'
                ],
                requireParenthesesAroundIIFE: true,
                requireSpacesInFunctionExpression: {
                    beforeOpeningRoundBrace: true,
                    beforeOpeningCurlyBrace: true
                },
                disallowSpacesInsideObjectBrackets: true,
                disallowSpacesInsideArrayBrackets: true,
                disallowSpacesInsideParentheses: true,
                disallowQuotedKeysInObjects: true,
                disallowSpaceAfterObjectKeys: true,
                requireCommaBeforeLineBreak: true,
                requireOperatorBeforeLineBreak: [
                    '?',
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!==',
                    '>',
                    '>=',
                    '<',
                    '<='
                ],
                disallowLeftStickedOperators: [
                    '?',
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!==',
                    '>',
                    '>=',
                    '<',
                    '<='
                ],
                requireRightStickedOperators: ['!'],
                disallowRightStickedOperators: [
                    '?',
                    '+',
                    '/',
                    '*',
                    ':',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!==',
                    '>',
                    '>=',
                    '<',
                    '<='
                ],
                requireLeftStickedOperators: [','],
                disallowSpaceAfterPrefixUnaryOperators: [
                    '++',
                    '--',
                    '+',
                    '-',
                    '~',
                    '!'
                ],
                disallowSpaceBeforePostfixUnaryOperators: [
                    '++',
                    '--'
                ],
                requireSpaceBeforeBinaryOperators: [
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!=='
                ],
                requireSpaceAfterBinaryOperators: [
                    '+',
                    '-',
                    '/',
                    '*',
                    '=',
                    '==',
                    '===',
                    '!=',
                    '!=='
                ],
                requireCamelCaseOrUpperCaseIdentifiers: true,
                disallowKeywords: ["with"],
                disallowMultipleLineBreaks: true,
                validateQuoteMarks: '\'',
                disallowMixedSpacesAndTabs: true,
                disallowTrailingWhitespace: true,
                disallowKeywordsOnNewLine: ['else'],
                requireDotNotation: true,
                validateJSDoc: {
                    checkParamNames: true,
                    checkRedundantParams: true,
                    requireParamTypes: true
                }
            }
        }
    });

    require('load-grunt-tasks')(grunt);

    grunt.registerTask('default', ['bower-install']);
    grunt.registerTask('test', [
        'jscs',
        'shell:syTests:lib',
        'shell:syTests:storage',
        'shell:syTests:topLevel'
    ]);

};
<|endoftext|>


<commit_before>
import { Component } from "react";
import { connect } from "react-redux";
import moment from "moment";

import { give as giveActions } from "../../../../data/store";

import Layout from "./Layout";

type IScheduleProps = {
  authorized: boolean,
  saveSchedule: Function,
  setCanCheckout: Function,
  preCheck: boolean,
  bindSubComponentReset: Function,
};

type IScheduleState = {
  checked: boolean;
  showDatePicker: boolean,
  start: string,
  frequency: string,
};

const GIVING_SCHEDULES = [
  { label: "One time", value: "One-Time" },
  { label: "Every Month", value: "Monthly" },
  { label: "Every Week", value: "Weekly" },
  { label: "Every 2 Weeks", value: "Bi-Weekly" },
];

const nextMonth = moment().endOf("Month").add(1, "days");
const START_DATES = [
  { label: "Tomorrow", value: moment().add(1, "days").toISOString() },
  { label: nextMonth.format("MMM D"), value: nextMonth.toISOString() },
  { label: "Custom", value: "custom" },
];

export class Schedule extends Component {

  props: IScheduleProps;
  state: IScheduleState;

  state = {
    checked: false,
    start: null,
    frequency: null,
    showDatePicker: false,
  }

  componentWillMount() {
    if (this.props.preCheck) this.setState({ checked: true });
    this.props.bindSubComponentReset(this.toggleSchedule);
  }

  componentDidMount() {
    if (typeof window !== "undefined") {
      window.addEventListener("resize", this.fixPickerPosition);
    }
  }

  componentDidUpdate(_, { checked, start, frequency }) {
    if (this.state.checked && !checked) {
      this.props.setCanCheckout(false);
      return;
    }

    if (!this.state.checked && checked) {
      this.props.setCanCheckout(true);
      return;
    }

    if (
      (this.state.start && this.state.frequency) &&
      (!start || !frequency)
    ) {
      this.props.setCanCheckout(true);
      return;
    }

    if (
      (!this.state.start && start) ||
      (!this.state.frequency && frequency)
    ) {
      this.props.setCanCheckout(false);
      return;
    }
  }

  componentWillUnmount() {
    if (typeof window !== "undefined") {
      window.removeEventListener("resize", this.fixPickerPosition);
    }
  }

  fixPickerPosition = () => {
    const picker = document.getElementById("datepicker");
    if (!picker) return;

    const child = picker.children[0];
    const globalTop = Number(child.getBoundingClientRect().top);
    if (globalTop < 0) {
      const marginTop = Number(child.style.marginTop.slice(0, -2));
      child.style.marginTop = `${marginTop + Math.abs(globalTop)}px`;
    }
  }

  toggleDatePicker = () => {
    this.setState(({ showDatePicker }) => ({ showDatePicker: !showDatePicker }));
    setTimeout(() => {
      this.fixPickerPosition();
    }, 200);
  }

  toggleSchedule = () => {
    this.setState(({ checked }) => {
      if (!checked) return { checked: true };

      this.props.saveSchedule({
        frequency: null,
        start: null,
      });

      return {
        frequency: null,
        start: null,
        checked: false,
      };
    });
  }

  /*
    if one is selected, and freqClick is called with the same one, disable it
    if one is selected, and freqClick is called with another one, SET THAT ONE
    if one is not selected, set it
  */
  frequencyClick = (value: string) => {
    let newValue = value;
    if (this.state.frequency === newValue) newValue = null;

    this.setState({ frequency: newValue });
    this.props.saveSchedule({
      frequency: newValue,
      start: this.state.start,
    });
  }

  startClick = (value: string) => {
    let newValue = value;
    if (this.state.start === newValue) newValue = null;

    if (this.state.start || value !== "custom") {
      this.setState({ start: newValue });
      this.props.saveSchedule({
        frequency: this.state.frequency,
        start: newValue,
      });
      return;
    }

    this.setState(({ showDatePicker }) => ({ showDatePicker: !showDatePicker }));
  }

  onDayClick = (e, day, { selected, disabled }) => {
    if (disabled) return;
    this.setState({ start: selected ? null : day });
    this.props.saveSchedule({
      frequency: this.state.frequency,
      start: day,
    });
  }

  render() {
    const { authorized } = this.props;
    if (!authorized) return null;
    const { checked, start, showDatePicker } = this.state;

    return (
      <Layout
        GIVING_SCHEDULES={GIVING_SCHEDULES}
        START_DATES={START_DATES}
        checked={checked}
        frequencyClick={this.frequencyClick}
        onDayClick={this.onDayClick}
        showDatePicker={showDatePicker}
        start={start}
        startClick={this.startClick}
        toggleDatePicker={this.toggleDatePicker}
        toggleSchedule={this.toggleSchedule}
      />
    );
  }
}

export const map = ({ routing: { location } }) => ({
  preCheck: location && location.query && location.query.schedule,
});

export const withGiveActions = connect(map, giveActions);

export default withGiveActions(Schedule);
<commit_msg>fixed tag select --untested<commit_after>
import { Component } from "react";
import { connect } from "react-redux";
import moment from "moment";

import { give as giveActions } from "../../../../data/store";

import Layout from "./Layout";

type IScheduleProps = {
  authorized: boolean,
  saveSchedule: Function,
  setCanCheckout: Function,
  preCheck: boolean,
  bindSubComponentReset: Function,
};

type IScheduleState = {
  checked: boolean;
  showDatePicker: boolean,
  start: string,
  frequency: string,
};

const GIVING_SCHEDULES = [
  { label: "One time", value: "One-Time" },
  { label: "Every Month", value: "Monthly" },
  { label: "Every Week", value: "Weekly" },
  { label: "Every 2 Weeks", value: "Bi-Weekly" },
];

const nextMonth = moment().endOf("Month").add(1, "days");
const START_DATES = [
  { label: "Tomorrow", value: moment().add(1, "days").toISOString() },
  { label: nextMonth.format("MMM D"), value: nextMonth.toISOString() },
  { label: "Custom", value: "custom" },
];

export class Schedule extends Component {

  props: IScheduleProps;
  state: IScheduleState;

  state = {
    checked: false,
    start: null,
    frequency: null,
    showDatePicker: false,
  }

  componentWillMount() {
    if (this.props.preCheck) this.setState({ checked: true });
    this.props.bindSubComponentReset(this.toggleSchedule);
  }

  componentDidMount() {
    if (typeof window !== "undefined") {
      window.addEventListener("resize", this.fixPickerPosition);
    }
  }

  componentDidUpdate(_, { checked, start, frequency }) {
    if (this.state.checked && !checked) {
      this.props.setCanCheckout(false);
      return;
    }

    if (!this.state.checked && checked) {
      this.props.setCanCheckout(true);
      return;
    }

    if (
      (this.state.start && this.state.frequency) &&
      (!start || !frequency)
    ) {
      this.props.setCanCheckout(true);
      return;
    }

    if (
      (!this.state.start && start) ||
      (!this.state.frequency && frequency)
    ) {
      this.props.setCanCheckout(false);
      return;
    }
  }

  componentWillUnmount() {
    if (typeof window !== "undefined") {
      window.removeEventListener("resize", this.fixPickerPosition);
    }
  }

  fixPickerPosition = () => {
    const picker = document.getElementById("datepicker");
    if (!picker) return;

    const child = picker.children[0];
    const globalTop = Number(child.getBoundingClientRect().top);
    if (globalTop < 0) {
      const marginTop = Number(child.style.marginTop.slice(0, -2));
      child.style.marginTop = `${marginTop + Math.abs(globalTop)}px`;
    }
  }

  toggleDatePicker = () => {
    this.setState(({ showDatePicker }) => ({ showDatePicker: !showDatePicker }));
    setTimeout(() => {
      this.fixPickerPosition();
    }, 200);
  }

  toggleSchedule = () => {
    this.setState(({ checked }) => {
      if (!checked) return { checked: true };

      this.props.saveSchedule({
        frequency: null,
        start: null,
      });

      return {
        frequency: null,
        start: null,
        checked: false,
      };
    });
  }

  /*
    if one is selected, and freqClick is called with the same one, disable it
    if one is selected, and freqClick is called with another one, SET THAT ONE
    if one is not selected, set it
  */
  frequencyClick = (value: string) => {
    let newValue = value;
    if (this.state.frequency === newValue) newValue = null;

    this.setState({ frequency: newValue });
    this.props.saveSchedule({
      frequency: newValue,
      start: this.state.start,
    });
  }

  startClick = (value: string) => {
    const filtered = START_DATES.find(x => moment(x.value).isSame(value, "day"));
    const label = filtered ? filtered.label : "Custom"; // the tag label

    // DATETIME || "custom"
    const newValue = this.state.start === value ? null : value;
    const newStartTag = this.state.activeStartTag === label ? null : label;

    // other tags have a start date, so update schedule
    if (value !== "custom") {
      this.setState(s => ({ start: newValue, activeStartTag: newStartTag }));
      this.props.saveSchedule({
        frequency: this.state.frequency,
        start: newValue,
      });
      return;
    }

    // custom doesn't need to save schedule.
    // toggle date picker and clear previous set start dates
    this.setState(({activeStartTag}) => ({ showDatePicker: activeStartTag !== "Custom", start: null, activeStartTag: newStartTag }));
  }

  onDayClick = (e, day, { selected, disabled }) => {
    if (disabled) return;
    this.setState({ start: selected ? null : day });
    this.props.saveSchedule({
      frequency: this.state.frequency,
      start: day,
    });
  }

  render() {
    const { authorized } = this.props;
    if (!authorized) return null;
    const { checked, start, showDatePicker } = this.state;

    return (
      <Layout
        GIVING_SCHEDULES={GIVING_SCHEDULES}
        START_DATES={START_DATES}
        checked={checked}
        frequencyClick={this.frequencyClick}
        onDayClick={this.onDayClick}
        showDatePicker={showDatePicker}
        start={start}
        startClick={this.startClick}
        toggleDatePicker={this.toggleDatePicker}
        toggleSchedule={this.toggleSchedule}
      />
    );
  }
}

export const map = ({ routing: { location } }) => ({
  preCheck: location && location.query && location.query.schedule,
});

export const withGiveActions = connect(map, giveActions);

export default withGiveActions(Schedule);
<|endoftext|>