<commit_before>'use strict';

var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var path = require('path');
var _ = require('lodash');

var options = {};

module.exports = yeoman.generators.Base.extend({
  initializing: function () {
    if (!this.options.skipWelcome) {
      this.log(yosay(
        'Welcome to ' + chalk.red('Gadget') + ', the gnarly generator for Grunt Drupal Tasks!'
      ));
    }

    this.pkg = require('../package.json');
    this.distros = require('./distros');
  },

  prompting: function () {
    var self = this;
    var done = this.async();

    var prompts = require('../lib/prompts');
    prompts = _.filter(prompts, function (item) {
      return _.isUndefined(self.options[item.name]);
    });

    this.prompt(prompts, function (props) {
      options = _.assign(props, this.options);
      this.log("\nOk, I'm going to start assembling this project...");
      done();
    }.bind(this));
  },

  // Install Grunt Drupal Tasks, either the latest published version or the
  // current development version in the master branch.
  installGDT: function() {
    //require('./gdt')(this).install();
  },

  // Determine the latest stable release for the requested Drupal core version.
  getDistroRelease: function () {
    // Provide a fallback value in case the request fails.
    options.drupalDistroRelease = options.drupalDistroVersion;

    // Handle version used by updates.drupal.org for 8.x.x releases.
    var majorVersionForUpdateSystem = options.drupalDistroVersion;
    if (majorVersionForUpdateSystem.match(/^8\.\d+\.x$/)) {
      majorVersionForUpdateSystem = '8.x';
    }

    // Find the latest stable release for the Drupal distro version.
    var done = this.async();
    options.drupalDistro.releaseVersion(majorVersionForUpdateSystem, done, function(err, version, done) {
      if (err) {
        this.log.error(err);
        return done(err);
      }
      options.drupalDistroRelease = version;
      done();
    }.bind(this));
  },

  memcacheVersion: function() {
    if (options.cacheInternal == 'memcache') {
      var done = this.async();
      require('../lib/drupalProjectVersion')
        .latestRelease('memcache', '7.x', done, function(err, version, done) {
          if (err) {
            this.log.error(err);
            return done(err);
          }
          options.memcacheVersion = version;
          done();
        }.bind(this)
      );
    }
  },

  writing: {
    template: function () {
      this.directory(
        this.destinationPath('node_modules/grunt-drupal-tasks/example'),
        this.destinationPath()
      );

      this.directory(
        this.templatePath(path.resolve(options.drupalDistro.id, options.drupalDistroVersion)),
        this.destinationPath()
      );<commit_msg>Correct memcache partial version and 8.x compatibility.<commit_after>'use strict';

var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var path = require('path');
var _ = require('lodash');

var options = {};

module.exports = yeoman.generators.Base.extend({
  initializing: function () {
    if (!this.options.skipWelcome) {
      this.log(yosay(
        'Welcome to ' + chalk.red('Gadget') + ', the gnarly generator for Grunt Drupal Tasks!'
      ));
    }

    this.pkg = require('../package.json');
    this.distros = require('./distros');
  },

  prompting: function () {
    var self = this;
    var done = this.async();

    var prompts = require('../lib/prompts');
    prompts = _.filter(prompts, function (item) {
      return _.isUndefined(self.options[item.name]);
    });

    this.prompt(prompts, function (props) {
      options = _.assign(props, this.options);
      this.log("\nOk, I'm going to start assembling this project...");
      done();
    }.bind(this));
  },

  // Install Grunt Drupal Tasks, either the latest published version or the
  // current development version in the master branch.
  installGDT: function() {
    //require('./gdt')(this).install();
  },

  // Determine the latest stable release for the requested Drupal core version.
  getDistroRelease: function () {
    // Provide a fallback value in case the request fails.
    options.drupalDistroRelease = options.drupalDistroVersion;

    // Handle version used by updates.drupal.org for 8.x.x releases.
    options.majorVersionForUpdateSystem = options.drupalDistroVersion;
    if (options.majorVersionForUpdateSystem.match(/^8\.\d+\.x$/)) {
      options.majorVersionForUpdateSystem = '8.x';
    }


    // Find the latest stable release for the Drupal distro version.
    var done = this.async();
    options.drupalDistro.releaseVersion(options.majorVersionForUpdateSystem, done, function(err, version, done) {
      if (err) {
        this.log.error(err);
        return done(err);
      }
      options.drupalDistroRelease = version;
      done();
    }.bind(this));
  },

  memcacheVersion: function() {
    if (options.cacheInternal == 'memcache') {
      var done = this.async();
      require('../lib/drupalProjectVersion')
        .latestRelease('memcache', options.majorVersionForUpdateSystem, done, function(err, version, done) {
          if (err) {
            this.log.error(err);
            return done(err);
          }
          options.memcacheVersion = version.substr(4);
          done();
        }.bind(this)
      );
    }
  },

  writing: {
    template: function () {
      this.directory(
        this.destinationPath('node_modules/grunt-drupal-tasks/example'),
        this.destinationPath()
      );

      this.directory(
        this.templatePath(path.resolve(options.drupalDistro.id, options.drupalDistroVersion)),
        this.destinationPath()
      );
{'fraction_non_alphanumeric': 0.14007308160779536, 'fraction_numerical': 0.0015660344527579607, 'mean_word_length': 2.781578947368421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '287404', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1673, 'n_words': 391}