<commit_before>
'use strict';

var util   = require('util')
  , path   = require('path')
  , fs     = require('fs')
  , yeoman = require('yeoman-generator')
  , rimraf = require('rimraf')
  , exec   = require('child_process').exec
  , semver = require('semver')
  , config = require('./../config.js')

module.exports = Generator

function Generator() {
  yeoman.generators.Base.apply(this, arguments)

  this.sourceRoot(path.join(__dirname, 'templates'))
}

util.inherits(Generator, yeoman.generators.NamedBase)

// try to find the config file and read the infos to set the prompts default values
Generator.prototype.getConfig = function getConfig() {
  var cb   = this.async()
    , self = this

  self.configExists = false

  config.getConfig(function(err, data) {
    if (!err) {
      self.configExists = true
    }

    self.defaultAuthorName = data.authorName
    self.defaultAuthorURI = data.authorURI
    self.defaultTheme = data.themeUrl
    self.latestVersion = data.latestVersion

    cb()
  })
}

// get the latest stable version of Wordpress
Generator.prototype.getVersion = function getVersion() {
  var cb   = this.async()
    , self = this

  this.log.writeln('')
  this.log.writeln('Trying to get the latest stable version of Wordpress')

  // try to get the latest version using the git tags
  try {
    var version = exec('git ls-remote --tags git://github.com/WordPress/WordPress.git | tail -n 1', function(err, stdout, stderr) {
                    if (err) {
                      cb()
                    }
                    else {
                      var pattern = /\d\.\d[\.\d]*/ig
                        , match = pattern.exec(stdout)

                      if (match !== null && typeof match[0] !== 'undefined' && match[0] !== 'undefined') {
                        // update config if needed
                        if (semver.gt(match[0], self.latestVersion)) {
                          self.log.writeln('Updating config with latest version: '+match[0])
                          config.updateWordpressVersion(match[0])
                        }

                        self.latestVersion = match[0]
                        self.log.writeln('Latest version: '+self.latestVersion)
                      }
                    }

                    cb()
                  })
  }
  catch(e) {
    cb()
  }
}<commit_msg>Hotfix for ( #31 ) Semver error on Wordpress version<commit_after>
'use strict';

var util   = require('util')
  , path   = require('path')
  , fs     = require('fs')
  , yeoman = require('yeoman-generator')
  , rimraf = require('rimraf')
  , exec   = require('child_process').exec
  , semver = require('semver')
  , config = require('./../config.js')

module.exports = Generator

function Generator() {
  yeoman.generators.Base.apply(this, arguments)

  this.sourceRoot(path.join(__dirname, 'templates'))
}

util.inherits(Generator, yeoman.generators.NamedBase)

// try to find the config file and read the infos to set the prompts default values
Generator.prototype.getConfig = function getConfig() {
  var cb   = this.async()
    , self = this

  self.configExists = false

  config.getConfig(function(err, data) {
    if (!err) {
      self.configExists = true
    }

    self.defaultAuthorName = data.authorName
    self.defaultAuthorURI = data.authorURI
    self.defaultTheme = data.themeUrl
    self.latestVersion = data.latestVersion

    cb()
  })
}

// get the latest stable version of Wordpress
Generator.prototype.getVersion = function getVersion() {
  var cb   = this.async()
    , self = this

  this.log.writeln('')
  this.log.writeln('Trying to get the latest stable version of Wordpress')

  // try to get the latest version using the git tags
  try {
    var version = exec('git ls-remote --tags git://github.com/WordPress/WordPress.git | tail -n 1', function(err, stdout, stderr) {
                    if (err) {
                      cb()
                    }
                    else {
                      var pattern = /\d\.\d[\.\d]*/ig
                        , match = pattern.exec(stdout)
                        , patternShort = /^\d\.\d$/
                        , semverLatestString = match[0]
                        , semverVersionString = self.latestVersion
                        
                      if (semverLatestString.match(patternShort)) semverLatestString += '.0'
                      if (semverVersionString.match(patternShort)) semverVersionString += '.0'

                      if (match !== null && typeof match[0] !== 'undefined' && match[0] !== 'undefined') {
                        // update config if needed
                        if (semver.gt(semverLatestString, semverVersionString)) {
                          self.log.writeln('Updating config with latest version: '+match[0])
                          config.updateWordpressVersion(match[0])
                        }

                        self.latestVersion = match[0]
                        self.log.writeln('Latest version: '+self.latestVersion)
                      }
                    }

                    cb()
                  })
  }
  catch(e) {
    cb()
  }
}
{'fraction_non_alphanumeric': 0.11960326721120186, 'fraction_numerical': 0.003500583430571762, 'mean_word_length': 1.8057828696126568, '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': '3891683', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1388, 'n_words': 337}