{"size": 1743, "ext": "js", "max_stars_repo_path": "util/buildAppConfig.js", "max_stars_repo_name": "isabella232/top-up-sample", "max_stars_repo_stars_event_min_datetime": "2016-08-10T23:56:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-29T23:06:36.000Z", "max_issues_repo_path": "util/buildAppConfig.js", "max_issues_repo_name": "bitpay/top-up-sample", "max_issues_repo_issues_event_min_datetime": "2021-03-23T13:03:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-23T13:03:03.000Z", "max_forks_repo_path": "util/buildAppConfig.js", "max_forks_repo_name": "isabella232/top-up-sample", "max_forks_repo_forks_event_min_datetime": "2016-08-11T13:09:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-29T23:06:23.000Z"}
{"max_stars_count": 5, "max_issues_count": 1, "max_forks_count": 10, "avg_line_length": 30.5789473684, "max_line_length": 91, "alphanum_fraction": 0.6752725186}
#!/usr/bin/env node

'use strict';

var fs = require('fs');
var shell = require('shelljs');

var getCommitHash = function() {
  //exec git command to get the hash of the current commit
  //git rev-parse HEAD

  var hash = shell.exec('git rev-parse HEAD', {
    silent: true
  }).trim().substr(0, 7);
  return hash;
}

var cleanJSONQuotesOnKeys = function(json) {
  return json.replace(/"(\w+)"\s*:/g, '$1:');
};

// Build src/js/appConfig.js from appConfig.json.
var buildAppConfig = function() {
	var production = false; // TODO
	appConfig.commitHash = commitHash;

  for (var i = 0; i < Object.keys(appConfig.paymentMethods).length; i++) {
    var paymentMethod = appConfig.paymentMethods[Object.keys(appConfig.paymentMethods)[i]];

    // Add an id property (equal to its object key) to each payment method.
    paymentMethod.id = Object.keys(appConfig.paymentMethods)[i];

    // Delete non-production payment methods if building for production.
    if (production && !paymentMethod.production) {
      delete appConfig.paymentMethods[Object.keys(appConfig.paymentMethods)[i]];
    } else {
      // Production attribute no longer needed.
      delete paymentMethod.production;
    }
  }

  var content = '';
  content += '\'use strict\';\n\n';
  content += 'angular.module(\'topUpApp\').constant(\'appConfig\', \n';
  content += cleanJSONQuotesOnKeys(JSON.stringify(appConfig, null, 2));
  content += ');\n';
  fs.writeFileSync("./src/js/appConfig.js", content);
};

var commitHash = getCommitHash();
var appConfig = JSON.parse(fs.readFileSync('./appConfig.json', 'utf8'));
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));

buildAppConfig();

console.log('v' + pkg.version + ' #' + commitHash + ' App:' + appConfig.name);
