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

  grunt.loadNpmTasks('grunt-tizen');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadTasks('tools/grunt-tasks');

  grunt.initConfig({
    packageInfo: grunt.file.readJSON('package.json'),
    chromeInfo: grunt.file.readJSON('data/manifest.json'),

    clean: ['build'],

    tizen_configuration: {
      // location on the device to install the tizen-app.sh script to
      // (default: '/tmp')
      tizenAppScriptDir: '/home/developer/',

      // path to the config.xml file for the Tizen wgt file
      // (default: 'config.xml')
      configFile: 'data/config.xml',

      // path to the sdb command (default: process.env.SDB or 'sdb')
      sdbCmd: 'sdb'
    },

    // minify JS
    uglify: {
      dist: {
        files: {
          'build/app/js/contextmenu.js': ['app/js/contextmenu.js'],
          'build/app/js/date.js': ['app/js/date.js'],
          'build/app/js/en_default.js': ['app/js/en_default.js'],
          'build/app/js/helper.js': ['app/js/helper.js'],
          'build/app/js/iscroll-lite.js': ['app/js/iscroll-lite.js'],
          'build/app/js/jquery-1.7.1.min.js': ['app/js/jquery-1.7.1.min.js'],
          'build/app/js/jquery.mobile-1.0.min.js': ['app/js/jquery.mobile-1.0.min.js'],
          'build/app/js/jquery-ui-1.8.17.custom.min.js': ['app/js/jquery-ui-1.8.17.custom.min.js'],
          'build/app/js/license.js': ['app/js/license.js'],
          'build/app/js/movetodate.js': ['app/js/movetodate.js'],
          'build/app/js/settings-backend.js': ['app/js/settings-backend.js'],
          'build/app/js/todo-backend.js': ['app/js/todo-backend.js'],
          'build/app/js/todo.js': ['app/js/todo.js'],
          'build/app/js/web-ui-fw.js': ['app/js/web-ui-fw.js'],
          'build/app/js/web-ui-fw-libs.js': ['app/js/web-ui-fw-libs.js']
        }
      }
    },

    // minify CSS
    cssmin: {
      dist: {
        files: {
          'build/app/css/contextmenu.css': ['app/css/contextmenu.css'],
          'build/app/css/default.css': ['app/css/default.css'],
          'build/app/css/default_landscape.css': ['app/css/default_landscape.css'],
          'build/app/css/default_portrait.css': ['app/css/default_portrait.css'],
          'build/app/css/jquery.mobile-1.0.min.css': ['app/css/jquery.mobile-1.0.min.css'],
          'build/app/css/movetodate.css': ['app/css/movetodate.css'],
          'build/app/css/todo-jquery-mobile.css': ['app/css/todo-jquery-mobile.css'],
          'build/app/css/web-ui-fw-theme.css': ['app/css/web-ui-fw-theme.css'],
          'build/app/css/web-ui-fw-widget.css': ['app/css/web-ui-fw-widget.css']
        }
      }
    },

    copy: {
      common: {
        files: [
          { expand: true, cwd: '.', src: ['app/css/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/fonts/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/audio/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['LICENSE'], dest: 'build/app/' },
          { expand: true, cwd: 'app/', src: ['README.txt'], dest: 'build/app/' },
          { expand: true, cwd: '.', src: ['app/_locales/**'], dest: 'build/' }
        ]
      },
      wgt: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/wgt/' },
          { expand: true, cwd: 'data/', src: ['config.xml'], dest: 'build/wgt/' },
          { expand: true, cwd: '.', src: ['icon_128.png'], dest: 'build/wgt/' }
        ]
      },
      crx: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['manifest.json'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/crx/' }
        ]
      },
      sdk: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/sdk/' },
          { expand: true, cwd: '.', src: ['app/css/*.css'], dest: 'build/sdk/css/' },
          { expand: true, cwd: '.', src: ['app/js/*.js'], dest: 'build/sdk/js/' },
          { expand: true, cwd: '.', src: ['app/*.html'], dest: 'build/sdk/' },
          { expand: true, cwd: 'data/', src: ['config.xml'], dest: 'build/sdk/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/sdk/' }
        ]
      }
    },

    htmlmin: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: ['app/*.html'], dest: 'build/' }
        ],
        options: {
          removeComments: true,
          collapseWhitespace: true,
          removeCommentsFromCDATA: false,
          removeCDATASectionsFromCDATA: false,
          removeEmptyAttributes: true,
          removeEmptyElements: false
        }
      }
    },

    imagemin: {
      dist: {
        options: {
          optimizationLevel: 3,
          progressive: true
        },
        files: [
          { expand: true, cwd: '.', src: ['app/images/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/css/images/**'], dest: 'build/' }
        ]
      }
    },

    // make wgt package in build/ directory
    package: {
      wgt: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/wgt/**',
        stripPrefix: 'build/wgt/',
        outDir: 'build',
        suffix: '.wgt',
        addGitCommitId: false
      },
      sdk: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/sdk/**',
        stripPrefix: 'build/sdk/',
        outDir: 'build',
        suffix: '.wgt',
      }
    },

    simple_server: {
      port: 30303,
      dir: 'build/app/'
    },

    tizen: {
      push: {
        action: 'push',
        localFiles: {
          pattern: 'build/*.wgt',
          filter: 'latest'
        },
        remoteDir: '/home/developer/'
      },

      install: {
        action: 'install',
        remoteFiles: {
          pattern: '/home/developer/Todo*.wgt',
          filter: 'latest'
        }
      },

      uninstall: {
        action: 'uninstall'
      },

      start: {
        action: 'start',
        stopOnFailure: true
      },

      stop: {
        action: 'stop',
        stopOnFailure: false
      },

      debug: {
        action: 'debug',
        browserCmd: 'google-chrome %URL%',
        localPort: 9090,
        stopOnFailure: true
      }
    }
  });

  grunt.registerTask('dist', [
    'clean',
    'imagemin:dist',
    'uglify:dist',
    'cssmin:dist',
    'htmlmin:dist',
    'copy:common'
  ]);

  grunt.registerTask('crx', ['dist', 'copy:crx']);
  grunt.registerTask('wgt', ['dist', 'copy:wgt', 'package:wgt']);

  grunt.registerTask('sdk', [
    'clean',
    'imagemin:dist',
    'copy:common',
    'copy:sdk',
    'package:sdk'
  ]);

  grunt.registerTask('perf', [
    'dist',
    'uglify:perf',
    'inline',
    'copy:wgt',
    'package:wgt'
  ]);

  grunt.registerTask('install', [
    'tizen:push',
    'tizen:stop',
    'tizen:uninstall',
    'tizen:install',
    'tizen:start'
  ]);

  grunt.registerTask('wait', function () {
    var done = this.async();
    setTimeout(function () {
      done();
    }, 10000);
  });

  grunt.registerTask('restart', ['tizen:stop', 'tizen:start']);

  grunt.registerTask('server', ['dist', 'simple_server']);

  grunt.registerTask('wgt-install', ['wgt', 'install']);
  grunt.registerTask('sdk-install', ['sdk', 'install']);

  grunt.registerTask('default', 'wgt');
};
<commit_msg>Adjusting sdk grunt target.<commit_after>module.exports = function (grunt) {

  grunt.loadNpmTasks('grunt-tizen');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadTasks('tools/grunt-tasks');

  grunt.initConfig({
    packageInfo: grunt.file.readJSON('package.json'),
    chromeInfo: grunt.file.readJSON('data/manifest.json'),

    clean: ['build'],

    tizen_configuration: {
      // location on the device to install the tizen-app.sh script to
      // (default: '/tmp')
      tizenAppScriptDir: '/home/developer/',

      // path to the config.xml file for the Tizen wgt file
      // (default: 'config.xml')
      configFile: 'data/config.xml',

      // path to the sdb command (default: process.env.SDB or 'sdb')
      sdbCmd: 'sdb'
    },

    // minify JS
    uglify: {
      dist: {
        files: {
          'build/app/js/contextmenu.js': ['app/js/contextmenu.js'],
          'build/app/js/date.js': ['app/js/date.js'],
          'build/app/js/en_default.js': ['app/js/en_default.js'],
          'build/app/js/helper.js': ['app/js/helper.js'],
          'build/app/js/iscroll-lite.js': ['app/js/iscroll-lite.js'],
          'build/app/js/jquery-1.7.1.min.js': ['app/js/jquery-1.7.1.min.js'],
          'build/app/js/jquery.mobile-1.0.min.js': ['app/js/jquery.mobile-1.0.min.js'],
          'build/app/js/jquery-ui-1.8.17.custom.min.js': ['app/js/jquery-ui-1.8.17.custom.min.js'],
          'build/app/js/license.js': ['app/js/license.js'],
          'build/app/js/movetodate.js': ['app/js/movetodate.js'],
          'build/app/js/settings-backend.js': ['app/js/settings-backend.js'],
          'build/app/js/todo-backend.js': ['app/js/todo-backend.js'],
          'build/app/js/todo.js': ['app/js/todo.js'],
          'build/app/js/web-ui-fw.js': ['app/js/web-ui-fw.js'],
          'build/app/js/web-ui-fw-libs.js': ['app/js/web-ui-fw-libs.js']
        }
      }
    },

    // minify CSS
    cssmin: {
      dist: {
        files: {
          'build/app/css/contextmenu.css': ['app/css/contextmenu.css'],
          'build/app/css/default.css': ['app/css/default.css'],
          'build/app/css/default_landscape.css': ['app/css/default_landscape.css'],
          'build/app/css/default_portrait.css': ['app/css/default_portrait.css'],
          'build/app/css/jquery.mobile-1.0.min.css': ['app/css/jquery.mobile-1.0.min.css'],
          'build/app/css/movetodate.css': ['app/css/movetodate.css'],
          'build/app/css/todo-jquery-mobile.css': ['app/css/todo-jquery-mobile.css'],
          'build/app/css/web-ui-fw-theme.css': ['app/css/web-ui-fw-theme.css'],
          'build/app/css/web-ui-fw-widget.css': ['app/css/web-ui-fw-widget.css']
        }
      }
    },

    copy: {
      common: {
        files: [
          { expand: true, cwd: '.', src: ['app/css/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/fonts/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/audio/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['LICENSE'], dest: 'build/app/' },
          { expand: true, cwd: 'app/', src: ['README.txt'], dest: 'build/app/' },
          { expand: true, cwd: '.', src: ['app/_locales/**'], dest: 'build/' }
        ]
      },
      wgt: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/wgt/' },
          { expand: true, cwd: 'data/', src: ['config.xml'], dest: 'build/wgt/' },
          { expand: true, cwd: '.', src: ['icon_128.png'], dest: 'build/wgt/' }
        ]
      },
      crx: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['manifest.json'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/crx/' }
        ]
      },
      sdk: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['js/**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['css/**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['*.html'], dest: 'build/sdk/' },
          { expand: true, cwd: 'data/', src: ['config.xml'], dest: 'build/sdk/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/sdk/' }
        ]
      }
    },

    htmlmin: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: ['app/*.html'], dest: 'build/' }
        ],
        options: {
          removeComments: true,
          collapseWhitespace: true,
          removeCommentsFromCDATA: false,
          removeCDATASectionsFromCDATA: false,
          removeEmptyAttributes: true,
          removeEmptyElements: false
        }
      }
    },

    imagemin: {
      dist: {
        options: {
          optimizationLevel: 3,
          progressive: true
        },
        files: [
          { expand: true, cwd: '.', src: ['app/images/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/css/images/**'], dest: 'build/' }
        ]
      }
    },

    // make wgt package in build/ directory
    package: {
      wgt: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/wgt/**',
        stripPrefix: 'build/wgt/',
        outDir: 'build',
        suffix: '.wgt',
        addGitCommitId: false
      },
      sdk: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/sdk/**',
        stripPrefix: 'build/sdk/',
        outDir: 'build',
        suffix: '.wgt',
      }
    },

    simple_server: {
      port: 30303,
      dir: 'build/app/'
    },

    tizen: {
      push: {
        action: 'push',
        localFiles: {
          pattern: 'build/*.wgt',
          filter: 'latest'
        },
        remoteDir: '/home/developer/'
      },

      install: {
        action: 'install',
        remoteFiles: {
          pattern: '/home/developer/Todo*.wgt',
          filter: 'latest'
        }
      },

      uninstall: {
        action: 'uninstall'
      },

      start: {
        action: 'start',
        stopOnFailure: true
      },

      stop: {
        action: 'stop',
        stopOnFailure: false
      },

      debug: {
        action: 'debug',
        browserCmd: 'google-chrome %URL%',
        localPort: 9090,
        stopOnFailure: true
      }
    }
  });

  grunt.registerTask('dist', [
    'clean',
    'imagemin:dist',
    'uglify:dist',
    'cssmin:dist',
    'htmlmin:dist',
    'copy:common'
  ]);

  grunt.registerTask('crx', ['dist', 'copy:crx']);
  grunt.registerTask('wgt', ['dist', 'copy:wgt', 'package:wgt']);

  grunt.registerTask('sdk', [
    'clean',
    'imagemin:dist',
    'copy:common',
    'copy:sdk',
    'package:sdk'
  ]);

  grunt.registerTask('perf', [
    'dist',
    'uglify:perf',
    'inline',
    'copy:wgt',
    'package:wgt'
  ]);

  grunt.registerTask('install', [
    'tizen:push',
    'tizen:stop',
    'tizen:uninstall',
    'tizen:install',
    'tizen:start'
  ]);

  grunt.registerTask('wait', function () {
    var done = this.async();
    setTimeout(function () {
      done();
    }, 10000);
  });

  grunt.registerTask('restart', ['tizen:stop', 'tizen:start']);

  grunt.registerTask('server', ['dist', 'simple_server']);

  grunt.registerTask('wgt-install', ['wgt', 'install']);
  grunt.registerTask('sdk-install', ['sdk', 'install']);

  grunt.registerTask('default', 'wgt');
};
<|endoftext|>


<commit_before>// Generated on 2014-03-28 using generator-phaser-official 0.0.8-rc-2
'use strict';
var config = require('./config.json'),
    _ = require('underscore'),
    shell = require('shelljs'),
    LIVERELOAD_PORT = 35729,
    lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});

_.str = require('underscore.string');
_.mixin(_.str.exports());

function mountFolder(connect, dir) {
  return connect.static(require('path').resolve(dir));
}

module.exports = function (grunt) {
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  grunt.initConfig({
    manifest: grunt.file.readJSON('manifest.json'),
    watch: {
      scripts: {
        files: [
          '!game/main.js',
          'game/**/*.js',
          'templates/*.tpl',
          'config.json',
          'css/**/*.css'
        ],
        options: {
          spawn: false,
          livereload: LIVERELOAD_PORT
        },
        tasks: ['build:serve']
      }
    },
    connect: {
      options: {
        port: 9000,
        // change this to '0.0.0.0' to access the server from outside
        hostname: 'localhost'
      },
      livereload: {
        options: {
          middleware: function (connect) {
            return [
              lrSnippet,
              mountFolder(connect, 'serve')
            ];
          }
        }
      }
    },
    open: {
      server: {
        path: 'http://localhost:9000'
      }
    },
    copy: {
      serve: {
        files: [
          // includes files within path and its sub-directories
          { expand: true, src: ['assets/**', 'fonts/**', 'css/**'], dest: 'serve/' },
          { expand: true, flatten: true, src: [
            'game/plugins/*{.js,.map}',
            'bower_components/*/build/*{.js,.map}',
            'bower_components/*/dist/*{.js,.map}',
            'game/index.html'
          ], dest: 'serve/' }
        ]
      },
      dist: {
        files: [
          // includes files within path and its sub-directories
          { expand: true, src: [
            'assets/**',
            'fonts/**',
            'css/**',
            'icon.png',
            'manifest.json'
          ], dest: 'dist/' },
          { expand: true, flatten: true, src: [
            'game/plugins/*{.js,.map}',
            'bower_components/*/build/*{.js,.map}',
            'bower_components/*/dist/*{.js,.map}',
            'game/index.html'
          ], dest: 'dist/' }
        ]
      },
      dev: {
        options: {
          process: function(content) {
            return grunt.template.process(content, {
              data: {
                dependencies: [
                  'cordova.js',
                  'phaser.js',
                  'phaser-state-transition-plugin.min.js',
                  'game.js'
                ]
              }
            });
          }
        },
        files: [
          { src: 'game/config/config.dev.json', dest: 'game/config.json' },
          { src: 'templates/_index.html.tpl', dest: 'game/index.html' }
        ]
      },
      prod: {
        options: {
          process: function(content) {
            return grunt.template.process(content, {
              data: {
                dependencies: [
                  'cordova.js',
                  'phaser.js',
                  'phaser-state-transition-plugin.min.js',
                  'game.js'
                ]
              }
            });
          }
        },
        files: [
          { src: 'game/config/config.prod.json', dest: 'game/config.json' },
          { src: 'templates/_index.html.tpl', dest: 'game/index.html' }
        ]
      }
    },
    browserify: {
      serve: {
        src: ['game/main.js'],
        dest: 'serve/game.js'
      },
      dist: {
        src: ['game/main.js'],
        dest: 'dist/game.js'
        // dest: '.cache/game.js'
      }
    },
    uglify: {
      dist: {
        // files: {
        //   'dist/game.min.js': ['.cache/game.js']
        // }
      },
      serve: {}
    },
    clean: {
      serve: ['serve'],
      dist: ['dist', 'build'],
    },
    shell: {
      options: {
        stderr: false
      },
      buildAndroid: {
        command: './build_android.sh <%= manifest.package %> <%= manifest.name %> <%= manifest.version %>'
      },
      installAndroidx86: {
        command: 'adb install -r build/*_x86.apk'
      },
      installAndroidarm: {
        command: 'adb install -r build/*_arm.apk'
      },
      restartAdb: {
        command: [
          'sudo $(which adb) kill-server',
          'sudo $(which adb) start-server',
          'adb devices'
        ].join('&&')
      },
      prepareCordova: {
        command: [
          'rm -rf www',
          'cp -a dist www'
        ].join('&&')
      }
    },
    bump: {
      options: {
        files: ['package.json', 'bower.json', 'manifest.json', 'config.xml'],
        updateConfigs: [],
        commit: true,
        commitMessage: 'Release %VERSION%',
        commitFiles: ['package.json', 'bower.json', 'manifest.json', 'config.xml'],
        createTag: false,
        tagName: '%VERSION%',
        tagMessage: 'Version %VERSION%',
        push: false,
        pushTo: 'upstream',
        gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
      }
    },
    jshint: {
      all: ['game/**/*.js', 'Gruntfile.js'],
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      }
    },
    jscs: {
      src: [
        'game/**/*.js',
        '!game/main.js',
        '!game/plugins/*'
      ],
      options: {
        config: '.jscsrc',
        reporter: require('jscs-stylish').path
      }
    },
    githooks: {
      all: {
        'pre-commit': 'jshint jscs',
      }
    },
    'notify_hooks': {
      options: {
        enabled: true,
        'max_jshint_notifications': 5, // maximum number of notifications from jshint output
        success: true, // whether successful grunt executions should be notified automatically
        duration: 3 // the duration of notification in seconds, for `notify-send only
      }
    },
  });

  // Register Grunt Tasks
  grunt.registerTask('default', 'serve');
  grunt.registerTask('build', function(dest) {
    grunt.task.run([
      'buildBootstrapper',
      'browserify:' + (dest || 'dist'),
      'uglify:' + (dest || 'dist'),
      'copy:' + (dest || 'dist'),
      'notify_hooks'
    ]);
  });
  grunt.registerTask('serve', function(environment) {
    grunt.task.run([
      'githooks',
      'clean:serve',
      'copy:' + (environment || 'dev'),
      'build:serve',
      'connect:livereload',
      'open',
      'watch'
    ]);
  });
  grunt.registerTask('buildAndroid', function(environment) {
    grunt.task.run([
      'clean:dist',
      'copy:' + (environment || 'prod'),
      'build:dist',
      'shell:buildAndroid',
      'notify_hooks'
    ]);
  });
  grunt.registerTask('restartAdb', ['shell:restartAdb']);
  grunt.registerTask('installAndroid', function(arch) {
    // arch is x86 (Intel based tablets) or arm (non-Intel)
    grunt.task.run(['shell:installAndroid' + (arch || 'arm'), 'notify_hooks']);
  });
  grunt.registerTask('buildBootstrapper', function() {
    var stateFiles = grunt.file.expand('game/states/*.js'),
        gameStates = [],
        statePattern = new RegExp(/(\w+).js$/),
        bootstrapper = grunt.file.read('templates/_main.js.tpl');

    stateFiles.forEach(function(file) {
      var state = file.match(statePattern)[1];
      if (!!state) {
        gameStates.push({shortName: state, stateName: _.capitalize(state) + 'State'});
      }
    });
    config.gameStates = gameStates;
    bootstrapper = grunt.template.process(bootstrapper, {data: config});
    grunt.file.write('game/main.js', bootstrapper);
  });
  grunt.registerTask('cordovaSetup', function(environment) {
    var pkg = grunt.file.readJSON('package.json');

    if (!pkg.platforms) {
      return grunt.log.error('Platforms not found.');
    }
    _.forEach(pkg.platforms, function (platform) {
      grunt.log.writeln('Installing platform ' + platform);
      shell.exec('cordova platform add ' + platform);
    });
    _.forEach(pkg.plugins, function (plugin) {
      grunt.log.writeln('Installing plugin ' + plugin);
      shell.exec('cordova plugin add ' + plugin);
    });
    grunt.task.run([
      'clean:dist',
      'copy:' + (environment || 'prod'),
      'build:dist',
      'shell:prepareCordova'
    ]);
  });
};
<commit_msg>fix(cordovaSetup): prepares www directory before installing platforms<commit_after>// Generated on 2014-03-28 using generator-phaser-official 0.0.8-rc-2
'use strict';
var config = require('./config.json'),
    _ = require('underscore'),
    shell = require('shelljs'),
    LIVERELOAD_PORT = 35729,
    lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});

