<commit_before>var bump = require('gulp-bump');
var exec = require('child_process').exec;
var fs = require('fs-extra');
var git = require('gulp-git');
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var tagVersion = require('gulp-tag-version');
var template = require('gulp-template');
var util = require('util');
var yaml = require('js-yaml');
var resource = require('./src/resource');
var helpers = require('./src/helpers');

/**
 * Paths
 */
var test = 'test/**/*';

/**
 * Environment
 */
var languages = {
  js: {
    repo: 'Asana/node-asana',
    branch: 'api-meta-incoming',
    templatePath: 'src/templates',
    outputPath: 'lib/resources/gen',
    updatePackage: function(version, cb) {
      var repoRoot = paths.repo('js');
      var destPackage = readPackage(repoRoot + '/package.json');
      destPackage.version = version;
      writePackage(repoRoot + '/package.json', destPackage);
      exec('git add package.json', {cwd: repoRoot}, cb);
    }
  }
};

var paths = {
  dist: function(lang) {
    return 'dist/' + lang;
  },
  repo: function(lang) {
    return 'dist/git/' + lang;
  },
  repoOutput: function(lang) {
    return paths.repo(lang) + '/' + paths.repoOutputRelative(lang);
  },
  repoOutputRelative: function(lang) {
    return languages[lang].outputPath;
  }
};

function readPackage(filename) {
  return fs.readJSONSync(filename || 'package.json');
}

function writePackage(filename, data) {
  return fs.writeJSONSync(filename || 'package.json', data);
}

/**
 * High-level tasks
 */

// Build all languages
gulp.task('build', ['test'].concat(Object.keys(languages).map(function(lang) {
  return 'build-' + lang;
})));

// Deploy languages
gulp.task('deploy', ['ensure-git-clean', 'build'].concat(Object.keys(languages).map(function(lang) {
  return 'deploy-' + lang;
})));

/**
 * Generate build and deploy rules for each language
 */
