<commit_before>var Thorax,
  mode = 0777 ^ process.umask(),
  path = require('path'),
  fs = require('fs'),
  exec = require('child_process').exec,
  handlebars = require('handlebars');

//private methods
var camelize = function(string) {
    return string.replace (/(?:^|[-_])(\w)/g, function (_, c) {
      return c ? c.toUpperCase () : '';
    });
  },

  cleanFileName = function(name, pattern, extension) {
    if (name.match(pattern)) {
      name = name.replace(pattern, '');
    }
    if (!name.match(/\.(js|coffee)$/)) {
      name = name + (extension ? '.' + extension : (this.thoraxJSON.language === 'javascript' ? '.js' : '.coffee'));
    }
    return name;
  },

  nameFromFileName = function(file_name) {
    return path.basename(file_name).replace(/\..*$/, '');
  },

  moduleNameFromArguments = function(args) {
    if (args.length === 1) {
      module_name = args[0].split('/').shift();
    } else {
      module_name = args[0];
    }
    if (!this.lumbarJSON.modules[module_name]) {
      this.error('module "' + module_name + '" does not exist');
      console.log('');
      console.log('To create a module or router with this name run either:');
      console.log('  thorax router ' + module_name);
      console.log('  thorax module ' + module_name);
      console.log('');
      if (args.length === 1) {
        console.log('Or specify an existing module:');
        console.log('  thorax ' + module.exports.currentAction + ' your-module-name ' + args[0]);
      }
      console.log('');
      return false;
    }
    return module_name;
  },

  fileNameFromArguments = function(args) {
    if (args.length === 1) {
      return args[0];
    } else {
      return args[1];
    }
  },

  // Recursive mkdir
  mkdirsSync = function(dirname) {
    var pathsNotFound = [];
    var fn = dirname;
    while (true) {
      try {
        var stats = fs.statSync(fn);
        if (stats.isDirectory()) {
          break;
        }
        throw new Error('Unable to create directory at ' + fn);
      }
      catch (e) {
        pathsNotFound.push(fn);
        fn = path.dirname(fn);
      }
    }
    for (var i = pathsNotFound.length - 1; i >- 1; i--) {
      var fn = pathsNotFound[i];
      fs.mkdirSync(fn, mode);
    }
    return pathsNotFound;
  },

  detectThoraxProjectDir = function(options) {
    if (!path.existsSync(path.join(this.target, 'package.json')) || !path.existsSync(path.join(this.target, 'lumbar.json')) || !path.existsSync(path.join(this.target, 'thorax.json'))) {
      //crude attempt to see if we are in a thorax project dir
      var dir, test_target;
      for (var i = 1; i < 4; ++i) {
        dir = [this.target];
        for (var _i = 0; _i < i; ++_i) {
          dir.push('..');
        }
        test_target = path.join.apply(path, dir);
        if (path.existsSync(path.join(test_target, 'package.json')) && path.existsSync(path.join(test_target, 'lumbar.json')) && path.existsSync(path.join(test_target, 'thorax.json'))) {
          setTarget.call(this, test_target);
          return true;
        }
      }
      thorax.log(this.target + ' does not appear to be a thorax project, lumbar.json, thorax.json, package.json must be present');
      if (!options || typeof options.exit === 'undefined' || options.exit === false) {
        process.exit(1);
        return false;
      }
    } else {
      return true;
    }
  },

  setTarget = function(target) {
    this.target = target;
    this._packageJSONPath = path.join(this.target, 'package.json');
    this._lumbarJSONPath = path.join(this.target, 'lumbar.json');
    this._thoraxJSONPath = path.join(this.target, 'thorax.json');
  };

//constructor
module.exports = function(target, options) {
  this.generatorName = 'base'; //for thorax.log
  this.loadPrefix = '';
  setTarget.call(this, target || process.cwd());
  if (options && options.create) {
    this.project = camelize(path.basename(this.target));
  } else {
    if (detectThoraxProjectDir.call(this, options)) {
      this.packageJSON = JSON.parse(fs.readFileSync(this._packageJSONPath));
      this.lumbarJSON = JSON.parse(fs.readFileSync(this._lumbarJSONPath));
      this.thoraxJSON = JSON.parse(fs.readFileSync(this._thoraxJSONPath));
      this.project = this.lumbarJSON.application.name;
    }
  }
};

module.exports.action = function (action) {
  module.exports.currentAction = action;
  return module.exports.actions[action].apply(this, Array.prototype.slice.call(arguments, 1));
};

module.exports.help = [
  "Usage:",
  "",
  "Create a new project & directory:",
  "",
  "  thorax create project-name",
  "",
  "In project directory:",
  "",
  "  thorax view module-name file-name",
  "  thorax collection-view module-name file-name",
  "  thorax model [module-name] file-name",
  "  thorax collection [module-name] file-name",
  "  thorax router module-name",
  "  thorax module name",
  "  thorax template template",
  "  thorax platform name",
  "  thorax package name"
].join("\n");