_.str = require('underscore.string');
_.mixin(_.str.exports());

function mountFolder(connect, dir) {
  return connect.static(require('path').resolve(dir));
}

module.exports = function (grunt) {
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  grunt.initConfig({
    manifest: grunt.file.readJSON('manifest.json'),
    watch: {
      scripts: {
        files: [
          '!game/main.js',
          'game/**/*.js',
          'templates/*.tpl',
          'config.json',
          'css/**/*.css'
        ],
        options: {
          spawn: false,
          livereload: LIVERELOAD_PORT
        },
        tasks: ['build:serve']
      }
    },
    connect: {
      options: {
        port: 9000,
        // change this to '0.0.0.0' to access the server from outside
        hostname: 'localhost'
      },
      livereload: {
        options: {
          middleware: function (connect) {
            return [
              lrSnippet,
              mountFolder(connect, 'serve')
            ];
          }
        }
      }
    },
    open: {
      server: {
        path: 'http://localhost:9000'
      }
    },
    copy: {
      serve: {
        files: [
          // includes files within path and its sub-directories
          { expand: true, src: ['assets/**', 'fonts/**', 'css/**'], dest: 'serve/' },
          { expand: true, flatten: true, src: [
            'game/plugins/*{.js,.map}',
            'bower_components/*/build/*{.js,.map}',
            'bower_components/*/dist/*{.js,.map}',
            'game/index.html'
          ], dest: 'serve/' }
        ]
      },
      dist: {
        files: [
          // includes files within path and its sub-directories
          { expand: true, src: [
            'assets/**',
            'fonts/**',
            'css/**',
            'icon.png',
            'manifest.json'
          ], dest: 'dist/' },
          { expand: true, flatten: true, src: [
            'game/plugins/*{.js,.map}',
            'bower_components/*/build/*{.js,.map}',
            'bower_components/*/dist/*{.js,.map}',
            'game/index.html'
          ], dest: 'dist/' }
        ]
      },
      dev: {
        options: {
          process: function(content) {
            return grunt.template.process(content, {
              data: {
                dependencies: [
                  'cordova.js',
                  'phaser.js',
                  'phaser-state-transition-plugin.min.js',
                  'game.js'
                ]
              }
            });
          }
        },
        files: [
          { src: 'game/config/config.dev.json', dest: 'game/config.json' },
          { src: 'templates/_index.html.tpl', dest: 'game/index.html' }
        ]
      },
      prod: {
        options: {
          process: function(content) {
            return grunt.template.process(content, {
              data: {
                dependencies: [
                  'cordova.js',
                  'phaser.js',
                  'phaser-state-transition-plugin.min.js',
                  'game.js'
                ]
              }
            });
          }
        },
        files: [
          { src: 'game/config/config.prod.json', dest: 'game/config.json' },
          { src: 'templates/_index.html.tpl', dest: 'game/index.html' }
        ]
      }
    },
    browserify: {
      serve: {
        src: ['game/main.js'],
        dest: 'serve/game.js'
      },
      dist: {
        src: ['game/main.js'],
        dest: 'dist/game.js'
        // dest: '.cache/game.js'
      }
    },
    uglify: {
      dist: {
        // files: {
        //   'dist/game.min.js': ['.cache/game.js']
        // }
      },
      serve: {}
    },
    clean: {
      serve: ['serve'],
      dist: ['dist', 'build'],
    },
    shell: {
      options: {
        stderr: false
      },
      buildAndroid: {
        command: './build_android.sh <%= manifest.package %> <%= manifest.name %> <%= manifest.version %>'
      },
      installAndroidx86: {
        command: 'adb install -r build/*_x86.apk'
      },
      installAndroidarm: {
        command: 'adb install -r build/*_arm.apk'
      },
      restartAdb: {
        command: [
          'sudo $(which adb) kill-server',
          'sudo $(which adb) start-server',
          'adb devices'
        ].join('&&')
      },
      prepareCordova: {
        command: [
          'rm -rf www',
          'cp -a dist www'
        ].join('&&')
      }
    },
    bump: {
      options: {
        files: ['package.json', 'bower.json', 'manifest.json', 'config.xml'],
        updateConfigs: [],
        commit: true,
        commitMessage: 'Release %VERSION%',
        commitFiles: ['package.json', 'bower.json', 'manifest.json', 'config.xml'],
        createTag: false,
        tagName: '%VERSION%',
        tagMessage: 'Version %VERSION%',
        push: false,
        pushTo: 'upstream',
        gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
      }
    },
    jshint: {
      all: ['game/**/*.js', 'Gruntfile.js'],
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      }
    },
    jscs: {
      src: [
        'game/**/*.js',
        '!game/main.js',
        '!game/plugins/*'
      ],
      options: {
        config: '.jscsrc',
        reporter: require('jscs-stylish').path
      }
    },
    githooks: {
      all: {
        'pre-commit': 'jshint jscs',
      }
    },
    'notify_hooks': {
      options: {
        enabled: true,
        'max_jshint_notifications': 5, // maximum number of notifications from jshint output
        success: true, // whether successful grunt executions should be notified automatically
        duration: 3 // the duration of notification in seconds, for `notify-send only
      }
    },
  });

  // Register Grunt Tasks
  grunt.registerTask('default', 'serve');
  grunt.registerTask('build', function(dest) {
    grunt.task.run([
      'buildBootstrapper',
      'browserify:' + (dest || 'dist'),
      'uglify:' + (dest || 'dist'),
      'copy:' + (dest || 'dist'),
      'notify_hooks'
    ]);
  });
  grunt.registerTask('serve', function(environment) {
    grunt.task.run([
      'githooks',
      'clean:serve',
      'copy:' + (environment || 'dev'),
      'build:serve',
      'connect:livereload',
      'open',
      'watch'
    ]);
  });
  grunt.registerTask('buildAndroid', function(environment) {
    grunt.task.run([
      'clean:dist',
      'copy:' + (environment || 'prod'),
      'build:dist',
      'shell:buildAndroid',
      'notify_hooks'
    ]);
  });
  grunt.registerTask('restartAdb', ['shell:restartAdb']);
  grunt.registerTask('installAndroid', function(arch) {
    // arch is x86 (Intel based tablets) or arm (non-Intel)
    grunt.task.run(['shell:installAndroid' + (arch || 'arm'), 'notify_hooks']);
  });
  grunt.registerTask('buildBootstrapper', function() {
    var stateFiles = grunt.file.expand('game/states/*.js'),
        gameStates = [],
        statePattern = new RegExp(/(\w+).js$/),
        bootstrapper = grunt.file.read('templates/_main.js.tpl');

    stateFiles.forEach(function(file) {
      var state = file.match(statePattern)[1];
      if (!!state) {
        gameStates.push({shortName: state, stateName: _.capitalize(state) + 'State'});
      }
    });
    config.gameStates = gameStates;
    bootstrapper = grunt.template.process(bootstrapper, {data: config});
    grunt.file.write('game/main.js', bootstrapper);
  });
  grunt.registerTask('cordovaSetup', function(environment) {
    var pkg = grunt.file.readJSON('package.json');

    grunt.task.run([
      'clean:dist',
      'copy:' + (environment || 'prod'),
      'build:dist',
      'shell:prepareCordova'
    ]);
    if (!pkg.platforms) {
      return grunt.log.error('Platforms not found.');
    }
    _.forEach(pkg.platforms, function (platform) {
      grunt.log.writeln('Installing platform ' + platform);
      shell.exec('cordova platform add ' + platform);
    });
    _.forEach(pkg.plugins, function (plugin) {
      grunt.log.writeln('Installing plugin ' + plugin);
      shell.exec('cordova plugin add ' + plugin);
    });
  });
};
<|endoftext|>


