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

  var fs = require('fs');
  var bower = require('bower');
  require('es6-shim');
  var mime = require('mime');
  var path = require('path');

  var pkgFile = require('./package.json');
  var lyriaConfig = pkgFile.lyriaProject || {};

  var buildPrefix = 'builds';
  var buildVersion = pkgFile.version + '-' + grunt.template.today("yymmdd-HHMMss");
  var buildId = pkgFile.name + '-v' + buildVersion;
  var buildFolder = [buildPrefix, buildId].join('/');

  var libFiles = (fs.existsSync('./lib')) ? fs.readdirSync('./lib') : [];
  var styleFiles = (fs.existsSync('./css')) ? fs.readdirSync('./css') : [];

  var libFilesPriorities = ['almond', 'handlebars', 'fastclick', 'udefine'];

  var templateScripts = {
    development: [],
    production: []
  };
  var templateStyles = [];

  var uglifyLibObject = {};

  for (var i = 0, j = libFiles.length; i < j; i++) {
    (function(iterator) {
      uglifyLibObject[path.join(buildFolder, 'lib', iterator)] = path.join('./lib', iterator);
      if (libFilesPriorities.indexOf(iterator) >= 0) {
        templateScripts.unshift('lib/' + iterator);
      } else {
        templateScripts.push('lib/' + iterator);
      }
    })(libFiles[i]);
  }

  uglifyLibObject[buildFolder + '/js/<%= pkg.name %>.js'] = '<%= concat_sourcemap.dist.dest %>';
  //templateScripts.push('js/<%= pkg.name %>.js');

  for (var k = 0, l = styleFiles.length; k < l; k++) {
    (function(iterator) {
      templateStyles.push('css/' + iterator);
    })(styleFiles[k]);
  }

  grunt.initConfig({
    pkg: pkgFile,
    lyriaConfig: lyriaConfig,
    buildVersion: buildVersion,
    buildFolder: buildFolder,
    concat_sourcemap: {
      options: {
        sourcesContent: true,
        sourceRoot: '/'
      },
      dist: {
        src: ['src/**/*.js'],
        dest: 'js/<%= pkg.name %>.js'
      }
    },
    copy: {
      production: {
        files: [{
          expand: true,
          src: ['assets/**'],
          dest: '<%= buildFolder %>/',
          filter: function(filepath) {
            if ((filepath.indexOf('/scenes') >= 0) || (filepath.indexOf('/prefabs') >= 0)) {
              return false;
            } else {
              return true;
            }
          }
        }, {
          expand: true,
          src: ['css/**'],
          dest: '<%= buildFolder %>/'
        }, {
          expand: true,
          src: ['favicon.ico'],
          dest: '<%= buildFolder %>/'
        }, {
          expand: true,
          src: ['*.png'],
          dest: '<%= buildFolder %>/'
        }]
      }
    },
    template: {
      development: {
        src: 'template.html',
        dest: 'index.html',
        engine: 'handlebars',
        variables: {
          livereload: true,
          scripts: templateScripts.development,
          styles: templateStyles,
          mainModule: pkgFile.name,
          title: '<%= lyriaConfig.title %> (Development build <%= buildVersion %>)',
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      },
      production: {
        src: 'template.html',
        dest: '<%= buildFolder %>/index.html',
        engine: 'handlebars',
        variables: {
          livereload: false,
          scripts: templateScripts.production,
          styles: templateStyles,
          mainModule: pkgFile.name,
          title: lyriaConfig.title,
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      }
    },
    uglify: {
      production: {
        files: uglifyLibObject
      }
    },
    compress: {
      deploy: {
        options: {
          archive: '<%= buildFolder %>.zip'
        },
        files: [{
          cwd: '<%= buildFolder %>/',
          src: ['**'],
          dest: '<%= pkg.name %>/'
        }]
      }
    },
    stylus: {
      options: {
        paths: ['stylus'],
        urlfunc: 'embedurl',
        import: ['nib'],
      },
      development: {
        options: {
          compress: false,
          linenos: true
        },
        files: {
          'css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      },
      production: {
        options: {
          compress: true
        },
        files: {
          '<%= buildFolder %>/css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      }
    },
    csslint: {
      lint: {
        src: ['css/mygame.css']
      }
    },
    jshint: {
      assets: {
        src: ['assets/**/*.js']
      },
      source: {
        src: ['src/**/*.js', '!src/generated/**/*.js']
      }
    },
    watch: {
      options: {
        // Start a live reload server on the default port 35729
        livereload: true,
      },
      stylus: {
        files: 'stylus/**/*.styl',
        tasks: ['stylus']
      },
      prepare: {
        files: 'assets/**/*',
        tasks: ['prepare']
      },
      template: {
        files: 'template.html',
        tasks: ['template:development']
      },
      concat: {
        files: 'src/**/*.js',
        tasks: ['concat_sourcemap']
      }
    }
  });

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  var prepareScenes = require('./preparescenes');

  grunt.registerMultiTask('assetArray', 'Updated asset array', function() {
    var files = this.filesSrc;

    for (var i = 0, j = files.length; i < j; i++) {
      (function(file) {

      })(files[i]);
    }
  });

  grunt.registerTask('prepare', 'Updates asset array and prepares scenes', function() {
    var done = this.async();
    var dir = './';
    var projectName = pkgFile.name;
    var assetObject = {};

    grunt.file.recurse(path.join(dir, 'assets'), function(abspath, rootdir, subdir, filename) {
      var stat;
      var dirname;

      if (subdir == null) {
        subdir = '';
      }

      if ((filename.toLowerCase().indexOf('readme') >= 0) || (subdir.indexOf('scenes') >= 0) || (subdir.indexOf('prefabs') >= 0) || (subdir.indexOf('gameobjects') >= 0) || (filename.indexOf('.') === 0)) {
        return;
      }

      if (!subdir) {
        dirname = 'root';
      } else {
        dirname = subdir;
      }

      assetObject[dirname] = assetObject[subdir] || {};
      stat = fs.statSync(abspath);
      assetObject[dirname].files = assetObject[dirname].files || [];
      assetObject[dirname].files.push({
        name: abspath,
        type: mime.lookup(abspath),
        size: stat.size
      });
      if (assetObject[dirname].totalSize) {
        assetObject[dirname].totalSize += stat.size;
      } else {
        assetObject[dirname].totalSize = stat.size;
      }
    });

    var assetSize = 0;
    var value;
    for (var key in assetObject) {
      value = assetObject[key];

      assetSize += value.totalSize;
    }

    assetObject.totalSize = assetSize;

    grunt.file.write(path.join(dir, 'src', 'generated', 'assetlist.js'), 'define("' + projectName + '/assetlist",' + JSON.stringify(assetObject) + ');');

    prepareScenes(projectName, path.join(dir, 'assets', 'scenes'), path.join(dir, 'src', 'generated', 'scenelist.js'), function() {
      grunt.log.writeln('Project built');
      done();
    });
  });

  grunt.registerTask('bower', 'Prepares scripts using bower components', function() {
    var done = this.async();

    bower.commands.list({
      paths: true
    }).on('end', function(results) {
      for (var key in results) {
        var val = results[key];

        if (val.indexOf(',') >= 0) {
          val = val.split(',');
        }

        var value = '';
        if (Array.isArray(val)) {
          if (key === 'handlebars') {
            value = val[1];
          }

          for (var i = 0, j = val.length; i < j; i++) {
            if ((path.extname(val[i]) === '.js') && !val[i].endsWith('.min.js')) {
              value = val[i];
              break;
            }
          }
        } else {
          value = val;
        }
        var value = path.relative(process.cwd(), value);

        if (!value.endsWith('.css')) {

          if (!value.endsWith('.js')) {
            value += path.sep + key + '.js';
          }

          if (libFilesPriorities.indexOf(key) >= 0) {
            templateScripts.development.unshift(value);
          } else {
            templateScripts.development.push(value);
          }

        }

      }

      templateScripts.development.push('js/<%= pkg.name %>.js');

      grunt.task.run('template:development');
      done();
    });
  });

  grunt.registerTask('prebuild', 'Task before building the project', ['prepare', 'concat_sourcemap', 'bower']);
  grunt.registerTask('test', 'Lints JavaScript and CSS files', ['jshint']);

  grunt.registerTask('development', 'Development build', ['prebuild', 'stylus:development']);
  grunt.registerTask('production', 'Production build', ['prebuild', 'uglify', 'copy', 'stylus:production', 'template:production']);
  grunt.registerTask('deploy', 'Deploys project', ['production', 'compress:deploy']);

  grunt.registerTask('build', 'Builds the default project', ['development']);
  grunt.registerTask('default', 'Default task', ['development']);

};<commit_msg>Fixes watch triggering to many tasks<commit_after>module.exports = function(grunt) {

  var fs = require('fs');
  var bower = require('bower');
  require('es6-shim');
  var mime = require('mime');
  var path = require('path');

  var pkgFile = require('./package.json');
  var lyriaConfig = pkgFile.lyriaProject || {};

  var buildPrefix = 'builds';
  var buildVersion = pkgFile.version + '-' + grunt.template.today("yymmdd-HHMMss");
  var buildId = pkgFile.name + '-v' + buildVersion;
  var buildFolder = [buildPrefix, buildId].join('/');

  var libFiles = (fs.existsSync('./lib')) ? fs.readdirSync('./lib') : [];
  var styleFiles = (fs.existsSync('./css')) ? fs.readdirSync('./css') : [];

  var libFilesPriorities = ['almond', 'handlebars', 'fastclick', 'udefine'];

  var templateScripts = {
    development: [],
    production: []
  };
  var templateStyles = [];

  var uglifyLibObject = {};

  for (var i = 0, j = libFiles.length; i < j; i++) {
    (function(iterator) {
      uglifyLibObject[path.join(buildFolder, 'lib', iterator)] = path.join('./lib', iterator);
      if (libFilesPriorities.indexOf(iterator) >= 0) {
        templateScripts.unshift('lib/' + iterator);
      } else {
        templateScripts.push('lib/' + iterator);
      }
    })(libFiles[i]);
  }

  uglifyLibObject[buildFolder + '/js/<%= pkg.name %>.js'] = '<%= concat_sourcemap.dist.dest %>';
  //templateScripts.push('js/<%= pkg.name %>.js');

  for (var k = 0, l = styleFiles.length; k < l; k++) {
    (function(iterator) {
      templateStyles.push('css/' + iterator);
    })(styleFiles[k]);
  }

  grunt.initConfig({
    pkg: pkgFile,
    lyriaConfig: lyriaConfig,
    buildVersion: buildVersion,
    buildFolder: buildFolder,
    concat_sourcemap: {
      options: {
        sourcesContent: true,
        sourceRoot: '/'
      },
      dist: {
        src: ['src/**/*.js'],
        dest: 'js/<%= pkg.name %>.js'
      }
    },
    copy: {
      production: {
        files: [{
          expand: true,
          src: ['assets/**'],
          dest: '<%= buildFolder %>/',
          filter: function(filepath) {
            if ((filepath.indexOf('/scenes') >= 0) || (filepath.indexOf('/prefabs') >= 0)) {
              return false;
            } else {
              return true;
            }
          }
        }, {
          expand: true,
          src: ['css/**'],
          dest: '<%= buildFolder %>/'
        }, {
          expand: true,
          src: ['favicon.ico'],
          dest: '<%= buildFolder %>/'
        }, {
          expand: true,
          src: ['*.png'],
          dest: '<%= buildFolder %>/'
        }]
      }
    },
    template: {
      development: {
        src: 'template.html',
        dest: 'index.html',
        engine: 'handlebars',
        variables: {
          livereload: true,
          scripts: templateScripts.development,
          styles: templateStyles,
          mainModule: pkgFile.name,
          title: '<%= lyriaConfig.title %> (Development build <%= buildVersion %>)',
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      },
      production: {
        src: 'template.html',
        dest: '<%= buildFolder %>/index.html',
        engine: 'handlebars',
        variables: {
          livereload: false,
          scripts: templateScripts.production,
          styles: templateStyles,
          mainModule: pkgFile.name,
          title: lyriaConfig.title,
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      }
    },
    uglify: {
      production: {
        files: uglifyLibObject
      }
    },
    compress: {
      deploy: {
        options: {
          archive: '<%= buildFolder %>.zip'
        },
        files: [{
          cwd: '<%= buildFolder %>/',
          src: ['**'],
          dest: '<%= pkg.name %>/'
        }]
      }
    },
    stylus: {
      options: {
        paths: ['stylus'],
        urlfunc: 'embedurl',
        import: ['nib'],
      },
      development: {
        options: {
          compress: false,
          linenos: true
        },
        files: {
          'css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      },
      production: {
        options: {
          compress: true
        },
        files: {
          '<%= buildFolder %>/css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      }
    },
    csslint: {
      lint: {
        src: ['css/mygame.css']
      }
    },
    jshint: {
      assets: {
        src: ['assets/**/*.js']
      },
      source: {
        src: ['src/**/*.js', '!src/generated/**/*.js']
      }
    },
    watch: {
      options: {
        // Start a live reload server on the default port 35729
        livereload: true,
      },
      stylus: {
        files: 'stylus/**/*.styl',
        tasks: ['stylus:development']
      },
      prepare: {
        files: 'assets/**/*',
        tasks: ['prepare']
      },
      template: {
        files: 'template.html',
        tasks: ['template:development']
      },
      concat: {
        files: 'src/**/*.js',
        tasks: ['concat_sourcemap']
      }
    }
  });

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  var prepareScenes = require('./preparescenes');

  grunt.registerMultiTask('assetArray', 'Updated asset array', function() {
    var files = this.filesSrc;

    for (var i = 0, j = files.length; i < j; i++) {
      (function(file) {

      })(files[i]);
    }
  });

  grunt.registerTask('prepare', 'Updates asset array and prepares scenes', function() {
    var done = this.async();
    var dir = './';
    var projectName = pkgFile.name;
    var assetObject = {};

    grunt.file.recurse(path.join(dir, 'assets'), function(abspath, rootdir, subdir, filename) {
      var stat;
      var dirname;

      if (subdir == null) {
        subdir = '';
      }

      if ((filename.toLowerCase().indexOf('readme') >= 0) || (subdir.indexOf('scenes') >= 0) || (subdir.indexOf('prefabs') >= 0) || (subdir.indexOf('gameobjects') >= 0) || (filename.indexOf('.') === 0)) {
        return;
      }

      if (!subdir) {
        dirname = 'root';
      } else {
        dirname = subdir;
      }

      assetObject[dirname] = assetObject[subdir] || {};
      stat = fs.statSync(abspath);
      assetObject[dirname].files = assetObject[dirname].files || [];
      assetObject[dirname].files.push({
        name: abspath,
        type: mime.lookup(abspath),
        size: stat.size
      });
      if (assetObject[dirname].totalSize) {
        assetObject[dirname].totalSize += stat.size;
      } else {
        assetObject[dirname].totalSize = stat.size;
      }
    });

    var assetSize = 0;
    var value;
    for (var key in assetObject) {
      value = assetObject[key];

      assetSize += value.totalSize;
    }

    assetObject.totalSize = assetSize;

    grunt.file.write(path.join(dir, 'src', 'generated', 'assetlist.js'), 'define("' + projectName + '/assetlist",' + JSON.stringify(assetObject) + ');');

    prepareScenes(projectName, path.join(dir, 'assets', 'scenes'), path.join(dir, 'src', 'generated', 'scenelist.js'), function() {
      grunt.log.writeln('Project built');
      done();
    });
  });

  grunt.registerTask('bower', 'Prepares scripts using bower components', function() {
    var done = this.async();

    bower.commands.list({
      paths: true
    }).on('end', function(results) {
      for (var key in results) {
        var val = results[key];

        if (val.indexOf(',') >= 0) {
          val = val.split(',');
        }

        var value = '';
        if (Array.isArray(val)) {
          if (key === 'handlebars') {
            value = val[1];
          }

          for (var i = 0, j = val.length; i < j; i++) {
            if ((path.extname(val[i]) === '.js') && !val[i].endsWith('.min.js')) {
              value = val[i];
              break;
            }
          }
        } else {
          value = val;
        }
        var value = path.relative(process.cwd(), value);

        if (!value.endsWith('.css')) {

          if (!value.endsWith('.js')) {
            value += path.sep + key + '.js';
          }

          if (libFilesPriorities.indexOf(key) >= 0) {
            templateScripts.development.unshift(value);
          } else {
            templateScripts.development.push(value);
          }

        }

      }

      templateScripts.development.push('js/<%= pkg.name %>.js');

      grunt.task.run('template:development');
      done();
    });
  });

  grunt.registerTask('prebuild', 'Task before building the project', ['prepare', 'concat_sourcemap', 'bower']);
  grunt.registerTask('test', 'Lints JavaScript and CSS files', ['jshint']);

  grunt.registerTask('development', 'Development build', ['prebuild', 'stylus:development']);
  grunt.registerTask('production', 'Production build', ['prebuild', 'uglify', 'copy', 'stylus:production', 'template:production']);
  grunt.registerTask('deploy', 'Deploys project', ['production', 'compress:deploy']);

  grunt.registerTask('build', 'Builds the default project', ['development']);
  grunt.registerTask('default', 'Default task', ['development']);

};<|endoftext|>


<commit_before>module.exports = function(grunt) {
  'use strict';

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

    jshint: {
      files: ['app/scripts/*.js'],
      options: {
        reporter: require('jshint-stylish'),
        jshintrc: true
      }
    },

    jasmine: {
      app : {
        src: 'app/scripts/*.js',
        options: {
          specs: 'test/js/spec.*.js'
        }
      }
    },

    uglify: {
      main: {
        options: {
          beautify: false
        },
        files: {
          'app/build/js/main.min.js': 'app/build/js/main.js'
        }
      }
    },

    concat: {
      dist: {
        src: ['app/scripts/app.js', 'app/vendor/jQuery/dist/jquery.min.js'],
        dest: 'app/build/js/main.js'
      }
    },

    watch: {
      options: {
        interrupt: true,
        spawn: false
      },
      css: {
        files: ['app/styles/**/*.scss'],
        tasks: ['sass']
      },
      js: {
        files: ['app/scripts/**/*.js'],
        tasks: ['jshint', 'concat', 'uglify']
      },
      grunt: {
        options: {
          reload: true
        },
        files: ['gruntfile.js']
      }
    },

    sass: {
      options: {
        style: 'nested',
        sourceMap: true
      },
      dist: {
        files: {
          'app/build/css/style.css' : 'app/styles/style.scss'
        }
      }
    },

    connect: {
      server: {
        options: {
          hostname: '127.0.0.1',
          port: 8888,
          base: '.',
          keepalive: false
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-contrib-concat');

  grunt.registerTask('default', ['connect:server', 'watch']);

};
<commit_msg>Add task for jasmine tests<commit_after>module.exports = function(grunt) {
  'use strict';

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

    jshint: {
      files: ['app/scripts/*.js'],
      options: {
        reporter: require('jshint-stylish'),
        jshintrc: true
      }
    },

    jasmine: {
      app : {
        src: 'app/scripts/*.js',
        options: {
          specs: 'test/js/spec.*.js'
        }
      }
    },

    uglify: {
      main: {
        options: {
          beautify: false
        },
        files: {
          'app/build/js/main.min.js': 'app/build/js/main.js'
        }
      }
    },

    concat: {
      dist: {
        src: ['app/scripts/app.js', 'app/vendor/jQuery/dist/jquery.min.js'],
        dest: 'app/build/js/main.js'
      }
    },

    watch: {
      options: {
        interrupt: true,
        spawn: false
      },
      css: {
        files: ['app/styles/**/*.scss'],
        tasks: ['sass']
      },
      js: {
        files: ['app/scripts/**/*.js'],
        tasks: ['jshint', 'concat', 'uglify']
      },
      grunt: {
        options: {
          reload: true
        },
        files: ['gruntfile.js']
      }
    },

    sass: {
      options: {
        style: 'nested',
        sourceMap: true
      },
      dist: {
        files: {
          'app/build/css/style.css' : 'app/styles/style.scss'
        }
      }
    },

    connect: {
      server: {
        options: {
          hostname: '127.0.0.1',
          port: 8888,
          base: '.',
          keepalive: false
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-contrib-concat');

  grunt.registerTask('default', ['connect:server', 'watch']);
  grunt.registerTask('test', ['jasmine']);

};
<|endoftext|>


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

  // configure the tasks
  grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),
    /*
      Copy clean sources to /build
    */
    copy: {
      build: {
        cwd: 'src',
        src: ['!**/*.styl', '!**/*.pug'],
        dest: 'build',
        expand: true
      },
    },

    /*
      Remove leftover sources from /build
    */
    clean: {
      build: {
        src: ['build']
      },
      stylesheets: {
        src: ['build/**/*.css']
      },
    },

    /*
      Compile Stylus-files
    */
    stylus: {
      build: {
        options: {
          compress: false
        },
        files : {
          'build/<%= pkg.namespace %>.css': 'src/**/<%= pkg.namespace %>.styl'
        }
      }
    },

    /*
      Run PostCSS to handle autoprefixing etc.
    */
    postcss: {
      build: {
        files: {
          'build/<%= pkg.namespace %>.css': 'build/**/*.css'
        }
      }
    },

    /*
      Compile a minified version of base CSS-file
    */
    cssmin: {
      build: {
        files: {
          'build/<%= pkg.namespace %>.min.css': 'build/**/*.css'
        }
      }
    },

    /*
      Compile .pug to .html
    */
    pug: {
      compile: {
        options: {
          pretty: true,
          data: {name: '<%= pkg.name %>', namespace: '<%= pkg.namespace %>', version: '<%= pkg.version %>'}
        },
        files: [{
          expand: true,
          cwd: 'src/pug/',
          src: ['**/*.pug'],
          dest: 'build/demo/',
          ext: '.html'
        }]
      }
    },

    /*
      Watch for changes in stylesheets, pugs and copies
    */
    watch: {
      stylesheets: {
        files: 'src/**/*.styl',
        tasks: ['stylesheets'],
        options: {
          livereload: true,
        },
      },
      pug: {
        files: 'src/**/*.pug',
        tasks: ['pug'],
        options: {
          livereload: true,
        },
      },
      copy: {
        files: ['src/**', '!src/**/*.styl', '!src/**/*.pug'],
        tasks: ['copy']
      }
    },

    /*
      Set up local server
    */
    connect: {
      server: {
        options: {
          port: 4999,
          base: 'build',
          hostname: 'localhost'
        }
      }
    }

  });

  /*
    Load tasks
  */
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-stylus');
  grunt.loadNpmTasks('grunt-postcss');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-pug');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-connect');

  /*
    Register stylesheet task. Handles all Stylus/CSS tasks
  */
  grunt.registerTask(
    'stylesheets',
    'Compile stylesheets',
    ['clean:stylesheets','stylus', 'postcss', 'cssmin']
  );

  /*
    Register build task
  */
  grunt.registerTask(
    'build',
    'Compile assets and copy files to /build',
    ['clean:build', 'copy', 'stylesheets', 'pug']
  );

  /*
    Register default task.
  */
  grunt.registerTask(
    'default',
    'Build, serve and watch. Woff.',
    ['build', 'connect', 'watch']
  );
};
<commit_msg>Updated gruntfile to allow only building/develop-server. Dev-mode starts watch/connect as well.<commit_after>module.exports = function(grunt) {

  // configure the tasks
  grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),
    /*
      Copy clean sources to /build
    */
    copy: {
      build: {
        cwd: 'src',
        src: ['!**/*.styl', '!**/*.pug'],
        dest: 'build',
        expand: true
      },
    },

    /*
      Remove leftover sources from /build
    */
    clean: {
      build: {
        src: ['build']
      },
      stylesheets: {
        src: ['build/**/*.css']
      },
    },

    /*
      Compile Stylus-files
    */
    stylus: {
      build: {
        options: {
          compress: false
        },
        files : {
          'build/<%= pkg.namespace %>.css': 'src/**/<%= pkg.namespace %>.styl'
        }
      }
    },

    /*
      Run PostCSS to handle autoprefixing etc.
    */
    postcss: {
      build: {
        files: {
          'build/<%= pkg.namespace %>.css': 'build/**/*.css'
        }
      }
    },

    /*
      Compile a minified version of base CSS-file
    */
    cssmin: {
      build: {
        files: {
          'build/<%= pkg.namespace %>.min.css': 'build/**/*.css'
        }
      }
    },

    /*
      Compile .pug to .html
    */
    pug: {
      compile: {
        options: {
          pretty: true,
          data: {name: '<%= pkg.name %>', namespace: '<%= pkg.namespace %>', version: '<%= pkg.version %>'}
        },
        files: [{
          expand: true,
          cwd: 'src/pug/',
          src: ['**/*.pug'],
          dest: 'build/demo/',
          ext: '.html'
        }]
      }
    },

    /*
      Watch for changes in stylesheets, pugs and copies
    */
    watch: {
      stylesheets: {
        files: 'src/**/*.styl',
        tasks: ['stylesheets'],
        options: {
          livereload: true,
        },
      },
      pug: {
        files: 'src/**/*.pug',
        tasks: ['pug'],
        options: {
          livereload: true,
        },
      },
      copy: {
        files: ['src/**', '!src/**/*.styl', '!src/**/*.pug'],
        tasks: ['copy']
      }
    },

    /*
      Set up local server
    */
    connect: {
      server: {
        options: {
          port: 4999,
          base: 'build',
          hostname: 'localhost'
        }
      }
    }

  });

  /*
    Load tasks
  */
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-stylus');
  grunt.loadNpmTasks('grunt-postcss');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-pug');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-connect');

  /*
    Register stylesheet task. Handles all Stylus/CSS tasks
  */
  grunt.registerTask(
    'stylesheets',
    'Compile stylesheets',
    ['clean:stylesheets','stylus', 'postcss', 'cssmin']
  );

  /*
    Register build task
  */
  grunt.registerTask(
    'build',
    'Compile assets and copy files to /build',
    ['clean:build', 'copy', 'stylesheets', 'pug']
  );

  /*
    Register default task.
  */
  var default_tasks = grunt.option('target') == 'develop' ? ['build', 'connect', 'watch'] : ['build'];

  grunt.registerTask(
    'default',
    'Build, serve and watch. Woff.',
    default_tasks
  );
};
<|endoftext|>


<commit_before>//Client-side Grunt Build File for TemplateX Project

var
	title					= "TemplateX",	//Project Title
	language			= "ru",					//Project Language
	dir						= "project",		//Project Directory
	images				= "images",			//Project Images Directory
	meta					= "meta",				//Meta Resources Directory
	res						= "res",				//Resources Directory

	resImages			= "images",			//Resource Images Directory
	css						= "css",				//CSS Production Directory
	cssDev				= "css.dev",		//CSS Development Directory
	cssFilename		= "styles",			//CSS Production Filename
	cssDevFiles		= [							//CSS Order
									"reset.css",
									"typography.css",
									"layout.css",
									"ui.css",
	],
	cssDevFilesIE = [							//CSS Order (IE)
									"reset-IE.css",
									"typography-IE.css",
									"layout-IE.css",
									"ui-IE.css",
	],
	js						= "js",					//JS Production Directory
	jsDev					= "js.dev",			//JS Development Directory
	jsFilename		= "scripts",		//JS Production Filename
	jsDevFiles		= [							//JS Order
									"utilites.js",
									"ui.js",
	],

	buildDir			= "build",			//Build Directory
	shareDir			= "build";			//Shared Build Directory

function fillAnArray(arr, path) {
	var resultArr = [];
	for (var i in arr) {
		resultArr.push(path + "/" + arr[i]);
	}
	return resultArr;
}

var project = {
	init: function() {
		this.title = title;
		this.language = language;
		this.dir = dir + "/";
		this.images = this.dir + images + "/";
		this.meta = meta;
		this.resDir = this.dir + res + "/";
		this.res = {
			images: {
				dir: this.resDir + resImages + "/"
			},
			css: {
				dir: this.resDir + css + "/",
				devDir: this.resDir + cssDev + "/",
				filename: cssFilename,
				dev: fillAnArray(cssDevFiles, dir + "/" + res + "/" + cssDev + "/"),
				devIE: fillAnArray(cssDevFilesIE, dir + "/" + res + "/" + cssDev + "/")
			},
			js: {
				dir: this.resDir + js + "/",
				devDir: this.resDir + jsDev + "/",
				filename: jsFilename,
				dev: fillAnArray(jsDevFiles, dir + "/" + res + "/" + jsDev + "/")
			}
		};
		this.build = {
			dir: buildDir + "/",
			shareDir: shareDir + "/"
		};
		return this;
	}
}.init();

module.exports = function(grunt) {

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

	grunt.initConfig({

		pkg: grunt.file.readJSON("package.json"),

		buildEnv: grunt.file.readJSON(process.env.buildJSON),

		htmlhint: {
			htmlHint: {
				options: {
					"tagname-lowercase": true,
					"attr-lowercase": true,
					"attr-value-double-quotes": true,
					"doctype-first": true,
					"tag-pair": true,
					"spec-char-escape": true,
					"id-unique": true,
					"src-not-empty": true,
					"id-class-value": true,
					"style-disabled": true,
					"img-alt-require": true
				},
				cwd: project.dir,
				src: ["*.html"],
				expand: true,
				flatten: true
			}
		},
		jshint: {
			jsHint: {
				options: {
					"evil": true,
					"regexdash": true,
					"browser": true,
					"wsh": true,
					"trailing": true,
					"sub": true
				},
				cwd: project.res.js.devDir,
				src: ["*.js"],
				expand: true,
				flatten: true
			}
		},
		csslint: {
			cssLint: {
				options: {
					"adjoining-classes": false,
					"box-model": false,
					"box-sizing": false,
					"compatible-vendor-prefixes": "warning",
					"display-property-grouping": true,
					"duplicate-background-images": false,
					"duplicate-properties": true,
					"empty-rules": true,
					"errors": true,
					"fallback-colors": false,
					"floats": "warning",
					"font-faces": "warning",
					"font-sizes": "warning",
					"gradients": "warning",
					"ids": "warning",
					"import": "warning",
					"important": "warning",
					"known-properties": true,
					"outline-none": "warning",
					"overqualified-elements": "warning",
					"qualified-headings": "warning",
					"regex-selectors": "warning",
					"rules-count": "warning",
					"shorthand": "warning",
					"star-property-hack": "warning",
					"text-indent": "warning",
					"underscore-property-hack": "warning",
					"unique-headings": "warning",
					"universal-selector": "warning",
					"vendor-prefix": true,
					"zero-units": false
				},
				cwd: project.res.css.devDir,
				src: ["*.css", "!reset*.css", "!typography*.css"],
				expand: true,
				flatten: true
			}
		},

		concat: {
			js: {
				options: {
					separator: "\n\n",
				},
				src: project.res.js.dev,
				dest: project.res.js.dir + project.res.js.filename + ".js",
			},
			css: {
				src: project.res.css.dev,
				dest: project.res.css.dir + project.res.css.filename + ".css"
			},
			cssIE: {
				checkIE: function() {
					var task = {};
					if (project.res.css.devIE.length !== 0) {
						task = {
							src: project.res.css.devIE,
							dest: project.res.css.dir + project.res.css.filename + "-IE.css"
						};
					}
					return task;
				}
			}.checkIE()
		},

		"string-replace": {
			sassDebug: {
				options: {
					replacements: [{
						pattern: /\/\*@ sourceMappingURL(.|\t|\s|\n)*?\*\/|.media \-sass\-debug\-info(.|\t|\s|\n)*?\}\}/gi,
						replacement: ""
					}]
				},
				files: {
					"./": [project.res.css.dir + "*.css"],
				}
			},
			build: {
				files: {
					"./": [project.build.dir + "*.html"],
				},
				options: {
					replacements: [{
						pattern: /@tx-title/gi,
						replacement: project.title
					},{
						pattern: /@tx-language/gi,
						replacement: project.language
					},{
						pattern: /.!-- @tx-css -->(.|\t|\s|\n)*?!-- \/@tx-css -->/gi,
						replacement: {
							checkIE: function() {
								var cssfiles;
								if (grunt.file.exists(project.res.css.dir + project.res.css.filename + "-IE.css")) {
									cssfiles = '<link rel="stylesheet" type="text/css" href="' + project.res.css.dir.replace(project.dir, "") + project.res.css.filename + '.min.css">\n\t\t<!--[if lte IE 7]> <link rel="stylesheet" type="text/css" href="' + project.res.css.dir.replace(project.dir, "") + project.res.css.filename + '-IE.min.css"> <![endif]-->';
								} else {
									cssfiles = '<link rel="stylesheet" type="text/css" href="' + project.res.css.dir.replace(project.dir, "") + project.res.css.filename + '.min.css">';
								}
								return cssfiles;
							}
						}.checkIE()
					},{
						pattern: /.!-- @tx-js -->(.|\t|\s|\n)*?!-- \/@tx-js -->/gi,
						replacement: '<script type="text/javascript" src="' + project.res.js.dir.replace(project.dir, "") + project.res.js.filename + '.min.js"></script>'
					}]
				}
			}
		},

		removelogging: {
			jsClean: {
				cwd: project.res.js.dir,
				src: ["*.js", "!*.min.js"],
				dest: project.res.js.dir,
				expand: true,
				flatten: true
			}
		},
		uglify: {
			jsMin: {
				cwd: project.res.js.dir,
				src: ["*.js", "!*.min.js"],
				dest: project.res.js.dir,
				ext: ".min.js",
				expand: true,
				flatten: true
			}
		},

		cssc: {
			options: {
					consolidateViaSelectors: true,
					consolidateMediaQueries: true
			},
			cssOptimize: {
				cwd: project.res.css.dir,
				src: ["*.css", "!*.min.css"],
				dest: project.res.css.dir,
				ext: ".min.css",
				expand: true,
				flatten: true
			}
		},
		uncss: {
			cssOptimize: {
				files: {
					cssMinFiles: function() {
						var cssMinFilesObject = {};
						cssMinFilesObject[project.res.css.dir + project.res.css.filename + ".min.css"] = project.dir + "*.html";
						return cssMinFilesObject;
					}
				}.cssMinFiles()
			}
		},
		cssmin: {
			cssMin: {
				cwd: project.res.css.dir,
				src: ["*.min.css"],
				dest: project.res.css.dir,
				expand: true,
				flatten: true
			}
		},

		csscomb: {
			options: {
				sortOrder: "cssorder.json"
			},
			cssSort: {
				cwd: project.res.css.dir,
				src: ["*.css", "!*.min.css"],
				dest: project.res.css.dir,
				expand: true,
				flatten: true
			}
		},

		clean: {
			build: [project.build.dir]
		},
		copy: {
			build: {
				cwd: project.dir,
				src: ["**", "!**/tx.*.*", "!**/txdebug.*.*", "!**/**.dev/**", "!**/txdebug/**"],
				dest: project.build.dir,
				expand: true
			},
			meta: {
				cwd: project.meta,
				src: ["*.ico", "*.png", "*.jpg", "*.gif"],
				dest: project.build.dir,
				expand: true,
				flatten: true
			},
			share: {
				cwd: project.build.dir,
				src: ["**"],
				dest: "<%= buildEnv.shareRoot %>" + project.build.shareDir,
				expand: true
			}
		},

		imagemin: {
			images: {
				cwd: project.images,
				src: ["**/*.{png,jpg,gif}", "!**/tx.*.*", "!**/txdebug.*.*"],
				dest: project.images,
				expand: true,
				flatten: true
			},
			res: {
				cwd: project.res.images.dir,
				src: ["**/*.{png,jpg,gif}", "!**/tx.*.*", "!**/txdebug.*.*"],
				dest: project.res.images.dir,
				expand: true,
				flatten: true
			},
			meta: {
				cwd: project.build.dir,
				src: ["*.{png,jpg,gif}"],
				dest: project.build.dir,
				expand: true,
				flatten: true
			}
		},
		compress: {
			gzip: {
				options: {
					mode: "gzip",
				},
				cwd: project.build.dir,
				src: ["**/*.min.js", "**/*.min.css",],
				dest: project.build.dir,
				expand: true
			}
		}

	});

	grunt.registerTask("lint", ["htmlhint", "jshint", "csslint"]);

	grunt.registerTask("images", ["imagemin:images", "imagemin:res"]);

	grunt.registerTask("build", ["htmlhint", "jshint", "csslint", "concat", "string-replace:sassDebug", "removelogging", "uglify", "cssc", "cssmin", "csscomb", "clean", "copy:build", "copy:meta", "imagemin:meta", "compress", "string-replace:build"]);

	grunt.registerTask("build-share", ["htmlhint", "jshint", "csslint", "concat", "string-replace:sassDebug", "removelogging", "uglify", "cssc", "cssmin", "csscomb", "clean", "copy:build", "copy:meta", "imagemin:meta", "compress", "string-replace:build", "copy:share"]);

	grunt.registerTask("build-exp", ["htmlhint", "jshint", "csslint", "concat", "string-replace:sassDebug", "removelogging", "uglify", "cssc", "uncss:cssOptimize", "cssmin", "csscomb", "clean", "copy:build", "copy:meta", "imagemin:meta", "compress", "string-replace:build"]);

};<commit_msg>Changes to the Build Tasks<commit_after>//Client-side Grunt Build File for TemplateX Project

var
	title					= "TemplateX",	//Project Title
	language			= "ru",					//Project Language
	dir						= "project",		//Project Directory
	images				= "images",			//Project Images Directory
	meta					= "meta",				//Meta Resources Directory
	res						= "res",				//Resources Directory

	resImages			= "images",			//Resource Images Directory
	css						= "css",				//CSS Production Directory
	cssDev				= "css.dev",		//CSS Development Directory
	cssFilename		= "styles",			//CSS Production Filename
	cssDevFiles		= [							//CSS Order
									"reset.css",
									"typography.css",
									"layout.css",
									"ui.css",
	],
	cssDevFilesIE = [							//CSS Order (IE)
									"reset-IE.css",
									"typography-IE.css",
									"layout-IE.css",
									"ui-IE.css",
	],
	js						= "js",					//JS Production Directory
	jsDev					= "js.dev",			//JS Development Directory
	jsFilename		= "scripts",		//JS Production Filename
	jsDevFiles		= [							//JS Order
									"utilites.js",
									"ui.js",
	],

	buildDir			= "build",			//Build Directory
	shareDir			= "build";			//Shared Build Directory

function fillAnArray(arr, path) {
	var resultArr = [];
	for (var i in arr) {
		resultArr.push(path + "/" + arr[i]);
	}
	return resultArr;
}

var project = {
	init: function() {
		this.title = title;
		this.language = language;
		this.dir = dir + "/";
		this.images = this.dir + images + "/";
		this.meta = meta;
		this.resDir = this.dir + res + "/";
		this.res = {
			images: {
				dir: this.resDir + resImages + "/"
			},
			css: {
				dir: this.resDir + css + "/",
				devDir: this.resDir + cssDev + "/",
				filename: cssFilename,
				dev: fillAnArray(cssDevFiles, dir + "/" + res + "/" + cssDev + "/"),
				devIE: fillAnArray(cssDevFilesIE, dir + "/" + res + "/" + cssDev + "/")
			},
			js: {
				dir: this.resDir + js + "/",
				devDir: this.resDir + jsDev + "/",
				filename: jsFilename,
				dev: fillAnArray(jsDevFiles, dir + "/" + res + "/" + jsDev + "/")
			}
		};
		this.build = {
			dir: buildDir + "/",
			shareDir: shareDir + "/"
		};
		return this;
	}
}.init();

module.exports = function(grunt) {

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

	grunt.initConfig({

		pkg: grunt.file.readJSON("package.json"),

		buildEnv: grunt.file.readJSON(process.env.buildJSON),

		htmlhint: {
			htmlHint: {
				options: {
					"tagname-lowercase": true,
					"attr-lowercase": true,
					"attr-value-double-quotes": true,
					"doctype-first": true,
					"tag-pair": true,
					"spec-char-escape": true,
					"id-unique": true,
					"src-not-empty": true,
					"id-class-value": true,
					"style-disabled": true,
					"img-alt-require": true
				},
				cwd: project.dir,
				src: ["*.html"],
				expand: true,
				flatten: true
			}
		},
		jshint: {
			jsHint: {
				options: {
					"evil": true,
					"regexdash": true,
					"browser": true,
					"wsh": true,
					"trailing": true,
					"sub": true
				},
				cwd: project.res.js.devDir,
				src: ["*.js"],
				expand: true,
				flatten: true
			}
		},
		csslint: {
			cssLint: {
				options: {
					"adjoining-classes": false,
					"box-model": false,
					"box-sizing": false,
					"compatible-vendor-prefixes": "warning",
					"display-property-grouping": true,
					"duplicate-background-images": false,
					"duplicate-properties": true,
					"empty-rules": true,
					"errors": true,
					"fallback-colors": false,
					"floats": "warning",
					"font-faces": "warning",
					"font-sizes": "warning",
					"gradients": "warning",
					"ids": "warning",
					"import": "warning",
					"important": "warning",
					"known-properties": true,
					"outline-none": "warning",
					"overqualified-elements": "warning",
					"qualified-headings": "warning",
					"regex-selectors": "warning",
					"rules-count": "warning",
					"shorthand": "warning",
					"star-property-hack": "warning",
					"text-indent": "warning",
					"underscore-property-hack": "warning",
					"unique-headings": "warning",
					"universal-selector": "warning",
					"vendor-prefix": true,
					"zero-units": false
				},
				cwd: project.res.css.devDir,
				src: ["*.css", "!reset.css", "!typography.css", "!*-IE.css"],
				expand: true,
				flatten: true
			}
		},

		concat: {
			js: {
				options: {
					separator: "\n\n",
				},
				src: project.res.js.dev,
				dest: project.res.js.dir + project.res.js.filename + ".js",
			},
			css: {
				src: project.res.css.dev,
				dest: project.res.css.dir + project.res.css.filename + ".css"
			},
			cssIE: {
				checkIE: function() {
					var task = {};
					if (project.res.css.devIE.length !== 0) {
						task = {
							src: project.res.css.devIE,
							dest: project.res.css.dir + project.res.css.filename + "-IE.css"
						};
					}
					return task;
				}
			}.checkIE()
		},

		"string-replace": {
			sassDebug: {
				options: {
					replacements: [{
						pattern: /\/\*@ sourceMappingURL(.|\t|\s|\n)*?\*\/|.media \-sass\-debug\-info(.|\t|\s|\n)*?\}\}/gi,
						replacement: ""
					}]
				},
				files: {
					"./": [project.res.css.dir + "*.css"],
				}
			},
			build: {
				files: {
					"./": [project.build.dir + "*.html"],
				},
				options: {
					replacements: [{
						pattern: /@tx-title/gi,
						replacement: project.title
					},{
						pattern: /@tx-language/gi,
						replacement: project.language
					},{
						pattern: /.!-- @tx-css -->(.|\t|\s|\n)*?!-- \/@tx-css -->/gi,
						replacement: {
							checkIE: function() {
								var cssfiles;
								if (grunt.file.exists(project.res.css.dir + project.res.css.filename + "-IE.css")) {
									cssfiles = '<link rel="stylesheet" type="text/css" href="' + project.res.css.dir.replace(project.dir, "") + project.res.css.filename + '.min.css">\n\t\t<!--[if lte IE 7]> <link rel="stylesheet" type="text/css" href="' + project.res.css.dir.replace(project.dir, "") + project.res.css.filename + '-IE.min.css"> <![endif]-->';
								} else {
									cssfiles = '<link rel="stylesheet" type="text/css" href="' + project.res.css.dir.replace(project.dir, "") + project.res.css.filename + '.min.css">';
								}
								return cssfiles;
							}
						}.checkIE()
					},{
						pattern: /.!-- @tx-js -->(.|\t|\s|\n)*?!-- \/@tx-js -->/gi,
						replacement: '<script type="text/javascript" src="' + project.res.js.dir.replace(project.dir, "") + project.res.js.filename + '.min.js"></script>'
					}]
				}
			}
		},

		removelogging: {
			jsClean: {
				cwd: project.res.js.dir,
				src: ["*.js", "!*.min.js"],
				dest: project.res.js.dir,
				expand: true,
				flatten: true
			}
		},
		uglify: {
			jsMin: {
				cwd: project.res.js.dir,
				src: ["*.js", "!*.min.js"],
				dest: project.res.js.dir,
				ext: ".min.js",
				expand: true,
				flatten: true
			}
		},

		cssc: {
			options: {
					consolidateViaSelectors: true,
					consolidateMediaQueries: true
			},
			cssOptimize: {
				cwd: project.res.css.dir,
				src: ["*.css", "!*.min.css"],
				dest: project.res.css.dir,
				ext: ".min.css",
				expand: true,
				flatten: true
			}
		},
		uncss: {
			cssOptimize: {
				files: {
					cssMinFiles: function() {
						var cssMinFilesObject = {};
						cssMinFilesObject[project.res.css.dir + project.res.css.filename + ".min.css"] = project.dir + "*.html";
						return cssMinFilesObject;
					}
				}.cssMinFiles()
			}
		},
		cssmin: {
			cssMin: {
				cwd: project.res.css.dir,
				src: ["*.min.css"],
				dest: project.res.css.dir,
				expand: true,
				flatten: true
			}
		},

		csscomb: {
			options: {
				sortOrder: "cssorder.json"
			},
			cssSort: {
				cwd: project.res.css.dir,
				src: ["*.css", "!*.min.css"],
				dest: project.res.css.dir,
				expand: true,
				flatten: true
			}
		},

		clean: {
			build: [project.build.dir]
		},
		copy: {
			build: {
				cwd: project.dir,
				src: ["**", "!**/tx.*.*", "!**/txdebug.*.*", "!**/**.dev/**", "!**/txdebug/**"],
				dest: project.build.dir,
				expand: true
			},
			meta: {
				cwd: project.meta,
				src: ["*.ico", "*.png", "*.jpg", "*.gif"],
				dest: project.build.dir,
				expand: true,
				flatten: true
			},
			share: {
				cwd: project.build.dir,
				src: ["**"],
				dest: "<%= buildEnv.shareRoot %>" + project.build.shareDir,
				expand: true
			}
		},

		imagemin: {
			images: {
				cwd: project.images,
				src: ["**/*.{png,jpg,gif}", "!**/tx.*.*", "!**/txdebug.*.*"],
				dest: project.images,
				expand: true,
				flatten: true
			},
			res: {
				cwd: project.res.images.dir,
				src: ["**/*.{png,jpg,gif}", "!**/tx.*.*", "!**/txdebug.*.*"],
				dest: project.res.images.dir,
				expand: true,
				flatten: true
			},
			meta: {
				cwd: project.build.dir,
				src: ["*.{png,jpg,gif}"],
				dest: project.build.dir,
				expand: true,
				flatten: true
			}
		},
		compress: {
			gzip: {
				options: {
					mode: "gzip",
				},
				cwd: project.build.dir,
				src: ["**/*.min.js", "**/*.min.css",],
				dest: project.build.dir,
				expand: true
			}
		}

	});

	grunt.registerTask("lint", ["htmlhint", "jshint", "csslint"]);

	grunt.registerTask("images", ["imagemin:images", "imagemin:res"]);

	grunt.registerTask("build", ["htmlhint", "jshint", "concat", "string-replace:sassDebug", "removelogging", "uglify", "cssc", "cssmin", "csscomb", "clean", "copy:build", "copy:meta", "imagemin:meta", "compress", "string-replace:build"]);

	grunt.registerTask("build-share", ["htmlhint", "jshint", "concat", "string-replace:sassDebug", "removelogging", "uglify", "cssc", "cssmin", "csscomb", "clean", "copy:build", "copy:meta", "imagemin:meta", "compress", "string-replace:build", "copy:share"]);

	grunt.registerTask("build-exp", ["htmlhint", "jshint", "concat", "string-replace:sassDebug", "removelogging", "uglify", "cssc", "uncss:cssOptimize", "cssmin", "csscomb", "clean", "copy:build", "copy:meta", "imagemin:meta", "compress", "string-replace:build"]);

};<|endoftext|>


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

  var fs = require('fs');
  require('es6-shim');
  var bower = require('bower');
  var path = require('path');

  var pkgFile = require('./package.json');
  var lyriaConfig = pkgFile.lyriaProject || {};

  var buildPrefix = 'builds';
  var buildVersion = pkgFile.version + '-' + grunt.template.today("yymmdd-HHMMss");
  var buildId = pkgFile.name + '-v' + buildVersion;
  buildId = grunt.option('build') || buildId;

  var buildFolder = [buildPrefix, buildId].join('/');

  var libFiles = (fs.existsSync('./lib')) ? fs.readdirSync('./lib') : [];
  var styleFiles = (fs.existsSync('./css')) ? fs.readdirSync('./css') : [];

  var libFilesPriorities = ['almond', 'handlebars', 'fastclick', 'udefine'];

  var templateScripts = {
    development: [],
    production: []
  };
  var templateStyles = {
    development: [],
    production: []
  };

  var uglifyLibObject = {};
  var bowerStyleObject = {};

  for (var i = 0, j = libFiles.length; i < j; i++) {
    (function(iterator) {
      uglifyLibObject[path.join(buildFolder, 'lib', iterator)] = path.join('./lib', iterator);
      if (libFilesPriorities.indexOf(iterator) >= 0) {
        templateScripts.unshift('lib/' + iterator);
      } else {
        templateScripts.push('lib/' + iterator);
      }
    })(libFiles[i]);
  }

  uglifyLibObject[buildFolder + '/js/<%= pkg.name %>.js'] = '<%= concat_sourcemap.dist.dest %>';
  //templateScripts.push('js/<%= pkg.name %>.js');

  for (var k = 0, l = styleFiles.length; k < l; k++) {
    (function(iterator) {
      templateStyles.development.push('css/' + iterator);
      templateStyles.production.push('css/' + iterator);
    })(styleFiles[k]);
  }

  grunt.initConfig({
    pkg: pkgFile,
    lyriaConfig: lyriaConfig,
    buildVersion: buildVersion,
    buildFolder: buildFolder,
    concat_sourcemap: {
      options: {
        sourcesContent: true,
        sourceRoot: '/'
      },
      dist: {
        src: ['src/**/*.js'],
        dest: 'js/<%= pkg.name %>.js'
      }
    },
    copy: {
      assets: {
        files: [{
          expand: true,
          src: ['assets/**'],
          dest: '<%= buildFolder %>/',
          filter: function(filepath) {
            if ((filepath.indexOf(path.sep + 'scenes') >= 0) || (filepath.indexOf(path.sep + 'prefabs') >= 0)) {
              return false;
            } else {
              return true;
            }
          }
        }]
      },
      root: {
        files: [{
          expand: true,
          src: ['css/**/*', 'favicon.ico', '*.png'],
          dest: '<%= buildFolder %>/'
        }]
      },
      styles: {
        files: [{
          expand: true,
          src: ['css/**/*'],
          dest: '<%= buildFolder %>/'
        }]
      },
      bowerStyles: {
        files: bowerStyleObject
      }
    },
    template: {
      development: {
        src: 'template.html',
        dest: 'index.html',
        engine: 'handlebars',
        variables: {
          livereload: true,
          scripts: templateScripts.development,
          styles: templateStyles.development,
          mainModule: pkgFile.name,
          title: '<%= lyriaConfig.title %> (Development build <%= buildVersion %>)',
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      },
      production: {
        src: 'template.html',
        dest: '<%= buildFolder %>/index.html',
        engine: 'handlebars',
        variables: {
          livereload: false,
          scripts: templateScripts.production,
          styles: templateStyles.production,
          mainModule: pkgFile.name,
          title: lyriaConfig.title,
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      }
    },
    uglify: {
      production: {
        files: uglifyLibObject
      }
    },
    compress: {
      all: {
        options: {
          archive: '<%= buildFolder %>.zip'
        },
        files: [{
          cwd: '<%= buildFolder %>/',
          src: ['**'],
          dest: '<%= pkg.name %>/'
        }]
      }
    },
    stylus: {
      options: {
        paths: ['stylus', 'stylus/lyria'],
        urlfunc: 'embedurl',
        import: ['nib', 'asset'],
      },
      development: {
        options: {
          compress: false,
          linenos: true
        },
        files: {
          'css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      },
      production: {
        options: {
          compress: true
        },
        files: {
          '<%= buildFolder %>/css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      }
    },
    csslint: {
      lint: {
        src: ['css/mygame.css']
      }
    },
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      assets: {
        src: ['assets/**/*.js']
      },
      source: {
        src: ['src/**/*.js', '!src/generated/**/*.js']
      }
    },
    connect: {
      built: {
        options: {
          keepalive: true,
          base: '<%= buildFolder %>/',
          port: 9000
        }
      }
    },
    watch: {
      options: {
        // Start a live reload server on the default port 35729
        livereload: true,
      },
      stylus: {
        files: 'stylus/**/*.styl',
        tasks: ['stylus:development']
      },
      assetList: {
        files: 'assets/**/*',
        tasks: ['lyriaAssetList']
      },
      scenes: {
        files: 'assets/scenes/*',
        tasks: ['lyriaScene']
      },
      i18nData: {
        files: 'assets/i18n/**/*.json',
        tasks: ['lyriaData']
      },
      template: {
        files: 'template.html',
        tasks: ['bower']
      },
      concat: {
        files: 'src/**/*.js',
        tasks: ['concat_sourcemap']
      }
    },
    lyriaData: {
      options: {
        namespace: '<%= pkg.name %>'
      },
      all: {
        options: {
          name: 'i18n'
        },
        dest: 'src/generated/i18n.js',
        src: ['assets/i18n/**/*.json']
      }
    },
    lyriaAssetList: {
      options: {
        namespace: '<%= pkg.name %>'
      },
      all: {
        dest: 'src/generated/assetlist.js',
        src: ['assets/**/*', '!**/README.md'],
        filter: 'isFile'
      }
    },
    lyriaScene: {
      options: {
        namespace: '<%= pkg.name %>'
      },
      scenes: {
        files: [{
          dest: 'src/generated/scenelist.js',
          src: ['assets/scenes/*'],
          filter: 'isDirectory'
        }]
      },
      prefabs: {
        options: {
          name: 'prefablist',
          entryFile: 'prefab.js',
          markupFile: 'prefab.html'
        },
        files: [{
          dest: 'src/generated/prefablist.js',
          src: ['assets/prefabs/*'],
          filter: 'isDirectory'
        }]
      }
    }
  });

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  var bowerList = function(done) {
    bower.commands.list({
      paths: true
    }).on('end', function(results) {
      var prepareBowerAsset = function(value) {
        value = path.relative(process.cwd(), value);

        // All forward slashes, please
        value = value.split('\\').join('/');

        if (!value.endsWith('.css')) {

          if (!value.endsWith('.js')) {
            value += '/' + key + '.js';
          }

          var libFile = ['lib', path.basename(value)].join('/');
          var buildLibFile = [buildFolder, libFile].join('/');
          uglifyLibObject[buildLibFile] = value;

          if (libFilesPriorities.indexOf(key) >= 0) {
            templateScripts.development.unshift(value);
            templateScripts.production.unshift(libFile);
          } else {
            templateScripts.development.push(value);
            templateScripts.production.push(libFile);
          }

        } else {
          var styleFile = ['css', path.basename(value)].join('/');
          bowerStyleObject[[buildFolder, styleFile].join('/')] = value;

          templateStyles.development.unshift(value);
          templateStyles.production.unshift(styleFile);
        }
      };

      for (var key in results) {
        var val = results[key];

        if (val.indexOf(',') >= 0) {
          val = val.split(',');
        }

        if (Array.isArray(val)) {
          // TODO: Handlebars doesn't need special treatment right now, but will once we use the AMD version
          //if (key === 'handlebars') {
          //  prepareBowerAsset(val[1]);
          //} else {
            for (var i = 0, j = val.length; i < j; i++) {
              if (((path.extname(val[i]) === '.js') && !val[i].endsWith('.min.js')) || path.extname(val[i]) === '.css') {
                prepareBowerAsset(val[i]);
              }
            }
          //}

        } else {
          prepareBowerAsset(val);
        }
      }

      templateScripts.development.push('js/<%= pkg.name %>.js');
      templateScripts.production.push('js/<%= pkg.name %>.js');

      done();
    });
  };

  grunt.registerTask('bower:development', 'Prepares scripts using bower components', function() {
    var done = this.async();

    bowerList(function() {
      grunt.task.run('template:development');
      done();
    });
  });

  grunt.registerTask('bower:production', 'Prepares scripts using bower components', function() {
    var done = this.async();

    bowerList(function() {
      grunt.task.run('template:production');
      done();
    });
  });

  grunt.registerTask('prebuild', 'Task before building the project', ['lyriaScene', 'lyriaAssetList', 'lyriaData', 'concat_sourcemap']);
  grunt.registerTask('test', 'Lints JavaScript and CSS files', ['jshint']);

  grunt.registerTask('development', 'Development build', ['test', 'prebuild', 'bower:development', 'stylus:development']);
  grunt.registerTask('production', 'Production build', ['test', 'prebuild', 'bower:production', 'uglify', 'copy', 'stylus:production']);
  grunt.registerTask('pack', 'Packs project', ['production', 'compress']);
  grunt.registerTask('deploy', 'Builds project in production mode and starts a local server', ['production', 'connect']);

  grunt.registerTask('build', 'Builds the default project', ['development']);
  grunt.registerTask('default', 'Default task', ['development']);

  // The future in order
  grunt.registerTask('observe', 'Default task', ['development', 'watch']);

};
<commit_msg>Added gruntfile to jshint linting<commit_after>module.exports = function(grunt) {

  var fs = require('fs');
  require('es6-shim');
  var bower = require('bower');
  var path = require('path');

  var pkgFile = require('./package.json');
  var lyriaConfig = pkgFile.lyriaProject || {};

  var buildPrefix = 'builds';
  var buildVersion = pkgFile.version + '-' + grunt.template.today("yymmdd-HHMMss");
  var buildId = pkgFile.name + '-v' + buildVersion;
  buildId = grunt.option('build') || buildId;

  var buildFolder = [buildPrefix, buildId].join('/');

  var libFiles = (fs.existsSync('./lib')) ? fs.readdirSync('./lib') : [];
  var styleFiles = (fs.existsSync('./css')) ? fs.readdirSync('./css') : [];

  var libFilesPriorities = ['almond', 'handlebars', 'fastclick', 'udefine'];

  var templateScripts = {
    development: [],
    production: []
  };
  var templateStyles = {
    development: [],
    production: []
  };

  var uglifyLibObject = {};
  var bowerStyleObject = {};

  for (var i = 0, j = libFiles.length; i < j; i++) {
    (function(iterator) {
      uglifyLibObject[path.join(buildFolder, 'lib', iterator)] = path.join('./lib', iterator);
      if (libFilesPriorities.indexOf(iterator) >= 0) {
        templateScripts.unshift('lib/' + iterator);
      } else {
        templateScripts.push('lib/' + iterator);
      }
    })(libFiles[i]);
  }

  uglifyLibObject[buildFolder + '/js/<%= pkg.name %>.js'] = '<%= concat_sourcemap.dist.dest %>';
  //templateScripts.push('js/<%= pkg.name %>.js');

  for (var k = 0, l = styleFiles.length; k < l; k++) {
    (function(iterator) {
      templateStyles.development.push('css/' + iterator);
      templateStyles.production.push('css/' + iterator);
    })(styleFiles[k]);
  }

  grunt.initConfig({
    pkg: pkgFile,
    lyriaConfig: lyriaConfig,
    buildVersion: buildVersion,
    buildFolder: buildFolder,
    concat_sourcemap: {
      options: {
        sourcesContent: true,
        sourceRoot: '/'
      },
      dist: {
        src: ['src/**/*.js'],
        dest: 'js/<%= pkg.name %>.js'
      }
    },
    copy: {
      assets: {
        files: [{
          expand: true,
          src: ['assets/**'],
          dest: '<%= buildFolder %>/',
          filter: function(filepath) {
            if ((filepath.indexOf(path.sep + 'scenes') >= 0) || (filepath.indexOf(path.sep + 'prefabs') >= 0)) {
              return false;
            } else {
              return true;
            }
          }
        }]
      },
      root: {
        files: [{
          expand: true,
          src: ['css/**/*', 'favicon.ico', '*.png'],
          dest: '<%= buildFolder %>/'
        }]
      },
      styles: {
        files: [{
          expand: true,
          src: ['css/**/*'],
          dest: '<%= buildFolder %>/'
        }]
      },
      bowerStyles: {
        files: bowerStyleObject
      }
    },
    template: {
      development: {
        src: 'template.html',
        dest: 'index.html',
        engine: 'handlebars',
        variables: {
          livereload: true,
          scripts: templateScripts.development,
          styles: templateStyles.development,
          mainModule: pkgFile.name,
          title: '<%= lyriaConfig.title %> (Development build <%= buildVersion %>)',
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      },
      production: {
        src: 'template.html',
        dest: '<%= buildFolder %>/index.html',
        engine: 'handlebars',
        variables: {
          livereload: false,
          scripts: templateScripts.production,
          styles: templateStyles.production,
          mainModule: pkgFile.name,
          title: lyriaConfig.title,
          description: lyriaConfig.description,
          author: lyriaConfig.author
        }
      }
    },
    uglify: {
      production: {
        files: uglifyLibObject
      }
    },
    compress: {
      all: {
        options: {
          archive: '<%= buildFolder %>.zip'
        },
        files: [{
          cwd: '<%= buildFolder %>/',
          src: ['**'],
          dest: '<%= pkg.name %>/'
        }]
      }
    },
    stylus: {
      options: {
        paths: ['stylus', 'stylus/lyria'],
        urlfunc: 'embedurl',
        import: ['nib', 'asset'],
      },
      development: {
        options: {
          compress: false,
          linenos: true
        },
        files: {
          'css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      },
      production: {
        options: {
          compress: true
        },
        files: {
          '<%= buildFolder %>/css/<%= pkg.name %>.css': 'stylus/**/*.styl'
        }
      }
    },
    csslint: {
      lint: {
        src: ['css/mygame.css']
      }
    },
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      assets: {
        src: ['assets/**/*.js']
      },
      source: {
        src: ['src/**/*.js', '!src/generated/**/*.js']
      },
      gruntfile: {
        src: ['grunfile.js']
      }
    },
    connect: {
      built: {
        options: {
          keepalive: true,
          base: '<%= buildFolder %>/',
          port: 9000
        }
      }
    },
    watch: {
      options: {
        // Start a live reload server on the default port 35729
        livereload: true,
      },
      stylus: {
        files: 'stylus/**/*.styl',
        tasks: ['stylus:development']
      },
      assetList: {
        files: 'assets/**/*',
        tasks: ['lyriaAssetList']
      },
      scenes: {
        files: 'assets/scenes/*',
        tasks: ['lyriaScene']
      },
      i18nData: {
        files: 'assets/i18n/**/*.json',
        tasks: ['lyriaData']
      },
      template: {
        files: 'template.html',
        tasks: ['bower']
      },
      concat: {
        files: 'src/**/*.js',
        tasks: ['concat_sourcemap']
      }
    },
    lyriaData: {
      options: {
        namespace: '<%= pkg.name %>'
      },
      all: {
        options: {
          name: 'i18n'
        },
        dest: 'src/generated/i18n.js',
        src: ['assets/i18n/**/*.json']
      }
    },
    lyriaAssetList: {
      options: {
        namespace: '<%= pkg.name %>'
      },
      all: {
        dest: 'src/generated/assetlist.js',
        src: ['assets/**/*', '!**/README.md'],
        filter: 'isFile'
      }
    },
    lyriaScene: {
      options: {
        namespace: '<%= pkg.name %>'
      },
      scenes: {
        files: [{
          dest: 'src/generated/scenelist.js',
          src: ['assets/scenes/*'],
          filter: 'isDirectory'
        }]
      },
      prefabs: {
        options: {
          name: 'prefablist',
          entryFile: 'prefab.js',
          markupFile: 'prefab.html'
        },
        files: [{
          dest: 'src/generated/prefablist.js',
          src: ['assets/prefabs/*'],
          filter: 'isDirectory'
        }]
      }
    }
  });

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  var bowerList = function(done) {
    bower.commands.list({
      paths: true
    }).on('end', function(results) {
      var prepareBowerAsset = function(value) {
        value = path.relative(process.cwd(), value);

        // All forward slashes, please
        value = value.split('\\').join('/');

        if (!value.endsWith('.css')) {

          if (!value.endsWith('.js')) {
            value += '/' + key + '.js';
          }

          var libFile = ['lib', path.basename(value)].join('/');
          var buildLibFile = [buildFolder, libFile].join('/');
          uglifyLibObject[buildLibFile] = value;

          if (libFilesPriorities.indexOf(key) >= 0) {
            templateScripts.development.unshift(value);
            templateScripts.production.unshift(libFile);
          } else {
            templateScripts.development.push(value);
            templateScripts.production.push(libFile);
          }

        } else {
          var styleFile = ['css', path.basename(value)].join('/');
          bowerStyleObject[[buildFolder, styleFile].join('/')] = value;

          templateStyles.development.unshift(value);
          templateStyles.production.unshift(styleFile);
        }
      };

      for (var key in results) {
        var val = results[key];

        if (val.indexOf(',') >= 0) {
          val = val.split(',');
        }

        if (Array.isArray(val)) {
          // TODO: Handlebars doesn't need special treatment right now, but will once we use the AMD version
          //if (key === 'handlebars') {
          //  prepareBowerAsset(val[1]);
          //} else {
            for (var i = 0, j = val.length; i < j; i++) {
              if (((path.extname(val[i]) === '.js') && !val[i].endsWith('.min.js')) || path.extname(val[i]) === '.css') {
                prepareBowerAsset(val[i]);
              }
            }
          //}

        } else {
          prepareBowerAsset(val);
        }
      }

      templateScripts.development.push('js/<%= pkg.name %>.js');
      templateScripts.production.push('js/<%= pkg.name %>.js');

      done();
    });
  };

  grunt.registerTask('bower:development', 'Prepares scripts using bower components', function() {
    var done = this.async();

    bowerList(function() {
      grunt.task.run('template:development');
      done();
    });
  });

  grunt.registerTask('bower:production', 'Prepares scripts using bower components', function() {
    var done = this.async();

    bowerList(function() {
      grunt.task.run('template:production');
      done();
    });
  });

  grunt.registerTask('prebuild', 'Task before building the project', ['lyriaScene', 'lyriaAssetList', 'lyriaData', 'concat_sourcemap']);
  grunt.registerTask('test', 'Lints JavaScript and CSS files', ['jshint']);

  grunt.registerTask('development', 'Development build', ['test', 'prebuild', 'bower:development', 'stylus:development']);
  grunt.registerTask('production', 'Production build', ['test', 'prebuild', 'bower:production', 'uglify', 'copy', 'stylus:production']);
  grunt.registerTask('pack', 'Packs project', ['production', 'compress']);
  grunt.registerTask('deploy', 'Builds project in production mode and starts a local server', ['production', 'connect']);

  grunt.registerTask('build', 'Builds the default project', ['development']);
  grunt.registerTask('default', 'Default task', ['development']);

  // The future in order
  grunt.registerTask('observe', 'Default task', ['development', 'watch']);

};
<|endoftext|>


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

module.exports = function (grunt) {

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

    // Build the list of valid source and test files based on sources.json
    var sources = grunt.file.readJSON("src/sources.json"),
        srcFiles = ["src/boot.js"],
        testFiles = [];
    sources.forEach(function (source) {
        var name = source.name;
        if (source.load !== false) {
            srcFiles.push("src/" + name + ".js");
            if (source.test !== false) {
                testFiles.push("test/" + name + ".js");
            }
        }
    });

    // Since the tasks are split using load-grunt-config, I need a global object containing the configuration
    global.configuration = {
        pkg: grunt.file.readJSON("./package.json"),
        selenium: (function () {
            try {
                return grunt.file.readJSON("./tmp/selenium.json");
            } catch (e) {
                console.warn("Tested selenium driver list is missing, use node detectSelenium");
            }
            return [];
        }()),
        srcFiles: srcFiles,
        testFiles: testFiles,
        jsLintedFiles: [
            "Gruntfile.js",
            "grunt/**/*.js",
            "statistics.js",
            ".eslintrules/*.js",
            "make/*.js",
            "test/host/**/*.js",
            "res/*.js"
        ]
            .concat(srcFiles)
            .concat(testFiles)
    };

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

};
<commit_msg>Documentation sources are flagged<commit_after>"use strict";
/*jshint node: true*/
/*eslint-env node*/

module.exports = function (grunt) {

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

    // Build the list of valid source and test files based on sources.json
    var sources = grunt.file.readJSON("src/sources.json"),
        srcFiles = ["src/boot.js"],
        docFiles = [],
        testFiles = [];
    sources.forEach(function (source) {
        var name = source.name;
        if (source.load !== false) {
            srcFiles.push("src/" + name + ".js");
            if (source.test !== false) {
                testFiles.push("test/" + name + ".js");
            }
            if (source.doc === true) {
                docFiles.push("src/" + name + ".js");
            }
        }
    });

    // Since the tasks are split using load-grunt-config, I need a global object containing the configuration
    global.configuration = {
        pkg: grunt.file.readJSON("./package.json"),
        selenium: (function () {
            try {
                return grunt.file.readJSON("./tmp/selenium.json");
            } catch (e) {
                console.warn("Tested selenium driver list is missing, use node detectSelenium");
            }
            return [];
        }()),
        srcFiles: srcFiles,
        testFiles: testFiles,
        docFiles: docFiles,
        jsLintedFiles: [
            "Gruntfile.js",
            "grunt/**/*.js",
            "statistics.js",
            ".eslintrules/*.js",
            "make/*.js",
            "test/host/**/*.js",
            "res/*.js"
        ]
            .concat(srcFiles)
            .concat(testFiles)
    };

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

};
<|endoftext|>


<commit_before>module.exports = function(grunt) {
    // Do grunt-related things in here.
    grunt.initConfig({
        // Project configuration
        pkg: grunt.file.readJSON('package.json'),

        jshint: {
            files: ['gruntfile.js'],
        },

        concat: {
            css: {
                src: ['node_modules/normalize.css/normalize.css', 'src/css/style.css'],
                dest: 'dist/css/style.css'
            }
        },

        cssmin: {
            target: {
                files: [{
                    expand: true,
                    cwd: 'dist/css',
                    src: '*.css',
                    dest: 'dist/css',
                    ext: '.min.css'
                }]
            }
        },

        processhtml: {
            dist: {
                files: {
                    'dist/index.html': ['src/index.html']
                }
            }
        },

        copy: {
            main: {
                expand: true,
                cwd: 'src/img/',
                src: '*',
                dest: 'dist/img/',
            }
        }
    });

    // Load the plugins that provides the tasks:
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-processhtml');
    grunt.loadNpmTasks('grunt-contrib-copy');

    // Default tasks:
    grunt.registerTask('default', ['jshint', 'concat', 'cssmin', 'processhtml', 'copy']);

};<commit_msg>chore: Add 'watch' task to 'gruntfile.js'<commit_after>module.exports = function(grunt) {
    // Do grunt-related things in here.
    grunt.initConfig({
        // Project configuration
        pkg: grunt.file.readJSON('package.json'),

        jshint: {
            files: ['gruntfile.js'],
        },

        concat: {
            css: {
                src: ['node_modules/normalize.css/normalize.css', 'src/css/style.css'],
                dest: 'dist/css/style.css'
            }
        },

        cssmin: {
            target: {
                files: [{
                    expand: true,
                    cwd: 'dist/css',
                    src: '*.css',
                    dest: 'dist/css',
                    ext: '.min.css'
                }]
            }
        },

        processhtml: {
            dist: {
                files: {
                    'dist/index.html': ['src/index.html']
                }
            }
        },

        copy: {
            main: {
                expand: true,
                cwd: 'src/img/',
                src: '*',
                dest: 'dist/img/',
            }
        },

        watch: {
            html: {
                files: ['src/index.html'],
                tasks: ['processhtml']
            },
            css: {
                files: ['app/css/*.*'],
                tasks: ['concat', 'cssmin']
            },
            gruntfile: {
                files: ['gruntfile.js'],
                tasks: ['jshint']
            },
            img: {
                files: ['src/img/*'],
                tasks: ['copy']
            },

        }
    });

    // Load the plugins that provides the tasks:
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-processhtml');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');

    // Default tasks:
    grunt.registerTask('default', ['jshint', 'concat', 'cssmin', 'processhtml', 'copy']);

};<|endoftext|>


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

    grunt.initConfig({
      uglify: {
          options: {
              mangle: false,
              sourceMap: 'public/build/js/main.min.js.map'
          },
          target: {
              files: {
                  'public/build/js/main.js': ['public/js/*.js']
              }
          }
      },
      copy: {
        image: {
          files: [
            {
              expand: true,
              cwd: 'public/img',
              src: '**.*{png,jpg,svg}',
              dest: 'public/build/img/'
            }
          ]
        }
      },
      sass: {
          main: {
              options: {
                  compass: true
              },
              files: {
                  'public/build/css/style.css': 'public/css/style.sass'
              }
          }
      },
      watch: {
          options: {
              livereload: true,
          },
          sass: {
              files: ['public/css/**/*.sass'],
              tasks: ['sass'],
              options: {
                  //
              }
          },
          js: {
              files: ['public/js/*.js'],
              tasks: ['uglify'],
              options: {
                  //
              }
          }
      },
      clean: {
        build: ['public/build']
      },
      bower: {
        install: {
          options: {
            copy: false,
            verbose: true
          }
        }
      },
      forever: {
        server: {
          options: {
            index: 'app.js',
            logDir: 'logs'
          }
        }
      }
    });

    grunt.registerTask('start', 'run server', function() {

      var nodemon = grunt.util.spawn({
        cmd: 'nodemon',
        args: ['app.js']
      });

      nodemon.stdout.pipe(process.stdout);
      nodemon.stderr.pipe(process.stderr);

      var done = this.async();

      setTimeout(function() {
        grunt.task.run('open');
        done();
      }, 400);

    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-bower-task');
    grunt.loadNpmTasks('grunt-forever');
    grunt.loadNpmTasks('grunt-open');

    grunt.registerTask('default', ['build', 'start', 'watch']);
    grunt.registerTask('depoly', ['build', 'forever:server:start'])
    grunt.registerTask('build', ['clean:build', 'bower', 'copy', 'uglify', 'sass']);
};
<commit_msg>fix grunt bug<commit_after>module.exports = function (grunt) {

    grunt.initConfig({
      uglify: {
          options: {
              mangle: false,
              sourceMap: 'public/build/js/main.min.js.map'
          },
          target: {
              files: {
                  'public/build/js/main.js': ['public/js/*.js']
              }
          }
      },
      copy: {
        image: {
          files: [
            {
              expand: true,
              cwd: 'public/img',
              src: '**.*{png,jpg,svg}',
              dest: 'public/build/img/'
            }
          ]
        }
      },
      sass: {
          main: {
              options: {
                  compass: true
              },
              files: {
                  'public/build/css/style.css': 'public/css/style.sass'
              }
          }
      },
      watch: {
          options: {
              livereload: true,
          },
          sass: {
              files: ['public/css/**/*.sass'],
              tasks: ['sass'],
              options: {
                  //
              }
          },
          js: {
              files: ['public/js/*.js'],
              tasks: ['uglify'],
              options: {
                  //
              }
          }
      },
      clean: {
        build: ['public/build']
      },
      bower: {
        install: {
          options: {
            copy: false,
            verbose: true
          }
        }
      },
      open: {
        dev: {
          path: 'http://localhost:3000/'
        }
      },
      forever: {
        server: {
          options: {
            index: 'app.js',
            logDir: 'logs'
          }
        }
      }
    });

    grunt.registerTask('start', 'run server', function() {

      var nodemon = grunt.util.spawn({
        cmd: 'nodemon',
        args: ['app.js']
      });

      nodemon.stdout.pipe(process.stdout);
      nodemon.stderr.pipe(process.stderr);

      var done = this.async();

      setTimeout(function() {
        grunt.task.run('open');
        done();
      }, 400);

    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-bower-task');
    grunt.loadNpmTasks('grunt-forever');
    grunt.loadNpmTasks('grunt-open');

    grunt.registerTask('default', ['build', 'start', 'watch']);
    grunt.registerTask('depoly', ['build', 'forever:server:start'])
    grunt.registerTask('build', ['clean:build', 'bower', 'copy', 'uglify', 'sass']);
};
<|endoftext|>


<commit_before>module.exports = function(grunt) {
    'use strict';

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

        less: {
            development: {
                files: {
                    'dist/css/main.css': 'less/*.less'
                },
                plugins: [
                    new (require('less-plugin-autoprefix'))({browsers: ['last 2 versions']}),
                    new (require('less-plugin-clean-css'))()
                ]
            }
        },

        copy: {
            lib: {
                files: [
                    {expand: true, cwd: 'public/', src: ['**'], dest: 'dist/'}
                ]
            },
            main: {
                src: 'src/main.html',
                dest: 'dist/index.html'
            }
        },

        webpack: {
            myConfig: {
                entry: './src/main.jsx',
                output: {
                    path: './dist/js/',
                    filename: 'main.js'
                },
                stats: {
                    colors: true
                },
                module: {
                    loaders: [
                        {
                            test: /\.jsx?$/,
                            exclude: /(node_modules)/,
                            loaders: ['babel']
                        }
                    ]
                }
            }
        },

        uglify: {
            build: {
                src: 'dist/js/main.js',
                dest: 'dist/js/main.min.js'
            }
        },

        cssmin: {
            build: {
                files: {
                    'dist/css/main.min.css': ['dist/css/main.css']
                }
            }
        },

        flow: {
            options: {
                style: 'color'
            },
            files: {}
        },

        watch: {
            less: {
                files: ['less/**'],
                tasks: ['less']
            },
            js: {
                files: ['src/**'],
                tasks: ['flow', 'webpack']
            }
        }

    });

// 3. Where we tell Grunt we plan to use this plug-in.

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-webpack');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-flow');

// 4. Where we tell Grunt what to do when we type 'grunt' into the terminal.

    grunt.registerTask('default', ['less', 'webpack', 'copy']);

    grunt.registerTask('build', ['less', 'webpack', 'copy']);

    grunt.registerTask('build-production', ['less', 'cssmin', 'webpack', 'uglify', 'copy', 'use-minified']);

// 5. Custom Tasks

    grunt.registerTask('use-minified', 'Update index.html to use minified files.', function() {

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

        var indexPath = path.join('dist', 'index.html');

    grunt.registerTask('default', ['less', 'flow', 'babel', 'webpack']);

        var indexHTML = '';

        // Read dist/index.html as text

        try {
            indexHTML = fs.readFileSync(indexPath, 'utf8');
        } catch(e) {
            grunt.log.error(e.message);
            return false;
        }

        // Find script tag for main.js

        var mainJSPatt = /(<script[^>]+src=[^>]+)(?:main\.js)([^<>]+>)/;

        if(!mainJSPatt.test(indexHTML)) {
            grunt.log.error('Unable to find script tag for main.js in dist/index.html');
            return false;
        }

        // Replace main.js with main.min.js

        indexHTML = indexHTML.replace(mainJSPatt, '$1main.min.js$2');

        // Find link tag for main.css

        var mainCSSPatt = /(<link[^>]+href=[^>]+)(?:main\.css)([^<>]+>)/;

        if(!mainCSSPatt.test(indexHTML)) {
            grunt.log.error('Unable to find link tag for main.css in dist/index.html');
            return false;
        }

        // Replace main.css with main.min.css

        indexHTML = indexHTML.replace(mainCSSPatt, '$1main.min.css$2');

        // Write the new index.html file

        try {
            fs.writeFileSync(indexPath, indexHTML, {encoding: 'utf8'});
        } catch(e) {
            grunt.log.error(e.message);
            return false;
        }

    });

};
<commit_msg>Updated gruntfile<commit_after>module.exports = function(grunt) {
    'use strict';

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

        less: {
            development: {
                files: {
                    'dist/css/main.css': 'less/*.less'
                },
                plugins: [
                    new (require('less-plugin-autoprefix'))({browsers: ['last 2 versions']}),
                    new (require('less-plugin-clean-css'))()
                ]
            }
        },

        copy: {
            lib: {
                files: [
                    {expand: true, cwd: 'public/', src: ['**'], dest: 'dist/'}
                ]
            },
            main: {
                src: 'src/main.html',
                dest: 'dist/index.html'
            }
        },

        webpack: {
            myConfig: {
                entry: './src/main.jsx',
                output: {
                    path: './dist/js/',
                    filename: 'main.js'
                },
                stats: {
                    colors: true
                },
                module: {
                    loaders: [
                        {
                            test: /\.jsx?$/,
                            exclude: /(node_modules)/,
                            loaders: ['babel']
                        }
                    ]
                }
            }
        },

        uglify: {
            build: {
                src: 'dist/js/main.js',
                dest: 'dist/js/main.min.js'
            }
        },

        cssmin: {
            build: {
                files: {
                    'dist/css/main.min.css': ['dist/css/main.css']
                }
            }
        },

        flow: {
            options: {
                style: 'color'
            },
            files: {}
        },

        watch: {
            less: {
                files: ['less/**'],
                tasks: ['less']
            },
            js: {
                files: ['src/**.jsx', 'src/**.js'],
                tasks: ['flow', 'webpack']
            },
            html: {
                files: ['src/*.html', 'public/**'],
                tasks: ['copy']
            }
        }

    });

// 3. Where we tell Grunt we plan to use this plug-in.

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-webpack');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-flow');

// 4. Where we tell Grunt what to do when we type 'grunt' into the terminal.

    grunt.registerTask('default', ['less', 'webpack', 'copy']);

    grunt.registerTask('build', ['less', 'webpack', 'copy']);

    grunt.registerTask('build-production', ['less', 'cssmin', 'webpack', 'uglify', 'copy', 'use-minified']);

// 5. Custom Tasks

    grunt.registerTask('use-minified', 'Update index.html to use minified files.', function() {

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

        var indexPath = path.join('dist', 'index.html');

    grunt.registerTask('default', ['less', 'flow', 'babel', 'webpack']);

        var indexHTML = '';

        // Read dist/index.html as text

        try {
            indexHTML = fs.readFileSync(indexPath, 'utf8');
        } catch(e) {
            grunt.log.error(e.message);
            return false;
        }

        // Find script tag for main.js

        var mainJSPatt = /(<script[^>]+src=[^>]+)(?:main\.js)([^<>]+>)/;

        if(!mainJSPatt.test(indexHTML)) {
            grunt.log.error('Unable to find script tag for main.js in dist/index.html');
            return false;
        }

        // Replace main.js with main.min.js

        indexHTML = indexHTML.replace(mainJSPatt, '$1main.min.js$2');

        // Find link tag for main.css

        var mainCSSPatt = /(<link[^>]+href=[^>]+)(?:main\.css)([^<>]+>)/;

        if(!mainCSSPatt.test(indexHTML)) {
            grunt.log.error('Unable to find link tag for main.css in dist/index.html');
            return false;
        }

        // Replace main.css with main.min.css

        indexHTML = indexHTML.replace(mainCSSPatt, '$1main.min.css$2');

        // Write the new index.html file

        try {
            fs.writeFileSync(indexPath, indexHTML, {encoding: 'utf8'});
        } catch(e) {
            grunt.log.error(e.message);
            return false;
        }

    });

};
<|endoftext|>


<commit_before>// Gruntfile.js

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    dirs: {
        output: 'dist', // path to build folder
    },

    connect: {
      server: {
        options: {
          port: 8000,
          hostname: 'localhost',
        }
      }
    },

    watch: {
      livereload: {
        options: {
          spawn: false,
          livereload: true,
        },
        files: ['*.html', 'src/**/*.js', 'src/**/*.tmpl', 'src/**/*.html', 'css/**/*.scss', '!lib/dontwatch.js'],
        tasks: ['jshint', 'build:dev'] //['default'],
      },
    },
    jshint: {
      options: {
        jshintrc: true,
      },
      all: ['gruntfile.js', 'src/**/*.js', 'test/**/*.js']
    },
    concat: {
        js: {
            src: [
              'src/common/**/*.js', // common scripts (utils and shared methods)
              'src/components/typeahead/*.module.js', // modules first
              'src/components/typeahead/*.js',

              'src/components/**/*.js', // load other source files (order doesn't matter)
              '<%=angularTemplateCache.newModule.dest %>'
            ],
            dest: '<%=dirs.output %>/<%= pkg.name %>.js'
        }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: '<%=dirs.output %>/<%= pkg.name %>.js',
        dest: '<%=dirs.output %>/<%= pkg.name %>.min.js'
      }
    },
    ngAnnotate: {
        options: {
            remove: true, // removes $inject from source (if any)
            add: true,  // adds $inject to source
            singleQuotes: true
        },
        app: {
            files: {
                '<%=dirs.output %>/<%= pkg.name %>.js': '<%=dirs.output %>/<%= pkg.name %>.js'
            }
            /*files: [
                {
                    expand: true,
                    src: ['build/<%= pkg.name %>.js'],
                    ext: '.annotated.js', // Dest filepaths will have this extension.
                    extDot: 'last',       // Extensions in filenames begin after the last dot
                },
            ],*/
        }
    },
    angularTemplateCache: {
      options: {
        module: '<%= pkg.name %>.tpls'
      },
      newModule: {
        options: {
          newModule: true,
        },
        src: '**/*.tmpl',// 'src/components/typeahead/**/*.tmpl'],
        dest: 'tmp/<%= pkg.name %>.tpls.js',
        cwd: 'src/components/typeahead' // path prefix for src
      },
    }
  });

  // Load the plugin that provides the "concat" task.
  grunt.loadNpmTasks('grunt-contrib-concat');

  // Load the plugin that provides the "watch" task.
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Load the plugin that provides the "connect" task.
  grunt.loadNpmTasks('grunt-contrib-connect');

  // Load the plugin that provides the "jshint" task.
  grunt.loadNpmTasks('grunt-contrib-jshint');

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // load the plugin that provides the "ng-annotate" task.
  grunt.loadNpmTasks('grunt-ng-annotate');

  grunt.loadNpmTasks('grunt-angular-templatecache');

  // Default task(s).
  grunt.registerTask('default', 'watch files and start livereload server', ['jshint', 'build:dev', 'connect', 'watch']);

  grunt.registerTask('build:dev', 'build src into dist folder (unminified)', ['angularTemplateCache', 'concat']);
  grunt.registerTask('build', 'build src into dist folder', ['angularTemplateCache', 'concat', 'ngAnnotate', 'uglify']);

};<commit_msg>added cleaning task. Added Karma and coverage. Added grunt-load-task to load all grunt-contrib plugins.<commit_after>// Gruntfile.js

module.exports = function(grunt) {
  // load all grunt plugins (every task that start's with 'grunt-')
  require('load-grunt-tasks')(grunt);

  grunt.loadNpmTasks('grunt-karma');
  grunt.loadNpmTasks('grunt-istanbul-coverage');

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    dirs: {
        output: 'dist', // path to build folder
    },
    sourceFiles: {
      js: [
        'src/common/**/*.js', // common scripts (utils and shared methods)
        'src/components/typeahead/*.module.js', // modules first
        'src/components/typeahead/*.js',

        'src/components/**/*.js', // load other source files (order doesn't matter)
        '<%=angularTemplateCache.newModule.dest %>',
        '!src/**/*.spec.js'
      ]
    },
    karma: {
      unit: {
        options: {
          frameworks: ['jasmine'],
          singleRun: true,
          browsers: ['PhantomJS'],
          files: [
            'bower_components/angular/angular.js',
            'bower_components/angular-mocks/angular-mocks.js',
            '<%=sourceFiles.js %>' //'src/**/*.js'
          ]
        }
      }
    },

    coverage: {
      default: {
        options: {
          thresholds: {
            'statements': 90,
            'branches': 90,
            'lines': 90,
            'functions': 90
          },
          dir: 'coverage',
          root: 'test'
        }
      }
    },

    clean: {
      build: {
        build: ['dist'],
        tmp: ['tmp'],
      },
      test: {
        coverage: ['coverage']
      }
    },

    connect: {
      server: {
        options: {
          port: 8000,
          hostname: 'localhost',
        }
      }
    },

    watch: {
      livereload: {
        options: {
          spawn: false,
          livereload: true,
        },
        files: ['*.html', 'src/**/*.js', 'src/**/*.tmpl', 'src/**/*.html', 'css/**/*.scss', '!lib/dontwatch.js'],
        tasks: ['jshint', 'build:dev'] //['default'],
      },
    },
    jshint: {
      options: {
        jshintrc: true,
      },
      all: ['gruntfile.js', 'src/**/*.js', 'test/**/*.js']
    },
    concat: {
        js: {
            src: '<%=sourceFiles.js %>',
            dest: '<%=dirs.output %>/<%= pkg.name %>.js'
        }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: '<%=dirs.output %>/<%= pkg.name %>.js',
        dest: '<%=dirs.output %>/<%= pkg.name %>.min.js'
      }
    },
    ngAnnotate: {
        options: {
            remove: true, // removes $inject from source (if any)
            add: true,  // adds $inject to source
            singleQuotes: true
        },
        app: {
            files: {
                '<%=dirs.output %>/<%= pkg.name %>.js': '<%=dirs.output %>/<%= pkg.name %>.js'
            }
            /*files: [
                {
                    expand: true,
                    src: ['build/<%= pkg.name %>.js'],
                    ext: '.annotated.js', // Dest filepaths will have this extension.
                    extDot: 'last',       // Extensions in filenames begin after the last dot
                },
            ],*/
        }
    },
    angularTemplateCache: {
      options: {
        module: '<%= pkg.name %>.tpls'
      },
      newModule: {
        options: {
          newModule: true,
        },
        src: '**/*.tmpl',// 'src/components/typeahead/**/*.tmpl'],
        dest: 'tmp/<%= pkg.name %>.tpls.js',
        cwd: 'src/components/typeahead' // path prefix for src
      },
    }
  });

  // Default task(s).
  grunt.registerTask('default', 'watch files and start livereload server', ['jshint', 'build:dev', 'connect', 'watch']);

  grunt.registerTask('build:dev', 'build src into dist folder (unminified)', ['angularTemplateCache', 'concat']);
  grunt.registerTask('build',
    'build src into dist folder',
    ['clean:build', 'angularTemplateCache', 'concat', 'ngAnnotate', 'uglify']
  );
  grunt.registerTask('test', 'Run unit tests (single run)', ['jshint', 'karma']);
  // grunt.registerTask('test:coverage', 'Run test coverage report (Istanbul)', ['coverage']);

};<|endoftext|>