var resourceNames = resource.names();
Object.keys(languages).forEach(function(lang) {
  var config = languages[lang];
  var outputPath = paths.repoOutput(lang);
  var repoRoot = paths.repo(lang);
  var token = process.env.ASANA_GITHUB_TOKEN || null;

  function echoAndExec() {
    if (process.env.GULP_DEBUG) {
      console.log('+ ' + arguments[0]);
    }
    return exec.apply(null, arguments);
  }

  function resTaskName(resourceName) {
    return 'build-' + lang + '-' + resourceName;
  }

  /**
   * Clean work area for target repo
   */
  Object.keys(languages).forEach(function(lang) {
    gulp.task('clean-' + lang, function() {
      fs.removeSync(paths.dist(lang));
    });
  });

  /**
   * Checkout target repo, for build and deploy
   */
  gulp.task('checkout-' + lang, ['clean-', lang], function(cb) {

    cloneRepo(cb);

    function cloneRepo(cb) {
      fs.removeSync(repoRoot);
      var url = (token !== null)
          ? util.format('https://github.com/%s', config.repo)
          : util.format('<EMAIL>:%s', config.repo);
      echoAndExec(
          util.format('git clone %s %s', url, repoRoot),
          switchToBranch);
    }

    function switchToBranch(err, stdout, stderr) {
      if (err) { cb(err); return; }
      var branch = config.branch;
      echoAndExec(
          util.format('git checkout --track -b %s origin/%s', branch, branch),
          {cwd: repoRoot},
          done);
    }

    function done(err, stdout, stderr) {
      if (err) { cb(err); return; }
      cb();
    }
  });

  /**
   * Build rules, per resource.
   */
  resourceNames.forEach(function(resourceName) {
    gulp.task(resTaskName(resourceName), function() {
      // Support templates existing either locally or in target repo.
      var templatePath = config.templatePath ?
          (paths.repo(lang) + '/' + config.templatePath):
          ('src/templates/' + lang);
      var resourceTemplateInfo = require(templatePath).resource;

      // Find the template info for resources
      var resource = resource.load(resourceName);
      var templateHelpers = helpers(lang);
      return gulp.src(templatePath + '/' + resourceTemplateInfo.template)
          .pipe(
              template(resource, {
                imports: templateHelpers,
                variable: 'resource'
              }))
          .pipe(
              rename(resourceTemplateInfo.filename(resource, templateHelpers)))
          .pipe(
              gulp.dest(paths.dist(lang)));
    });
  });
  gulp.task(
      'build-' + lang,
      ['checkout-' + lang].concat(resourceNames.map(resTaskName)));

  /**<commit_msg>fix some problems<commit_after>var bump = require('gulp-bump');
var exec = require('child_process').exec;
var fs = require('fs-extra');
var git = require('gulp-git');
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var tagVersion = require('gulp-tag-version');
var template = require('gulp-template');
var util = require('util');
var yaml = require('js-yaml');
var resource = require('./src/resource');
var helpers = require('./src/helpers');

/**
 * Paths
 */
var test = 'test/**/*';

/**
 * Environment
 */
var languages = {
  js: {
    repo: 'Asana/node-asana',
    branch: 'api-meta-incoming',
    templatePath: 'src/templates',
    outputPath: 'lib/resources/gen',
    updatePackage: function(version, cb) {
      var repoRoot = paths.repo('js');
      var destPackage = readPackage(repoRoot + '/package.json');
      destPackage.version = version;
      writePackage(repoRoot + '/package.json', destPackage);
      exec('git add package.json', {cwd: repoRoot}, cb);
    }
  }
};

var paths = {
  dist: function(lang) {
    return 'dist/' + lang;
  },
  repo: function(lang) {
    return 'dist/git/' + lang;
  },
  repoOutput: function(lang) {
    return paths.repo(lang) + '/' + paths.repoOutputRelative(lang);
  },
  repoOutputRelative: function(lang) {
    return languages[lang].outputPath;
  }
};

function readPackage(filename) {
  return fs.readJSONSync(filename || 'package.json');
}

function writePackage(filename, data) {
  return fs.writeJSONSync(filename || 'package.json', data);
}

/**
 * High-level tasks
 */

// Build all languages
gulp.task('build', ['test'].concat(Object.keys(languages).map(function(lang) {
  return 'build-' + lang;
})));

// Deploy languages
gulp.task('deploy', ['ensure-git-clean', 'build'].concat(Object.keys(languages).map(function(lang) {
  return 'deploy-' + lang;
})));

/**
 * Generate build and deploy rules for each language
 */
var resourceNames = resource.names();
Object.keys(languages).forEach(function(lang) {
  var config = languages[lang];
  var outputPath = paths.repoOutput(lang);
  var repoRoot = paths.repo(lang);
  var token = process.env.ASANA_GITHUB_TOKEN || null;

  function echoAndExec() {
    if (process.env.GULP_DEBUG) {
      console.log('+ ' + arguments[0]);
    }
    return exec.apply(null, arguments);
  }

  function resTaskName(resourceName) {
    return 'build-' + lang + '-' + resourceName;
  }

  /**
   * Clean work area for target repo
   */
  Object.keys(languages).forEach(function(lang) {
    gulp.task('clean-' + lang, function() {
      fs.removeSync(paths.dist(lang));
    });
  });

  /**
   * Checkout target repo, for build and deploy
   */
  gulp.task('checkout-' + lang, ['clean-' + lang], function(cb) {

    cloneRepo(cb);

    function cloneRepo(cb) {
      fs.removeSync(repoRoot);
      var url = (token !== null)
          ? util.format('https://github.com/%s', config.repo)
          : util.format('<EMAIL>:%s', config.repo);
      echoAndExec(
          util.format('git clone %s %s', url, repoRoot),
          switchToBranch);
    }

    function switchToBranch(err, stdout, stderr) {
      if (err) { cb(err); return; }
      var branch = config.branch;
      echoAndExec(
          util.format('git checkout --track -b %s origin/%s', branch, branch),
          {cwd: repoRoot},
          done);
    }

    function done(err, stdout, stderr) {
      if (err) { cb(err); return; }
      cb();
    }
  });

  /**
   * Build rules, per resource.
   */
  resourceNames.forEach(function(resourceName) {
    gulp.task(resTaskName(resourceName), ['checkout-' + lang], function() {
      // Support templates existing either locally or in target repo.
      var templatePath = config.templatePath ?
          (paths.repo(lang) + '/' + config.templatePath):
          ('src/templates/' + lang);
      var resourceTemplateInfo = require('./' + templatePath).resource;

      // Find the template info for resources
      var resourceInstance = resource.load(resourceName);
      var templateHelpers = helpers(lang);
      return gulp.src(templatePath + '/' + resourceTemplateInfo.template)
          .pipe(
              template(resourceInstance, {
                imports: templateHelpers,
                variable: 'resource'
              }))
          .pipe(
              rename(resourceTemplateInfo.filename(resourceInstance, templateHelpers)))
          .pipe(
              gulp.dest(paths.dist(lang)));
    });
  });
  gulp.task(
      'build-' + lang,
      resourceNames.map(resTaskName));

  /**
{'fraction_non_alphanumeric': 0.16261147198062315, 'fraction_numerical': 0.0002201915666629968, 'mean_word_length': 2.946133796698523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5027232', 'n_tokens_mistral': 2833, 'n_tokens_neox': 2797, 'n_words': 602}