<commit_before>/* jshint camelcase: false */
module.exports = function (grunt) {
  'use strict';

  grunt.initConfig({

    // load module meta data
    pkg: grunt.file.readJSON('package.json'),

    // define a src set of files for other tasks
    src: {
      lint: ['Gruntfile.js', 'index.js', 'install.js', 'lib/**/*.js', 'test/*.js'],
      complexity: ['index.js', 'install.js', 'lib/**/*.js'],
      test: ['test/*.js'],
      src: ['index.js', 'install.js', 'lib/**/*.js']
    },

    // clean automatically generated helper files & docs
    clean: {
      coverage: ['coverage', 'report/coverage'],
      report: ['report/complexity', 'report/api', 'report/docs'],
      reportZip: ['report.zip']
    },

    // linting
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: '<%= src.lint %>'
    },

    // testing
    mochaTest: {
      test: {
        options: {
          reporter: 'spec',
          require: 'coverage/blanket'
        },
        src: '<%= src.test %>'
      },
      coverage: {
        options: {
          reporter: 'html-cov',
          quiet: true,
          captureFile: 'report/coverage/index.html'
        },
        src: '<%= src.test %>'
      },
      jsoncoverage: {
        options: {
          reporter: 'json-cov',
          quiet: true,
          captureFile: 'report/coverage/coverage.json'
        },
        src: '<%= src.test %>'
      }
    },

    // code metrics
    complexity: {
      generic: {
        src: '<%= src.complexity %>',
        options: {
          cyclomatic: 5,
          halstead: 20,
          maintainability: 100
        }
      }
    },
    plato: {
      generic: {
        options : {
          jshint : grunt.file.readJSON('.jshintrc')
        },
        files: {
          'report/complexity': '<%= src.complexity %>',
        }
      }
    },

    // api docs
    yuidoc: {
      compile: {
        name: '<%= pkg.name %>',
        description: '<%= pkg.description %>',
        version: '<%= pkg.version %>',
        url: '<%= pkg.homepage %>',
        options: {
          paths: '.',
          outdir: 'report/api'
        }
      }
    },

    // user docs
    documantix: {
      options: {
        header: 'dalekjs/dalekjs.com/master/assets/header.html',
        footer: 'dalekjs/dalekjs.com/master/assets/footer.html',
        target: 'report/docs',
        vars: {
          title: 'DalekJS - Documentation - Browser - Internet Explorer',
          desc: 'DalekJS - Documentation - Browser - Internet Explorer',
          docs: true
        }
      },
      src: ['index.js']
    },

    // add current timestamp to the html document
    includereplace: {
      dist: {
        options: {
          globals: {
            timestamp: '<%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %>'
          },
        },
        src: 'report/docs/*.html',
        dest: '.'
      }
    },

    // up version, tag & commit
    bump: {
      options: {
        files: ['package.json'],
        commit: true,
        commitMessage: 'Release v%VERSION%',
        commitFiles: ['package.json'],
        createTag: true,
        tagName: '%VERSION%',
        tagMessage: '%VERSION%',
        push: true
      }
    },

    // compress artifacts
    compress: {
      main: {
        options: {
          archive: 'report.zip'
        },
        files: [
          {src: ['report/**'], dest: '/'}
        ]
      }
    }

  });

  // prepare files & folders for grunt:plato & coverage
  grunt.registerTask('preparePlato', function () {
    var fs = require('fs');

    var platoDummyFolders = ['report', 'report/coverage', 'report/complexity', 'report/complexity/files', 'report/complexity/files/test', 'report/complexity/files/index_js', 'report/complexity/files/install_js', 'report/complexity/files/lib_iedriver_js'];
    var platoDummyFiles = ['/report/complexity/report.history.json', '/report/complexity/files/report.history.json', '/report/complexity/files/index_js/report.history.json', '/report/complexity/files/install_js/report.history.json', '/report/complexity/files/lib_iedriver_js/report.history.json'];

    // loopy loop
    ['/test/'].forEach(function (folder) {
      fs.readdirSync(__dirname + folder).forEach(function (file) {
        var platoFolder = '/report/complexity/files/' + folder.substring(1).replace(/\//g, '_') + file.replace('.js', '_js');
        platoDummyFolders.push(platoFolder);
        platoDummyFiles.push(platoFolder + '/report.history.json');
      });
    });

    // generate dirs for docs & reports
    platoDummyFolders.forEach(function (path) {
      if (!fs.existsSync(__dirname + '/' + path)) {
        fs.mkdirSync(__dirname + '/' + path);
      }
    });

    // store some dummy reports, so that grunt plato doesnt complain
    platoDummyFiles.forEach(function (file) {
      if (!fs.existsSync(__dirname + file)) {
        fs.writeFileSync(__dirname + file, '{}');
      }
    });
  });

  // prepare files & folders for coverage
  grunt.registerTask('prepareCoverage', function () {
    var fs = require('fs');

    // generate folders
    ['coverage', 'report', 'report/coverage'].forEach(function (folder) {
      if (!fs.existsSync(__dirname + '/' + folder)) {
        fs.mkdirSync(__dirname + '/' + folder);
      }
    });

    // generate code coverage helper file
    var coverageHelper = 'require("blanket")({pattern: [require("fs").realpathSync(__dirname + "/../index.js"), require("fs").realpathSync(__dirname + "/../lib/")]});';
    if (!fs.existsSync(__dirname + '/coverage/blanket.js')) {
      fs.writeFileSync(__dirname + '/coverage/blanket.js', coverageHelper);
    }
  });

  // generates a coverage badge
  grunt.registerTask('generateCoverageBadge', function () {
    var fs = require('fs');
    if (fs.existsSync(__dirname + '/node_modules/coverage-badge')) {
      if (fs.existsSync(__dirname + '/report/coverage/coverage.json')) {
        var green = [147,188,59];
        var yellow = [166,157,0];
        var red = [189,0,2];

        var getColor = function (coverage) {
          if (coverage > 90) {
            return mixColors(yellow, green, (coverage-90)/10);
          }

          if (coverage > 80) {
            return mixColors(red, yellow, (coverage-80)/10);
          }

          return createColor(red);
        };

        var mixColors = function (from, to, ratio) {
          var result = [], i;
          for (i=0; i<3; i++) {
            result[i] = Math.round(from[i] + (ratio * (to[i]-from[i])));
          }
          return createColor(result);
        };

        var createColor = function (values) {
          return 'rgba('+values[0]+','+values[1]+','+values[2]+',1)';
        };

        var Badge = require(__dirname + '/node_modules/coverage-badge/lib/Badge.js');
        var badgeFn = function(coverage) {
          coverage = Math.floor(Number(coverage));
          var badge = new Badge({
            box_color: getColor(coverage),
            box_text: coverage+'%',
            label_text: 'cov',
            height: 18,
            width: 49,
            box_width: 25,
            rounding: 0,
            padding: 0,
            label_font: '7pt DejaVu Sans',
            box_font: 'bold 7pt DejaVu Sans'
          });
          return badge.stream();
        };

        var coverage = JSON.parse(fs.readFileSync(__dirname + '/report/coverage/coverage.json')).coverage;
        var file = fs.createWriteStream(__dirname + '/report/coverage/coverage.png');
        badgeFn(coverage).pipe(file);
      }
    }
  });

  // archives the docs if a new version appears
  grunt.registerTask('archive', function () {
    var done = this.async();
    grunt.util.spawn({cmd: 'git', args: ['describe', '--abbrev=0', '--tags']}, function (error, result) {
      var lastTag = result.toString();
      if (grunt.file.isFile('_raw/docs/' + lastTag + '/internetexplorer.html')) {
        grunt.log.ok('Nothing to archive');
        done();
        return true;
      }

      if (!grunt.file.isDir('_raw/docs/' + lastTag)) {
        grunt.file.mkdir('_raw/docs/' + lastTag);
      }

      grunt.file.copy('report/docs/internetexplorer.html', '_raw/docs/' + lastTag + '/internetexplorer.html');
      grunt.log.ok('Archived document with version: ' + lastTag);
      done();
    });
  });

  // releases a new canary build
  grunt.registerTask('release-canary', function () {
    var done = this.async();
    var pkg = grunt.config.get('pkg');
    var canaryPkg = grunt.util._.clone(pkg);

    Object.keys(canaryPkg.dependencies).forEach(function (pack) {
      if (pack.search('dalek') !== -1) {
        delete canaryPkg.dependencies[pack];
        canaryPkg.dependencies[pack + '-canary'] = 'latest';
      }
    });

    canaryPkg.name = canaryPkg.name + '-canary';
    canaryPkg.version = canaryPkg.version + '-' + grunt.template.today('yyyy-mm-dd-HH-MM-ss');

    grunt.file.write('package.json', JSON.stringify(canaryPkg, true, 2));

    var npm = require('npm');
    npm.load({}, function() {
      npm.registry.adduser(process.env.npmuser, process.env.npmpass, process.env.npmmail, function(err) {
        if (err) {
          grunt.log.error(err);
          grunt.file.write('package.json', JSON.stringify(pkg, true, 2));
          done(false);
        } else {
          npm.config.set('email', process.env.npmmail, 'user');
          npm.commands.publish([], function(err) {
            grunt.file.write('package.json', JSON.stringify(pkg, true, 2));
            grunt.log.ok('Published canary build to registry');
            done(!err);
          });
        }
      });
    });
  });

  // release a new version
  grunt.registerTask('release-package', function () {
    var done = this.async();
    var http = require('http');
    var pkg = grunt.config.get('pkg');
    var body = '';

    http.get('http://registry.npmjs.org/' + pkg.name, function(res) {
      res.on('data', function (data) {
        body += data;
      });

      res.on('end', function () {
        var versions = grunt.util._.pluck(JSON.parse(body).versions, 'version');
        var currVersion =  parseInt(pkg.version.replace(/\./gi, ''), 10);
        var availableVersions = versions.map(function (version) {
          return parseInt(version.replace(/\./gi, ''), 10);
        });

        if (!grunt.util._.contains(availableVersions, currVersion)) {
          var npm = require('npm');
          npm.load({}, function() {
            npm.registry.adduser(process.env.npmuser, process.env.npmpass, process.env.npmmail, function(err) {
              if (err) {
                grunt.log.error(err);
                done(false);
              } else {
                npm.config.set('email', process.env.npmmail, 'user');
                npm.commands.publish([], function(err) {
                  grunt.log.ok('Released new version: ', pkg.version);
                  done(!err);
                });
              }
            });
          });
        } else {
          done();
        }
      });
    });
  });

  // load 3rd party tasks
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-yuidoc');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-mocha-test');
  grunt.loadNpmTasks('grunt-complexity');
  grunt.loadNpmTasks('grunt-documantix');
  grunt.loadNpmTasks('grunt-plato');
  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-include-replace');

  // define runner tasks
  grunt.registerTask('lint', 'jshint');
  grunt.registerTask('test', ['clean:coverage', 'prepareCoverage', 'lint', 'mochaTest', 'generateCoverageBadge', 'complexity']);
  grunt.registerTask('docs', ['clean:reportZip', 'clean:report', 'preparePlato', 'plato', 'documantix', 'includereplace', 'yuidoc', 'compress']);
  grunt.registerTask('all', ['clean', 'test', 'docs']);

};
<commit_msg>Fixing Gruntfile<commit_after>/* jshint camelcase: false */
module.exports = function (grunt) {
  'use strict';

  grunt.initConfig({

    // load module meta data
    pkg: grunt.file.readJSON('package.json'),

    // define a src set of files for other tasks
    src: {
      lint: ['Gruntfile.js', 'index.js', 'install.js', 'lib/**/*.js', 'test/*.js'],
      complexity: ['index.js', 'install.js', 'lib/**/*.js'],
      test: ['test/*.js'],
      src: ['index.js', 'install.js', 'lib/**/*.js']
    },

    // clean automatically generated helper files & docs
    clean: {
      coverage: ['coverage', 'report/coverage'],
      report: ['report/complexity', 'report/api', 'report/docs'],
      reportZip: ['report.zip']
    },

    // linting
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: '<%= src.lint %>'
    },

    // testing
    mochaTest: {
      test: {
        options: {
          reporter: 'spec',
          require: 'coverage/blanket'
        },
        src: '<%= src.test %>'
      },
      coverage: {
        options: {
          reporter: 'html-cov',
          quiet: true,
          captureFile: 'report/coverage/index.html'
        },
        src: '<%= src.test %>'
      },
      jsoncoverage: {
        options: {
          reporter: 'json-cov',
          quiet: true,
          captureFile: 'report/coverage/coverage.json'
        },
        src: '<%= src.test %>'
      }
    },

    // code metrics
    complexity: {
      generic: {
        src: '<%= src.complexity %>',
        options: {
          cyclomatic: 5,
          halstead: 20,
          maintainability: 100
        }
      }
    },
    plato: {
      generic: {
        options : {
          jshint : grunt.file.readJSON('.jshintrc')
        },
        files: {
          'report/complexity': '<%= src.complexity %>',
        }
      }
    },

    // api docs
    yuidoc: {
      compile: {
        name: '<%= pkg.name %>',
        description: '<%= pkg.description %>',
        version: '<%= pkg.version %>',
        url: '<%= pkg.homepage %>',
        options: {
          paths: '.',
          outdir: 'report/api'
        }
      }
    },

    // user docs
    documantix: {
      options: {
        header: 'dalekjs/dalekjs.com/master/assets/header.html',
        footer: 'dalekjs/dalekjs.com/master/assets/footer.html',
        target: 'report/docs',
        vars: {
          title: 'DalekJS - Documentation - Browser - Internet Explorer',
          desc: 'DalekJS - Documentation - Browser - Internet Explorer',
          docs: true
        }
      },
      src: ['index.js']
    },

    // add current timestamp to the html document
    includereplace: {
      dist: {
        options: {
          globals: {
            timestamp: '<%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %>'
          },
        },
        src: 'report/docs/*.html',
        dest: '.'
      }
    },

    // up version, tag & commit
    bump: {
      options: {
        files: ['package.json'],
        commit: true,
        commitMessage: 'Release v%VERSION%',
        commitFiles: ['package.json'],
        createTag: true,
        tagName: '%VERSION%',
        tagMessage: '%VERSION%',
        push: true,
        pushTo: 'git@github.com:dalekjs/dalek-browser-ie.git'
      }
    },

    // compress artifacts
    compress: {
      main: {
        options: {
          archive: 'report.zip'
        },
        files: [
          {src: ['report/**'], dest: '/'}
        ]
      }
    }

  });

  // prepare files & folders for grunt:plato & coverage
  grunt.registerTask('preparePlato', function () {
    var fs = require('fs');

    var platoDummyFolders = ['report', 'report/coverage', 'report/complexity', 'report/complexity/files', 'report/complexity/files/test', 'report/complexity/files/index_js', 'report/complexity/files/install_js', 'report/complexity/files/lib_iedriver_js'];
    var platoDummyFiles = ['/report/complexity/report.history.json', '/report/complexity/files/report.history.json', '/report/complexity/files/index_js/report.history.json', '/report/complexity/files/install_js/report.history.json', '/report/complexity/files/lib_iedriver_js/report.history.json'];

    // loopy loop
    ['/test/'].forEach(function (folder) {
      fs.readdirSync(__dirname + folder).forEach(function (file) {
        var platoFolder = '/report/complexity/files/' + folder.substring(1).replace(/\//g, '_') + file.replace('.js', '_js');
        platoDummyFolders.push(platoFolder);
        platoDummyFiles.push(platoFolder + '/report.history.json');
      });
    });

    // generate dirs for docs & reports
    platoDummyFolders.forEach(function (path) {
      if (!fs.existsSync(__dirname + '/' + path)) {
        fs.mkdirSync(__dirname + '/' + path);
      }
    });

    // store some dummy reports, so that grunt plato doesnt complain
    platoDummyFiles.forEach(function (file) {
      if (!fs.existsSync(__dirname + file)) {
        fs.writeFileSync(__dirname + file, '{}');
      }
    });
  });

  // prepare files & folders for coverage
  grunt.registerTask('prepareCoverage', function () {
    var fs = require('fs');

    // generate folders
    ['coverage', 'report', 'report/coverage'].forEach(function (folder) {
      if (!fs.existsSync(__dirname + '/' + folder)) {
        fs.mkdirSync(__dirname + '/' + folder);
      }
    });

    // generate code coverage helper file
    var coverageHelper = 'require("blanket")({pattern: [require("fs").realpathSync(__dirname + "/../index.js"), require("fs").realpathSync(__dirname + "/../lib/")]});';
    if (!fs.existsSync(__dirname + '/coverage/blanket.js')) {
      fs.writeFileSync(__dirname + '/coverage/blanket.js', coverageHelper);
    }
  });

  // generates a coverage badge
  grunt.registerTask('generateCoverageBadge', function () {
    var fs = require('fs');
    if (fs.existsSync(__dirname + '/node_modules/coverage-badge')) {
      if (fs.existsSync(__dirname + '/report/coverage/coverage.json')) {
        var green = [147,188,59];
        var yellow = [166,157,0];
        var red = [189,0,2];

        var getColor = function (coverage) {
          if (coverage > 90) {
            return mixColors(yellow, green, (coverage-90)/10);
          }

          if (coverage > 80) {
            return mixColors(red, yellow, (coverage-80)/10);
          }

          return createColor(red);
        };

        var mixColors = function (from, to, ratio) {
          var result = [], i;
          for (i=0; i<3; i++) {
            result[i] = Math.round(from[i] + (ratio * (to[i]-from[i])));
          }
          return createColor(result);
        };

        var createColor = function (values) {
          return 'rgba('+values[0]+','+values[1]+','+values[2]+',1)';
        };

        var Badge = require(__dirname + '/node_modules/coverage-badge/lib/Badge.js');
        var badgeFn = function(coverage) {
          coverage = Math.floor(Number(coverage));
          var badge = new Badge({
            box_color: getColor(coverage),
            box_text: coverage+'%',
            label_text: 'cov',
            height: 18,
            width: 49,
            box_width: 25,
            rounding: 0,
            padding: 0,
            label_font: '7pt DejaVu Sans',
            box_font: 'bold 7pt DejaVu Sans'
          });
          return badge.stream();
        };

        var coverage = JSON.parse(fs.readFileSync(__dirname + '/report/coverage/coverage.json')).coverage;
        var file = fs.createWriteStream(__dirname + '/report/coverage/coverage.png');
        badgeFn(coverage).pipe(file);
      }
    }
  });

  // archives the docs if a new version appears
  grunt.registerTask('archive', function () {
    var done = this.async();
    grunt.util.spawn({cmd: 'git', args: ['describe', '--abbrev=0', '--tags']}, function (error, result) {
      var lastTag = result.toString();
      if (grunt.file.isFile('_raw/docs/' + lastTag + '/internetexplorer.html')) {
        grunt.log.ok('Nothing to archive');
        done();
        return true;
      }

      if (!grunt.file.isDir('_raw/docs/' + lastTag)) {
        grunt.file.mkdir('_raw/docs/' + lastTag);
      }

      grunt.file.copy('report/docs/internetexplorer.html', '_raw/docs/' + lastTag + '/internetexplorer.html');
      grunt.log.ok('Archived document with version: ' + lastTag);
      done();
    });
  });

  // releases a new canary build
  grunt.registerTask('release-canary', function () {
    var done = this.async();
    var pkg = grunt.config.get('pkg');
    var canaryPkg = grunt.util._.clone(pkg);

    Object.keys(canaryPkg.dependencies).forEach(function (pack) {
      if (pack.search('dalek') !== -1) {
        delete canaryPkg.dependencies[pack];
        canaryPkg.dependencies[pack + '-canary'] = 'latest';
      }
    });

    canaryPkg.name = canaryPkg.name + '-canary';
    canaryPkg.version = canaryPkg.version + '-' + grunt.template.today('yyyy-mm-dd-HH-MM-ss');

    grunt.file.write('package.json', JSON.stringify(canaryPkg, true, 2));

    var npm = require('npm');
    npm.load({}, function() {
      npm.registry.adduser(process.env.npmuser, process.env.npmpass, process.env.npmmail, function(err) {
        if (err) {
          grunt.log.error(err);
          grunt.file.write('package.json', JSON.stringify(pkg, true, 2));
          done(false);
        } else {
          npm.config.set('email', process.env.npmmail, 'user');
          npm.commands.publish([], function(err) {
            grunt.file.write('package.json', JSON.stringify(pkg, true, 2));
            grunt.log.ok('Published canary build to registry');
            done(!err);
          });
        }
      });
    });
  });

  // release a new version
  grunt.registerTask('release-package', function () {
    var done = this.async();
    var http = require('http');
    var pkg = grunt.config.get('pkg');
    var body = '';

    http.get('http://registry.npmjs.org/' + pkg.name, function(res) {
      res.on('data', function (data) {
        body += data;
      });

      res.on('end', function () {
        var versions = grunt.util._.pluck(JSON.parse(body).versions, 'version');
        var currVersion =  parseInt(pkg.version.replace(/\./gi, ''), 10);
        var availableVersions = versions.map(function (version) {
          return parseInt(version.replace(/\./gi, ''), 10);
        });

        if (!grunt.util._.contains(availableVersions, currVersion)) {
          var npm = require('npm');
          npm.load({}, function() {
            npm.registry.adduser(process.env.npmuser, process.env.npmpass, process.env.npmmail, function(err) {
              if (err) {
                grunt.log.error(err);
                done(false);
              } else {
                npm.config.set('email', process.env.npmmail, 'user');
                npm.commands.publish([], function(err) {
                  grunt.log.ok('Released new version: ', pkg.version);
                  done(!err);
                });
              }
            });
          });
        } else {
          done();
        }
      });
    });
  });

  // load 3rd party tasks
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-yuidoc');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-mocha-test');
  grunt.loadNpmTasks('grunt-complexity');
  grunt.loadNpmTasks('grunt-documantix');
  grunt.loadNpmTasks('grunt-plato');
  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-include-replace');

  // define runner tasks
  grunt.registerTask('lint', 'jshint');
  grunt.registerTask('test', ['clean:coverage', 'prepareCoverage', 'lint', 'mochaTest', 'generateCoverageBadge', 'complexity']);
  grunt.registerTask('docs', ['clean:reportZip', 'clean:report', 'preparePlato', 'plato', 'documantix', 'includereplace', 'yuidoc', 'compress']);
  grunt.registerTask('all', ['clean', 'test', 'docs']);

};
<|endoftext|>


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

   // Project configuration.
   grunt.initConfig({
     pkg: grunt.file.readJSON('package.json'),
     // Uglify Task
     uglify: {
       build: {
         src: 'js/app.js',
         dest: 'js/app.min.js'
       }
     },
     // minifyHtml Task
     minifyHtml: {
       options: {
         cdata: true
       },
       dist: {
         files: {
           'index.html': ['index_template.html']
         }
       }
     },
     // html w3c validation
     validation: {
       options: {
         reset: grunt.option('reset') || false,
         stoponerror: false,
         relaxerror: [
           'Bad value X-UA-Compatible for attribute http-equiv on element meta.',
           'The Content-Type was “text/html”. Using the HTML parser.',
           'Using the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support.'
         ],
         generateReport: false,
         errorHTMLRootDir: "w3cErrorFolder",
         useTimeStamp: true
       },
       files: {
         src: ['index.html']
       }
     },
     // CSSlint Task
     csslint: {
       strict: {
         options: {
           csslintrc: '.csslintrc'
         },
         src: ['css/app.css']
       }
     },
     // Grunt SVG Min Task
     svgmin: {
       dist: {
         files: [{
           expand: true,
           cwd: 'img',
           src: ['*.svg'],
           dest: 'img'
         }]
       }
     },
     // Grunt Icon Task
     grunticon: {
       myIcons: {
         files: [{
           expand: true,
           cwd: 'img',
           src: ['*.svg', '*.png'],
           dest: "img/grunticon-assets"
         }],
         options: {
           previewhtml: "img_assets_preview.html",
           pngfolder: "../png-fallback",
           pngpath: "../png-fallback",
           previewTemplate: "img/grunticon-assets/preview.hbs",
           defaultWidth: "64px",
           defaultHeight: "64px",
           colors: {
             colortheme1: "red",
             colortheme2: "blue",
             colortheme3: "green",
           }
         }
       }
     },
     // Grunt Styleguide Task
     styleguide: {
       options: {
         // global options
       },
       kss: {
         options: {
           framework: {
             name: 'kss'
           },
           name: 'Style Guide',
           template: {
             src: 'styleguide/kss_template/'
           }
         },
         files: {
           'styleguide': 'sass/*.scss'
         },
       }
     },
     // Compass Task
     compass: {
       dist: {
         options: {
           config: 'config.rb'
         }
       },
       dev: {
         options: {
           config: 'config.rb',
           watch: true
         }
       }
     },
     // UnCss Task
     uncss: {
       dist: {
         files: {
           'css/tidy.css': ['index_template.html']
         }
       }
     },
     // Palettable Task
     palettable: {
       options: {
         stylesDirectory: 'sass/',
         outputFilePath: 'styleguide/palette.html'
       }
     },
     //Pleease Shell
     shell: {
       pleeease: {
         command: 'sh pleeease.sh'
       }
     },
     //Copy
     copy: {
       grunticon: {
         files: [{
           src: 'img/grunticon-assets/icons.data.svg.css',
           dest: 'sass/_icons_data_svg.scss'
         }, {
           src: 'img/grunticon-assets/icons.data.png.css',
           dest: 'sass/_icons_data_png.scss'
         }, {
           src: 'img/grunticon-assets/icons.fallback.css',
           dest: 'sass/_icons_fallback.scss'
         }],
       },
     },
     //Preprocess
     preprocess: {
       svg: {
         options: {
           context: {
             ICONS: '_icons_data_svg'
           }
         },
         files: {
           'sass/app.data.svg.scss': './app_template.scss'
         }
       },
       png: {
         options: {
           context: {
             ICONS: '_icons_data_png'
           }
         },
         files: {
           'sass/app.data.png.scss': './app_template.scss'
         }
       },
       fallback: {
         options: {
           context: {
             ICONS: '_icons_fallback'
           }
         },
         files: {
           'sass/app.fallback.scss': './app_template.scss'
         }
       }
     },
     // Connect
    connect: {
      server: {
        options: {
          port: 8080,
          base: '.',
          keepalive: true
        }
      }
    },
   });

   // Require for Grunt Shell plugin
   require('load-grunt-tasks')(grunt);

   // Load the plugin for copying files
   grunt.loadNpmTasks('grunt-contrib-copy');
   // Load the plugin for preprocessing sass files
   grunt.loadNpmTasks('grunt-preprocess');
   // Load the plugin that provides the "uglify" task
   grunt.loadNpmTasks('grunt-contrib-uglify');
   // Load the plugin minify-html
   grunt.loadNpmTasks('grunt-minify-html');
   // Load the plugin html w3c validation
   grunt.loadNpmTasks('grunt-w3c-html-validation');
   // Load the plugin CSSlint
   grunt.loadNpmTasks('grunt-contrib-csslint');
   // Load the plugin SVGMin
   grunt.loadNpmTasks('grunt-svgmin');
   // Load the plugin Grunt Icon
   grunt.loadNpmTasks('grunt-grunticon');
   // Load the plugin Grunt Styleguide
   grunt.loadNpmTasks('grunt-styleguide');
   // Load the plugin compass
   grunt.loadNpmTasks('grunt-contrib-compass');
   // Load the plugin uncss
   grunt.loadNpmTasks('grunt-uncss');
   // Load the plugin palettable
   grunt.loadNpmTasks('palettable');

   // Serve task.
   grunt.registerTask('serve', ['connect']);
   // Default task.
   grunt.registerTask('default', ['preprocess', 'uglify', 'minifyHtml', 'validation', 'csslint:strict', 'svgmin', 'grunticon', 'copy', 'palettable', 'styleguide', 'compass:dist', 'shell:pleeease']);
   // Prod task.
   grunt.registerTask('dev', ['preprocess', 'svgmin', 'grunticon', 'copy', 'palettable', 'csslint:strict', 'validation', 'compass:dev']);

 };<commit_msg>add grunt connect<commit_after>module.exports = function(grunt) {

   // Project configuration.
   grunt.initConfig({
     pkg: grunt.file.readJSON('package.json'),
     // Uglify Task
     uglify: {
       build: {
         src: 'js/app.js',
         dest: 'js/app.min.js'
       }
     },
     // minifyHtml Task
     minifyHtml: {
       options: {
         cdata: true
       },
       dist: {
         files: {
           'index.html': ['index_template.html']
         }
       }
     },
     // html w3c validation
     validation: {
       options: {
         reset: grunt.option('reset') || false,
         stoponerror: false,
         relaxerror: [
            'Bad value X-UA-Compatible for attribute http-equiv on element meta.',
            'Bad value “https://fonts.googleapis.com/',
            'The Content-Type was “text/html”. Using the HTML parser.',
            'Using the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support.',
            'lacks heading. Consider using “h2”-“h6” elements to add identifying headings to all',
            'Consider using the “h1” element as a top-level heading',
       ],
         generateReport: false,
         errorHTMLRootDir: "w3cErrorFolder",
         useTimeStamp: true
       },
       files: {
         src: ['index.html']
       }
     },
     // CSSlint Task
     csslint: {
       strict: {
         options: {
           csslintrc: '.csslintrc'
         },
         src: ['css/app.css']
       }
     },
     // Grunt SVG Min Task
     svgmin: {
       dist: {
         files: [{
           expand: true,
           cwd: 'img',
           src: ['*.svg'],
           dest: 'img'
         }]
       }
     },
     // Grunt Icon Task
     grunticon: {
       myIcons: {
         files: [{
           expand: true,
           cwd: 'img',
           src: ['*.svg', '*.png'],
           dest: "img/grunticon-assets"
         }],
         options: {
           previewhtml: "img_assets_preview.html",
           pngfolder: "../png-fallback",
           pngpath: "../png-fallback",
           previewTemplate: "img/grunticon-assets/preview.hbs",
           defaultWidth: "64px",
           defaultHeight: "64px",
           colors: {
             colortheme1: "red",
             colortheme2: "blue",
             colortheme3: "green",
           }
         }
       }
     },
     // Grunt Styleguide Task
     styleguide: {
       options: {
         // global options
       },
       kss: {
         options: {
           framework: {
             name: 'kss'
           },
           name: 'Style Guide',
           template: {
             src: 'styleguide/kss_template/'
           }
         },
         files: {
           'styleguide': 'sass/*.scss'
         },
       }
     },
     // Compass Task
     compass: {
       dist: {
         options: {
           config: 'config.rb'
         }
       },
       dev: {
         options: {
           config: 'config.rb',
           watch: true
         }
       }
     },
     // UnCss Task
     uncss: {
       dist: {
         files: {
           'css/tidy.css': ['index_template.html']
         }
       }
     },
     // Palettable Task
     palettable: {
       options: {
         stylesDirectory: 'sass/',
         outputFilePath: 'styleguide/palette.html'
       }
     },
     //Pleease Shell
     shell: {
       pleeease: {
         command: 'sh pleeease.sh'
       }
     },
     //Copy
     copy: {
       grunticon: {
         files: [{
           src: 'img/grunticon-assets/icons.data.svg.css',
           dest: 'sass/_icons_data_svg.scss'
         }, {
           src: 'img/grunticon-assets/icons.data.png.css',
           dest: 'sass/_icons_data_png.scss'
         }, {
           src: 'img/grunticon-assets/icons.fallback.css',
           dest: 'sass/_icons_fallback.scss'
         }],
       },
     },
     //Preprocess
     preprocess: {
       svg: {
         options: {
           context: {
             ICONS: '_icons_data_svg'
           }
         },
         files: {
           'sass/app.data.svg.scss': './app_template.scss'
         }
       },
       png: {
         options: {
           context: {
             ICONS: '_icons_data_png'
           }
         },
         files: {
           'sass/app.data.png.scss': './app_template.scss'
         }
       },
       fallback: {
         options: {
           context: {
             ICONS: '_icons_fallback'
           }
         },
         files: {
           'sass/app.fallback.scss': './app_template.scss'
         }
       }
     },
     // Connect
    connect: {
      server: {
        options: {
          port: 8080,
          base: '.',
          keepalive: true
        }
      }
    },
   });

   // Require for Grunt Shell plugin
   require('load-grunt-tasks')(grunt);

   // Load the plugin for copying files
   grunt.loadNpmTasks('grunt-contrib-copy');
   // Load the plugin for preprocessing sass files
   grunt.loadNpmTasks('grunt-preprocess');
   // Require for Grunt Shell plugin
   require('load-grunt-tasks')(grunt);
   // Load the plugin that provides the "uglify" task
   grunt.loadNpmTasks('grunt-contrib-uglify');
   // Load the plugin minify-html
   grunt.loadNpmTasks('grunt-minify-html');
   // Load the plugin html w3c validation
   grunt.loadNpmTasks('grunt-w3c-html-validation');
   // Load the plugin CSSlint
   grunt.loadNpmTasks('grunt-contrib-csslint');
   // Load the plugin SVGMin
   grunt.loadNpmTasks('grunt-svgmin');
   // Load the plugin Grunt Icon
   grunt.loadNpmTasks('grunt-grunticon');
   // Load the plugin Grunt Styleguide
   grunt.loadNpmTasks('grunt-styleguide');
   // Load the plugin compass
   grunt.loadNpmTasks('grunt-contrib-compass');
   // Load the plugin uncss
   grunt.loadNpmTasks('grunt-uncss');
   // Load the plugin palettable
   grunt.loadNpmTasks('palettable');
   // Load the plugin connect
   grunt.loadNpmTasks('grunt-contrib-connect');

   // Default task.
   grunt.registerTask('default', ['preprocess', 'uglify', 'minifyHtml', 'validation', 'csslint:strict', 'svgmin', 'grunticon', 'copy', 'palettable', 'styleguide', 'compass:dist', 'shell:pleeease']);
   // Prod task.
   grunt.registerTask('dev', ['preprocess', 'svgmin', 'grunticon', 'copy', 'palettable', 'csslint:strict', 'validation', 'compass:dev']);
   // Serve task.
   grunt.registerTask('serve', ['connect']);

 };<|endoftext|>


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

  // Dependencies
  var path = require('path');

  // Variables
  var bootstrap_path = '../bootstrap';

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

    clean: {
      main: ['publish/*', 'less/variables.less']
    },

    xsltproc: {
      options: {
        stylesheet: 'style/main.xsl',
        xinclude: true
      },
      main: {
        files: {
          'publish/index.html': 'src/main.xml'
        }
      }
    },

    copy: {
      main: {
        files: [
          {
            expand: true,
            flatten: true,
            nonull: true,
            cwd: bootstrap_path,
            src: '**/bootstrap*.min.css',
            dest: 'publish/css/'
          },
          {
            expand: true,
            flatten: true,
            nonull: true,
            cwd: bootstrap_path,
            src: '**/bootstrap.min.js',
            dest: 'publish/js/'
          }
        ]
      }
    },

    less: {
      main: {
        options: {
          strictMath: true
        },
        files: {
          'publish/css/style.css': 'less/style.less'
        }
      }
    },

    autoprefixer: {
//      options: {
//        'browsers': '> 1%, last 2 versions'
//      },
      main: {
        src: ['publish/css/style.css']
      }
    },

    csslint: {
      options: {
        'adjoining-classes': false,
        'compatible-vendor-prefixes': false
      },
      main: {
        src: ['publish/css/style.css']
      }
    },

    cssmin: {
      main: {
        files: {
          'publish/css/style.css': 'publish/css/style.css'
        }
      }
    },

    htmlmin: {
      main: {
        options: {
          removeComments: true,
          collapseWhitespace: true
        },
        expand: true,
        nonull: true,
        src: 'publish/**.html'
      }
    },

    connect: {
      server: {
        options: {
          port: 8000,
          base: 'publish',
          keepalive: true,
          //open: 'http://localhost:8000/',
        }
      }
    }
  });

  // Load the plugin(s)
  require('load-grunt-tasks')(grunt);

  // Copy sample files
  grunt.registerTask('copy_samples', function() {
    // Recurse samples directory
    grunt.file.recurse('src/sample', function(abspath, rootdir, subdir, filename) {
      var destfile = path.join('src', filename);

      // Check if destination file exists
      if (! grunt.file.exists(destfile)) {
        grunt.log.writeln('Copying sample: ' + filename);

        // Copy sample to destination
        grunt.file.copy(abspath, destfile);
      }
    });
  });

  // Read bootstrap variables.less or config.json
  grunt.registerTask('parse_bootstrap_config', function() {
    // Find variables.less in bootstrap_path
    var bootstrap_config_path = grunt.file.expand({ cwd: bootstrap_path }, '**/variables.less')[0];
    if (bootstrap_config_path) {
      grunt.log.writeln('Copying Bootstrap variables: ' + bootstrap_config_path);

      // Copy variables.less
      grunt.file.copy(path.join(bootstrap_path, bootstrap_config_path), 'less/variables.less');

      return true;
    }
    grunt.log.writeln('Bootstrap variables not found!');

    // Find config.json in bootstrap_path
    var bootstrap_config_path = grunt.file.expand({ cwd: bootstrap_path }, '**/config.json')[0];
    if (! bootstrap_config_path) {
      grunt.log.error('Bootstrap config not found!');

      return false;
    }
    grunt.log.writeln('Parsing Bootstrap config: ' + bootstrap_config_path);

    // Parse config.json
    var bootstrap_config = grunt.file.readJSON(path.join(bootstrap_path, bootstrap_config_path));
    var variables = '';
    for (var key in bootstrap_config.vars) {
      variables += key + ':\t' + bootstrap_config.vars[key] + ';\n';
    }

    // Generate variables.less
    grunt.file.write('less/variables.less', variables);

    return true;
  });

  // Default task including everything
  grunt.registerTask('default', ['clean', 'copy', 'copy_samples', 'xsltproc', 'parse_bootstrap_config', 'less', 'autoprefixer', 'csslint', 'cssmin', 'htmlmin', 'connect']);
  // Everything except minification
  grunt.registerTask('debug', ['clean', 'copy', 'copy_samples', 'xsltproc', 'parse_bootstrap_config', 'less', 'autoprefixer', 'csslint', 'connect']);
};
<commit_msg>Really adopted new folder structure<commit_after>module.exports = function(grunt) {

  // Dependencies
  var path = require('path');

  // Variables
  var bootstrap_path = '../bootstrap';

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

    clean: {
      main: ['publish/*', 'less/variables.less']
    },

    xsltproc: {
      options: {
        stylesheet: 'style/main.xsl',
        xinclude: true
      },
      main: {
        files: {
          'publish/index.html': 'src/main.xml'
        }
      }
    },

    copy: {
      main: {
        files: [
          {
            expand: true,
            flatten: true,
            nonull: true,
            cwd: bootstrap_path,
            src: '**/bootstrap*.min.css',
            dest: 'publish/css/'
          },
          {
            expand: true,
            flatten: true,
            nonull: true,
            cwd: bootstrap_path,
            src: '**/bootstrap.min.js',
            dest: 'publish/js/'
          }
        ]
      }
    },

    less: {
      main: {
        options: {
          strictMath: true
        },
        files: {
          'publish/css/style.css': 'less/style.less'
        }
      }
    },

    autoprefixer: {
//      options: {
//        'browsers': '> 1%, last 2 versions'
//      },
      main: {
        src: ['publish/css/style.css']
      }
    },

    csslint: {
      options: {
        'adjoining-classes': false,
        'compatible-vendor-prefixes': false
      },
      main: {
        src: ['publish/css/style.css']
      }
    },

    cssmin: {
      main: {
        files: {
          'publish/css/style.css': 'publish/css/style.css'
        }
      }
    },

    htmlmin: {
      main: {
        options: {
          removeComments: true,
          collapseWhitespace: true
        },
        expand: true,
        nonull: true,
        src: 'publish/**/*.html'
      }
    },

    connect: {
      server: {
        options: {
          port: 8000,
          base: 'publish',
          keepalive: true,
          //open: 'http://localhost:8000/',
        }
      }
    }
  });

  // Load the plugin(s)
  require('load-grunt-tasks')(grunt);

  // Copy sample files
  grunt.registerTask('copy_samples', function() {
    // Recurse samples directory
    grunt.file.recurse('src/sample', function(abspath, rootdir, subdir, filename) {
      var destfile = path.join('src', filename);

      // Check if destination file exists
      if (! grunt.file.exists(destfile)) {
        grunt.log.writeln('Copying sample: ' + filename);

        // Copy sample to destination
        grunt.file.copy(abspath, destfile);
      }
    });
  });

  // Read bootstrap variables.less or config.json
  grunt.registerTask('parse_bootstrap_config', function() {
    // Find variables.less in bootstrap_path
    var bootstrap_config_path = grunt.file.expand({ cwd: bootstrap_path }, '**/variables.less')[0];
    if (bootstrap_config_path) {
      grunt.log.writeln('Copying Bootstrap variables: ' + bootstrap_config_path);

      // Copy variables.less
      grunt.file.copy(path.join(bootstrap_path, bootstrap_config_path), 'less/variables.less');

      return true;
    }
    grunt.log.writeln('Bootstrap variables not found!');

    // Find config.json in bootstrap_path
    var bootstrap_config_path = grunt.file.expand({ cwd: bootstrap_path }, '**/config.json')[0];
    if (! bootstrap_config_path) {
      grunt.log.error('Bootstrap config not found!');

      return false;
    }
    grunt.log.writeln('Parsing Bootstrap config: ' + bootstrap_config_path);

    // Parse config.json
    var bootstrap_config = grunt.file.readJSON(path.join(bootstrap_path, bootstrap_config_path));
    var variables = '';
    for (var key in bootstrap_config.vars) {
      variables += key + ':\t' + bootstrap_config.vars[key] + ';\n';
    }

    // Generate variables.less
    grunt.file.write('less/variables.less', variables);

    return true;
  });

  // Default task including everything
  grunt.registerTask('default', ['clean', 'copy', 'copy_samples', 'xsltproc', 'parse_bootstrap_config', 'less', 'autoprefixer', 'csslint', 'cssmin', 'htmlmin', 'connect']);
  // Everything except minification
  grunt.registerTask('debug', ['clean', 'copy', 'copy_samples', 'xsltproc', 'parse_bootstrap_config', 'less', 'autoprefixer', 'csslint', 'connect']);
};
<|endoftext|>


