<commit_before>var path = require("path"),
    fs = require("fs"),
    languages = require("./l10n/languages.json").active;

var BannerPlugin = require("webpack/lib/BannerPlugin");
var SeparateFileTypeChunkPlugin = require("./scripts/SeparateFileTypeChunkPlugin.js");

module.exports = function(grunt) {
  // grunt.loadTasks('scripts/grunt');
  grunt.loadNpmTasks('grunt-recess');
  grunt.loadNpmTasks('grunt-webpack');
  grunt.loadNpmTasks('grunt-preprocess');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-mocha-protractor');
  grunt.loadNpmTasks('grunt-jade-l10n-extractor');
  grunt.loadNpmTasks('grunt-node-webkit-builder');
  grunt.loadNpmTasks('grunt-bower-task');
  grunt.loadNpmTasks('grunt-webfont');
  grunt.loadNpmTasks('grunt-shell');
  grunt.loadNpmTasks('grunt-aws');

  // Ripple client dependencies
  var deps = ["deps/js/jquery/dist/jquery.js",
              "deps/js/swfobject.js",
              "deps/js/setImmediate.js",
              "deps/js/underscore/underscore.js",
              "deps/js/downloadify.js",
              "deps/js/angular/angular.js",
              "deps/js/angular-route/angular-route.js",
              "deps/js/store.js/store.js",
              "deps/js/ripple.js",
              "deps/js/ripple-sjcl.js",
              "deps/js/moment/moment.js",
              "deps/js/bootstrap-modal.js",
              "deps/js/bootstrap-tooltip.js",
              "deps/js/bootstrap-popover.js",
              "deps/js/angular-bootstrap/ui-bootstrap-tpls.js",
              "deps/js/bootstrap-datepicker.js",
              "deps/js/qrcode-generator/js/qrcode.js",
              "deps/js/spin.js/dist/spin.js",
              "deps/js/snapjs/snap.js"];

  var compat_ie = ["compat/ie/base64/base64.js",
                   "compat/ie/ws/web_socket.js",
                   "compat/ie/ws/config.js",
                   "compat/ie/xdr/xdr.js"];

  var compat_nw = ["compat/nw/setImmediate/setImmediate.js"];

  /**
   * Returns true if the source is newer than the destination.
   */
  var isNewer = function (src,dest) {
    if (!fs.existsSync(dest)) {
      return true;
    }
    var fromstat = fs.statSync(src);
    var tostat = fs.statSync(dest);
    return fromstat.mtime > tostat.mtime;
  };

  /**
   * Where there are many files that compile to one, this returns true
   * if any of the input files are newer than the output.
   */
  var manyToOne = function (dest, src) {
    var compile = true;
    if (fs.existsSync(dest)) {
      var from = grunt.file.expand(src);
      var tostat = fs.statSync(dest);
      compile = false;
      for (var i = from.length - 1; i >= 0; i--) {
        if (fs.statSync(from[i]).mtime > tostat.mtime) {
          compile = true;
          break;
        }
      }
    }
    return [{dest:dest, src:compile?src:[]}];
  };

  /**
   * Add a prefix to a filename or array of filenames.
   */
  var prefix = function (pre, f) {
    if (Array.isArray(f)) {
      return f.map(prefix.bind(this, pre));
    } else if ("string" === typeof f) {
      return pre+f;
    } else {
      return f;
    }
  };

  grunt.registerTask("version", "Describes current git commit", function (prop) {
    var done = this.async();

    grunt.log.write("Version: ");

    grunt.util.spawn({
      cmd : "git",
      args : [ "describe", "--tags", "--always", "--dirty" ]
    }, function (err, result) {
      if (err) {
        grunt.config(prop || "meta.version", "unknown");
        grunt.log.writeln("Unable to determine version, continuing".red);
        return done();
      }

      grunt.config(prop || "meta.version", result.stdout);

      grunt.log.writeln(result.stdout.green);

      done(result);
    });
  });

  var aws = grunt.file.readJSON('config.json');

  grunt.initConfig({
    aws: {
      accessKeyId: aws.key,
      secretAccessKey: aws.secret,
    },
    s3: {
      options: {
        accessKeyId: aws.key,
        secretAccessKey: aws.secret,
        bucket: aws.bucket,
        enableWeb: true,
      },
      build: {
        cwd: 'build/packages/',
        src: '**'
      }
    },

    pkg: grunt.file.readJSON('package.json'),
    meta: {},
    shell: {
      options: {
        stdout: true,
        failOnError: true
      },
      linux: {
        command: [
          'tar -cvf ./build/packages/ripple-client32.tar ./build/pkg/nw/releases/RippleClient/linux32/RippleClient',
          'tar -cvf ./build/packages/ripple-client64.tar ./build/pkg/nw/releases/RippleClient/linux64/RippleClient'
        ].join('&')
      },
      osx: {
        command: process.platform === 'darwin' ? [
          'npm install appdmg',
          'appdmg ./res/dmg/dmg_config.json ./build/packages/ripple-client.dmg'
        ].join('&') : 'echo Skipping DMG build, only supported on OSX'
      }
    },
    recess: {
      web: {
        src: ['src/less/ripple/web.less'],
        dest: 'build/dist/ripple.css',
        options: {
          compile: true<commit_msg>[Desktop client] Added version-config file to deployment for download.html page<commit_after>var path = require("path"),
    fs = require("fs"),
    languages = require("./l10n/languages.json").active;

var BannerPlugin = require("webpack/lib/BannerPlugin");
var SeparateFileTypeChunkPlugin = require("./scripts/SeparateFileTypeChunkPlugin.js");

module.exports = function(grunt) {
  // grunt.loadTasks('scripts/grunt');
  grunt.loadNpmTasks('grunt-recess');
  grunt.loadNpmTasks('grunt-webpack');
  grunt.loadNpmTasks('grunt-preprocess');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-mocha-protractor');
  grunt.loadNpmTasks('grunt-jade-l10n-extractor');
  grunt.loadNpmTasks('grunt-node-webkit-builder');
  grunt.loadNpmTasks('grunt-bower-task');
  grunt.loadNpmTasks('grunt-webfont');
  grunt.loadNpmTasks('grunt-shell');
  grunt.loadNpmTasks('grunt-aws');

  // Ripple client dependencies
  var deps = ["deps/js/jquery/dist/jquery.js",
              "deps/js/swfobject.js",
              "deps/js/setImmediate.js",
              "deps/js/underscore/underscore.js",
              "deps/js/downloadify.js",
              "deps/js/angular/angular.js",
              "deps/js/angular-route/angular-route.js",
              "deps/js/store.js/store.js",
              "deps/js/ripple.js",
              "deps/js/ripple-sjcl.js",
              "deps/js/moment/moment.js",
              "deps/js/bootstrap-modal.js",
              "deps/js/bootstrap-tooltip.js",
              "deps/js/bootstrap-popover.js",
              "deps/js/angular-bootstrap/ui-bootstrap-tpls.js",
              "deps/js/bootstrap-datepicker.js",
              "deps/js/qrcode-generator/js/qrcode.js",
              "deps/js/spin.js/dist/spin.js",
              "deps/js/snapjs/snap.js"];

  var compat_ie = ["compat/ie/base64/base64.js",
                   "compat/ie/ws/web_socket.js",
                   "compat/ie/ws/config.js",
                   "compat/ie/xdr/xdr.js"];

  var compat_nw = ["compat/nw/setImmediate/setImmediate.js"];

  /**
   * Returns true if the source is newer than the destination.
   */
  var isNewer = function (src,dest) {
    if (!fs.existsSync(dest)) {
      return true;
    }
    var fromstat = fs.statSync(src);
    var tostat = fs.statSync(dest);
    return fromstat.mtime > tostat.mtime;
  };

  /**
   * Where there are many files that compile to one, this returns true
   * if any of the input files are newer than the output.
   */
  var manyToOne = function (dest, src) {
    var compile = true;
    if (fs.existsSync(dest)) {
      var from = grunt.file.expand(src);
      var tostat = fs.statSync(dest);
      compile = false;
      for (var i = from.length - 1; i >= 0; i--) {
        if (fs.statSync(from[i]).mtime > tostat.mtime) {
          compile = true;
          break;
        }
      }
    }
    return [{dest:dest, src:compile?src:[]}];
  };

  /**
   * Add a prefix to a filename or array of filenames.
   */
  var prefix = function (pre, f) {
    if (Array.isArray(f)) {
      return f.map(prefix.bind(this, pre));
    } else if ("string" === typeof f) {
      return pre+f;
    } else {
      return f;
    }
  };

  grunt.registerTask("version", "Describes current git commit", function (prop) {
    var done = this.async();

    grunt.log.write("Version: ");

    grunt.util.spawn({
      cmd : "git",
      args : [ "describe", "--tags", "--always", "--dirty" ]
    }, function (err, result) {
      if (err) {
        grunt.config(prop || "meta.version", "unknown");
        grunt.log.writeln("Unable to determine version, continuing".red);
        return done();
      }

      grunt.config(prop || "meta.version", result.stdout);

      grunt.log.writeln(result.stdout.green);

      done(result);
    });
  });

  var aws = grunt.file.readJSON('config.json');
  var configDesktopRead = grunt.file.readJSON('res/nw/package_desktop.json');
  var configDesktopWrite = grunt.file.write('res/nw/config.js', 'var config = ' + JSON.stringify(configDesktopRead));

  grunt.initConfig({
    aws: {
      accessKeyId: aws.key,
      secretAccessKey: aws.secret
    },
    s3: {
      options: {
        accessKeyId: aws.key,
        secretAccessKey: aws.secret,
        bucket: aws.bucket,
        enableWeb: true
      },
      build: {
        cwd: 'build/packages/',
        src: '**'
      },
      specificFiles: {
        src: 'res/nw/config.js',
        dest: 'version-config.js'
      }
    },

    pkg: grunt.file.readJSON('package.json'),
    meta: {},
    shell: {
      options: {
        stdout: true,
        failOnError: true
      },
      linux: {
        command: [
          'tar -cvf ./build/packages/ripple-client32.tar ./build/pkg/nw/releases/RippleClient/linux32/RippleClient',
          'tar -cvf ./build/packages/ripple-client64.tar ./build/pkg/nw/releases/RippleClient/linux64/RippleClient'
        ].join('&')
      },
      osx: {
        command: process.platform === 'darwin' ? [
          'npm install appdmg',
          'appdmg ./res/dmg/dmg_config.json ./build/packages/ripple-client.dmg'
        ].join('&') : 'echo Skipping DMG build, only supported on OSX'
      }
    },
    recess: {
      web: {
        src: ['src/less/ripple/web.less'],
        dest: 'build/dist/ripple.css',
        options: {
          compile: true
{'fraction_non_alphanumeric': 0.1590082952744897, 'fraction_numerical': 0.0035418025911082116, 'mean_word_length': 2.258426966292135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '594771', 'n_tokens_mistral': 3755, 'n_tokens_neox': 3634, 'n_words': 602}