//actions
module.exports.actions = {
  create: function(target) {
    var commands = [
      'git clone git://github.com/walmartlabs/thorax-example.git ' + target,
      'rm -rf ' + path.join(target, '.git'),
      'cd ' + target,
      'npm install'
    ];
    console.log(commands.join("\n"));
    exec(commands.join(";"), function(error, stdout, stderr) {
      if (stdout) {
        console.log(stdout);
      }
      if (stderr) {
        console.log(stderr);
      }
      console.log('new lumbar + thorax project created in ' + target);
    });
  }<commit_msg>fixed create task<commit_after>var Thorax,
  mode = 0777 ^ process.umask(),
  path = require('path'),
  fs = require('fs'),
  exec = require('child_process').exec,
  handlebars = require('handlebars');

//private methods
var camelize = function(string) {
    return string.replace (/(?:^|[-_])(\w)/g, function (_, c) {
      return c ? c.toUpperCase () : '';
    });
  },

  cleanFileName = function(name, pattern, extension) {
    if (name.match(pattern)) {
      name = name.replace(pattern, '');
    }
    if (!name.match(/\.(js|coffee)$/)) {
      name = name + (extension ? '.' + extension : (this.thoraxJSON.language === 'javascript' ? '.js' : '.coffee'));
    }
    return name;
  },

  nameFromFileName = function(file_name) {
    return path.basename(file_name).replace(/\..*$/, '');
  },

  moduleNameFromArguments = function(args) {
    if (args.length === 1) {
      module_name = args[0].split('/').shift();
    } else {
      module_name = args[0];
    }
    if (!this.lumbarJSON.modules[module_name]) {
      this.error('module "' + module_name + '" does not exist');
      console.log('');
      console.log('To create a module or router with this name run either:');
      console.log('  thorax router ' + module_name);
      console.log('  thorax module ' + module_name);
      console.log('');
      if (args.length === 1) {
        console.log('Or specify an existing module:');
        console.log('  thorax ' + module.exports.currentAction + ' your-module-name ' + args[0]);
      }
      console.log('');
      return false;
    }
    return module_name;
  },

  fileNameFromArguments = function(args) {
    if (args.length === 1) {
      return args[0];
    } else {
      return args[1];
    }
  },

  // Recursive mkdir
  mkdirsSync = function(dirname) {
    var pathsNotFound = [];
    var fn = dirname;
    while (true) {
      try {
        var stats = fs.statSync(fn);
        if (stats.isDirectory()) {
          break;
        }
        throw new Error('Unable to create directory at ' + fn);
      }
      catch (e) {
        pathsNotFound.push(fn);
        fn = path.dirname(fn);
      }
    }
    for (var i = pathsNotFound.length - 1; i >- 1; i--) {
      var fn = pathsNotFound[i];
      fs.mkdirSync(fn, mode);
    }
    return pathsNotFound;
  },

  detectThoraxProjectDir = function(options) {
    if (!path.existsSync(path.join(this.target, 'package.json')) || !path.existsSync(path.join(this.target, 'lumbar.json')) || !path.existsSync(path.join(this.target, 'thorax.json'))) {
      //crude attempt to see if we are in a thorax project dir
      var dir, test_target;
      for (var i = 1; i < 4; ++i) {
        dir = [this.target];
        for (var _i = 0; _i < i; ++_i) {
          dir.push('..');
        }
        test_target = path.join.apply(path, dir);
        if (path.existsSync(path.join(test_target, 'package.json')) && path.existsSync(path.join(test_target, 'lumbar.json')) && path.existsSync(path.join(test_target, 'thorax.json'))) {
          setTarget.call(this, test_target);
          return true;
        }
      }
      thorax.log(this.target + ' does not appear to be a thorax project, lumbar.json, thorax.json, package.json must be present');
      if (!options || typeof options.exit === 'undefined' || options.exit === false) {
        process.exit(1);
        return false;
      }
    } else {
      return true;
    }
  },

  setTarget = function(target) {
    this.target = target;
    this._packageJSONPath = path.join(this.target, 'package.json');
    this._lumbarJSONPath = path.join(this.target, 'lumbar.json');
    this._thoraxJSONPath = path.join(this.target, 'thorax.json');
  };

//constructor
module.exports = function(target, options) {
  this.generatorName = 'base'; //for thorax.log
  this.loadPrefix = '';
  setTarget.call(this, target || process.cwd());
  if (options && options.create) {
    this.project = camelize(path.basename(this.target));
  } else {
    if (detectThoraxProjectDir.call(this, options)) {
      this.packageJSON = JSON.parse(fs.readFileSync(this._packageJSONPath));
      this.lumbarJSON = JSON.parse(fs.readFileSync(this._lumbarJSONPath));
      this.thoraxJSON = JSON.parse(fs.readFileSync(this._thoraxJSONPath));
      this.project = this.lumbarJSON.application.name;
    }
  }
};

module.exports.action = function (action) {
  module.exports.currentAction = action;
  return module.exports.actions[action].apply(this, Array.prototype.slice.call(arguments, 1));
};

module.exports.help = [
  "Usage:",
  "",
  "Create a new project & directory:",
  "",
  "  thorax create project-name",
  "",
  "In project directory:",
  "",
  "  thorax view module-name file-name",
  "  thorax collection-view module-name file-name",
  "  thorax model [module-name] file-name",
  "  thorax collection [module-name] file-name",
  "  thorax router module-name",
  "  thorax module name",
  "  thorax template template",
  "  thorax platform name",
  "  thorax package name"
].join("\n");

//actions
module.exports.actions = {
  create: function(target) {
    var commands = [
      'git clone git://github.com/walmartlabs/thorax-example.git ' + target,
      'cd ' + target,
      'rm -rf .git',
      'mkdir public',
      'npm install'
    ];
    console.log(commands.join("\n"));
    exec(commands.join(";"), function(error, stdout, stderr) {
      if (stdout) {
        console.log(stdout);
      }
      if (stderr) {
        console.log(stderr);
      }
      console.log('new lumbar + thorax project created in ' + target);
    });
  }
{'fraction_non_alphanumeric': 0.16392553768299295, 'fraction_numerical': 0.0034339418037231157, 'mean_word_length': 2.702576112412178, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3539428', 'n_tokens_mistral': 3690, 'n_tokens_neox': 3588, 'n_words': 757}