<commit_before>/**
 * sivart-ci v0.1.0
 *
 * A simple interactive CI Dashboard built on MEAN stack.
 *
 * Author: Kushal Pandya <kushalspandya@gmail.com> (https://doublslash.com)
 * Date: 28 November, 2015
 *
 * Sivart Grunt Automation.
 */

/**
 * Initialize global grunt method.
 */
module.exports = function(grunt) {
    var compassDirConfig,
        fnMergeConfig;

    /**
	 * Simple method to merge Objects passed as arguments and return a new Object.
	 */
	fnMergeConfig = function() {
		var obj = {},
			i = 0,
			argl = arguments.length,
			key;

		for (; i < argl; i++) {
			for (key in arguments[i]) {
				if (arguments[i].hasOwnProperty(key))
				{
					obj[key] = arguments[i][key];
				}
			}
		}

		return obj;
	};

    compassDirConfig = {
        imagesDir: 'public/images/src',
        generatedImagesDir: 'public/images/dist',
        httpGeneratedImagesPath: '/images/dist',
        imagesPath: '/images/dist',
        httpImagesPath: '/images/dist',

        sassDir: 'public/scss',
        cssDir: 'public/css',

        noLineComments: true
    };

    /* Initializer configuration */
    grunt.initConfig({

        // Package to run tasks on.
        pkg: grunt.file.readJSON('package.json'),

        compass: {
            dev: {
                options: fnMergeConfig(compassDirConfig, { watch: true, sourcemap: true })
            },
            devbuild: {
                options: fnMergeConfig(compassDirConfig, { force: false, sourcemap: true })
            },
            dist: {
                options: fnMergeConfig(compassDirConfig, { outputStyle: 'compressed' })
            },
            clean: {
                options: fnMergeConfig(dirConfig, { clean: true })
            }
        }
    });

    /* Load tasks */
	grunt.loadNpmTasks('grunt-contrib-compass');

    /* Register tasks */

	/**
	 * Default task, runs Compass in developer mode and
	 * watches for changes SASS files to compile them to CSS upon every modification.
	 */
	grunt.registerTask('default', ['compass:dev']);

    /**
	 * Developer Build task;
	 * 1) Recompiles all SCSS files into CSS (compass:dist).
	 */
	grunt.registerTask('devbuild', ['compass:clean', 'compass:devbuild']);

    /**
	 * Clean task, cleans generated CSS and images and creates
	 * them again with default configuration.
	 */
	grunt.registerTask('clean', ['compass:clean', 'compass:dist']);

    /**
     * Build task;
     * 1) Cleans generated CSS and images (compass:clean).
     * 2) Recompiles all SCSS files into CSS (compass:dist).
     */
    grunt.registerTask('build', ['compass:clean', 'compass:dist']);
};
<commit_msg>Typo fixed for dirConfig.<commit_after>/**
 * sivart-ci v0.1.0
 *
 * A simple interactive CI Dashboard built on MEAN stack.
 *
 * Author: Kushal Pandya <kushalspandya@gmail.com> (https://doublslash.com)
 * Date: 28 November, 2015
 *
 * Sivart Grunt Automation.
 */

/**
 * Initialize global grunt method.
 */
module.exports = function(grunt) {
    var compassDirConfig,
        fnMergeConfig;

    /**
	 * Simple method to merge Objects passed as arguments and return a new Object.
	 */
	fnMergeConfig = function() {
		var obj = {},
			i = 0,
			argl = arguments.length,
			key;

		for (; i < argl; i++) {
			for (key in arguments[i]) {
				if (arguments[i].hasOwnProperty(key))
				{
					obj[key] = arguments[i][key];
				}
			}
		}

		return obj;
	};

    compassDirConfig = {
        imagesDir: 'public/images/src',
        generatedImagesDir: 'public/images/dist',
        httpGeneratedImagesPath: '/images/dist',
        imagesPath: '/images/dist',
        httpImagesPath: '/images/dist',

        sassDir: 'public/scss',
        cssDir: 'public/css',

        noLineComments: true
    };

    /* Initializer configuration */
    grunt.initConfig({

        // Package to run tasks on.
        pkg: grunt.file.readJSON('package.json'),

        compass: {
            dev: {
                options: fnMergeConfig(compassDirConfig, { watch: true, sourcemap: true })
            },
            devbuild: {
                options: fnMergeConfig(compassDirConfig, { force: false, sourcemap: true })
            },
            dist: {
                options: fnMergeConfig(compassDirConfig, { outputStyle: 'compressed' })
            },
            clean: {
                options: fnMergeConfig(compassDirConfig, { clean: true })
            }
        }
    });

    /* Load tasks */
	grunt.loadNpmTasks('grunt-contrib-compass');

    /* Register tasks */

	/**
	 * Default task, runs Compass in developer mode and
	 * watches for changes SASS files to compile them to CSS upon every modification.
	 */
	grunt.registerTask('default', ['compass:dev']);

    /**
	 * Developer Build task;
	 * 1) Recompiles all SCSS files into CSS (compass:dist).
	 */
	grunt.registerTask('devbuild', ['compass:clean', 'compass:devbuild']);

    /**
	 * Clean task, cleans generated CSS and images and creates
	 * them again with default configuration.
	 */
	grunt.registerTask('clean', ['compass:clean', 'compass:dist']);

    /**
     * Build task;
     * 1) Cleans generated CSS and images (compass:clean).
     * 2) Recompiles all SCSS files into CSS (compass:dist).
     */
    grunt.registerTask('build', ['compass:clean', 'compass:dist']);
};
<|endoftext|>


<commit_before>// './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html', './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html', './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html', './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html', './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html', './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html'

/*
 * grunt-html-head-urls-min-toggle
 * https://github.com/pinestec/html-head-urls-min-toggle
 *
 * Copyright (c) 2017 Michael Hartung
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

	// Project configuration.
	grunt.initConfig({
	  jshint : {
	    all : [ 'Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>' ],
	    options : {
	      jshintrc : '.jshintrc',
	      reporterOutput : ""
	    }
	  },

	  // Before generating any new files, remove any previously-created files.
	  clean : {
		  tests : [ 'tmp' ]
	  },

	  // Configuration to be run (and then tested).
	  html_head_urls_min_toggle : {
	    default_options : {
	      options : {},
	      files : {
		      'tmp/default_options' : [ 'test/fixtures/testing', 'test/fixtures/123' ]
	      }
	    },
	    custom_options : {
	      options : {
	        separator : ': ',
	        punctuation : ' !!!'
	      },
	      files : {
		      'tmp/custom_options' : [ 'test/fixtures/testing', 'test/fixtures/123' ]
	      }
	    },
	    targets : {
	      min_targets : [ './bash_sed_perl.max.html', './current_commented_places.max.html',
	          './git_files__get_prepare.max.html', './index.max.html', './linksys_quick_rebirth.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './node_js_with_grunt.max.html',
	          './regular_expression_snippets.max.html', './ssh_pearls.max.html', './windows_certificate_related.max.html' ],
	      regular_targets : [ './ctos_np.max.html', './eclipse_related.max.html', './graphicsWorkCurrentMemory.max.html',
	          './jquery_pearls.max.html', './linux.max.html', './mp4todvd.max.html', './quickcmds.max.html',
	          './ssh_key_generation.max.html', './useful_apps_steppingstone.max.html' ],
	    },
	    switch_targets_back_and_forth : {
	      min_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
	          './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
	          './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
	          './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
	          './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ],
	      regular_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
	          './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
	          './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
	          './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
	          './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ],
	    },
	    before_TARGETS_behind : {
	      min_targets : [ './bash_sed_perl.max.html', './current_commented_places.max.html',
	          './git_files__get_prepare.max.html', './index.max.html', './linksys_quick_rebirth.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './node_js_with_grunt.max.html',
	          './regular_expression_snippets.max.html', './ssh_pearls.max.html', './windows_certificate_related.max.html' ],
	      regular_targets : [ './ctos_np.max.html', './eclipse_related.max.html', './graphicsWorkCurrentMemory.max.html',
	          './jquery_pearls.max.html', './linux.max.html', './mp4todvd.max.html', './quickcmds.max.html',
	          './ssh_key_generation.max.html', './useful_apps_steppingstone.max.html' ],
	    },
	    targets_to_minified_files : {
		    min_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
		        './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
		        './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
		        './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
		        './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
		        './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ]
	    },
	    targets_to_regular_files : {
		    regular_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
		        './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
		        './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
		        './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
		        './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
		        './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ]
	    },
	    targets_to_no_files : {},
	    no_files_targets : {},
	    single_target_min : {
		    min_targets : [ './index.max.html' ]
	    },
	    single_target_regular : {
		    regular_targets : [ './index.max.html' ]
	    }
	  },

	  // Unit tests.
	  nodeunit : {
		  tests : [ 'test/*_test.js' ]
	  }

	});

	// Actually load this plugin's task(s).
	grunt.loadTasks('tasks');

	// These plugins provide necessary tasks.
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-nodeunit');

	// Whenever the "test" task is run, first clean the "tmp" dir, then run this
	// plugin's task(s), then test the result.
	grunt.registerTask('test', [ 'clean', 'html_head_urls_min_toggle', 'nodeunit' ]);

	// By default, lint and run all tests.
	grunt.registerTask('default', [ 'jshint', 'test' ]);

	grunt.registerTask('dt', 'html_head_urls_min_toggle:targets');
	grunt.registerTask('m', 'html_head_urls_min_toggle:targets_to_minified_files');
	grunt.registerTask('r', 'html_head_urls_min_toggle:targets_to_regular_files');
	grunt.registerTask('e', 'html_head_urls_min_toggle:targets_to_no_files');
	grunt.registerTask('n', 'html_head_urls_min_toggle:no_files_targets');
	grunt.registerTask('x', 'html_head_urls_min_toggle:before_TARGETS_behind');
	grunt.registerTask('s', 'html_head_urls_min_toggle:switch_targets_back_and_forth');
	grunt.registerTask('sm', 'html_head_urls_min_toggle:single_target_min');
	grunt.registerTask('sr', 'html_head_urls_min_toggle:single_target_regular');

};
<commit_msg>Expanded grunt with w and no errors... - MH - PT<commit_after>// './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html', './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html', './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html', './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html', './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html', './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html'

/*
 * grunt-html-head-urls-min-toggle
 * https://github.com/pinestec/html-head-urls-min-toggle
 *
 * Copyright (c) 2017 Michael Hartung
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

	// Project configuration.
	grunt.initConfig({
	  jshint : {
	    all : [ 'Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>' ],
	    options : {
	      jshintrc : '.jshintrc',
	      reporterOutput : ""
	    }
	  },

	  // Before generating any new files, remove any previously-created files.
	  clean : {
		  tests : [ 'tmp' ]
	  },

	  // Configuration to be run (and then tested).
	  html_head_urls_min_toggle : {
	    default_options : {
	      options : {},
	      files : {
		      'tmp/default_options' : [ 'test/fixtures/testing', 'test/fixtures/123' ]
	      }
	    },
	    custom_options : {
	      options : {
	        separator : ': ',
	        punctuation : ' !!!'
	      },
	      files : {
		      'tmp/custom_options' : [ 'test/fixtures/testing', 'test/fixtures/123' ]
	      }
	    },
	    wildcard_targets : {
		    files : [ {
		      expand : true,
		      direction : 'min',
		      cwd : './',
		      src : [ '*.max.html' ]
		    } ]
	    },
	    targets : {
	      min_targets : [ './bash_sed_perl.max.html', './current_commented_places.max.html',
	          './git_files__get_prepare.max.html', './index.max.html', './linksys_quick_rebirth.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './node_js_with_grunt.max.html',
	          './regular_expression_snippets.max.html', './ssh_pearls.max.html', './windows_certificate_related.max.html' ],
	      regular_targets : [ './ctos_np.max.html', './eclipse_related.max.html', './graphicsWorkCurrentMemory.max.html',
	          './jquery_pearls.max.html', './linux.max.html', './mp4todvd.max.html', './quickcmds.max.html',
	          './ssh_key_generation.max.html', './useful_apps_steppingstone.max.html' ],
	    },
	    switch_targets_back_and_forth : {
	      min_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
	          './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
	          './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
	          './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
	          './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ],
	      regular_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
	          './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
	          './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
	          './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
	          './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ],
	    },
	    before_TARGETS_behind : {
	      min_targets : [ './bash_sed_perl.max.html', './current_commented_places.max.html',
	          './git_files__get_prepare.max.html', './index.max.html', './linksys_quick_rebirth.max.html',
	          './loginBasedPrivacyKeyManagement.max.html', './node_js_with_grunt.max.html',
	          './regular_expression_snippets.max.html', './ssh_pearls.max.html', './windows_certificate_related.max.html' ],
	      regular_targets : [ './ctos_np.max.html', './eclipse_related.max.html', './graphicsWorkCurrentMemory.max.html',
	          './jquery_pearls.max.html', './linux.max.html', './mp4todvd.max.html', './quickcmds.max.html',
	          './ssh_key_generation.max.html', './useful_apps_steppingstone.max.html' ],
	    },
	    targets_to_minified_files : {
		    min_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
		        './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
		        './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
		        './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
		        './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
		        './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ]
	    },
	    targets_to_regular_files : {
		    regular_targets : [ './bash_sed_perl.max.html', './ctos_np.max.html', './current_commented_places.max.html',
		        './eclipse_related.max.html', './git_files__get_prepare.max.html', './graphicsWorkCurrentMemory.max.html',
		        './index.max.html', './jquery_pearls.max.html', './linksys_quick_rebirth.max.html', './linux.max.html',
		        './loginBasedPrivacyKeyManagement.max.html', './mp4todvd.max.html', './node_js_with_grunt.max.html',
		        './quickcmds.max.html', './regular_expression_snippets.max.html', './ssh_key_generation.max.html',
		        './ssh_pearls.max.html', './useful_apps_steppingstone.max.html', './windows_certificate_related.max.html' ]
	    },
	    targets_to_no_files : {},
	    no_files_targets : {},
	    single_target_min : {
		    min_targets : [ './index.max.html' ]
	    },
	    single_target_regular : {
		    regular_targets : [ './index.max.html' ]
	    }
	  },

	  // Unit tests.
	  nodeunit : {
		  tests : [ 'test/*_test.js' ]
	  }

	});

	// Actually load this plugin's task(s).
	grunt.loadTasks('tasks');

	// These plugins provide necessary tasks.
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-nodeunit');

	// Whenever the "test" task is run, first clean the "tmp" dir, then run this
	// plugin's task(s), then test the result.
	grunt.registerTask('test', [ 'clean', 'html_head_urls_min_toggle', 'nodeunit' ]);

	// By default, lint and run all tests.
	grunt.registerTask('default', [ 'jshint', 'test' ]);

	grunt.registerTask('dt', 'html_head_urls_min_toggle:targets');
	grunt.registerTask('m', 'html_head_urls_min_toggle:targets_to_minified_files');
	grunt.registerTask('r', 'html_head_urls_min_toggle:targets_to_regular_files');
	grunt.registerTask('e', 'html_head_urls_min_toggle:targets_to_no_files');
	grunt.registerTask('n', 'html_head_urls_min_toggle:no_files_targets');
	grunt.registerTask('x', 'html_head_urls_min_toggle:before_TARGETS_behind');
	grunt.registerTask('s', 'html_head_urls_min_toggle:switch_targets_back_and_forth');
	grunt.registerTask('sm', 'html_head_urls_min_toggle:single_target_min');
	grunt.registerTask('sr', 'html_head_urls_min_toggle:single_target_regular');
	grunt.registerTask('w', 'html_head_urls_min_toggle:wildcard_targets');
};
<|endoftext|>