<commit_before>'use strict';

var path        = require('path');
var chalk       = require('chalk');
var Config      = require('../utils/config');
var Command     = require('../models/command');
var Project     = require('../models/project');
var linkEnv     = require('../tasks/link-environment');
var stringUtils = require('../utils/string');
var ui          = require('../ui');
var Promise     = require('../ext/promise');

module.exports = Command.extend({
  name: 'new',
  description: 'Creates a cordova project with an ember-cli project inside with preinstalled dependencies and files for easy app development. If the git option is supplied it will initialize a git repo and commit the initial setup.',
  commandSuffix: '<app-name> <reverse.style.domain> <options...>',
  optionsHelp: [
    '--directory|-d  (Default: project name)',
    '--git|-g'
  ],
  parseArgs: function() {
    this.args.name = this.rawArgs[1];
    this.args.id   = this.rawArgs[2];
  },
  validateArgs: function() {
    if(this.args.name && this.args.id) {
      return true;
    }
  },
  parseOptions: function() {
    this.options.dirName = this.options.directory || this.options.d || this.args.name;
    this.options.dirName = stringUtils.dasherize(this.options.dirName);
    this.options.git     = this.options.hasOwnProperty('git') || this.options.hasOwnProperty('g') || false;
  },
  run: function() {
    var root = path.join(process.cwd(), this.options.dirName);
    var configPath  = path.join(root, '.ember-cdv');

    this.config = new Config(configPath, {
      root:          path.join(process.cwd(), this.options.dirName),
      name:          this.args.name,
      modulePrefix:  stringUtils.dasherize(this.args.name),
      id:            this.args.id
    });

    this.setupCordova()
      .then(this.setupEmber.bind(this))
      .then(this.linkEnvironment.bind(this))
      .then(this.initializeGit.bind(this))
      .then(function() {
        ui.write(chalk.cyan('\n\n-------------------\n'));
        ui.write(chalk.green('All Done. Enjoy :)\n'));
        ui.write(chalk.cyan('-------------------\n'));
      })
      .catch(function(err){
        ui.write(chalk.red('\nError thrown while setting up project:\n\n'));
        ui.write(err);
      });
  },
  setupCordova: function() {
    var createProject = require('../tasks/create-cordova-project')(this.config);
    var copyHooks     = require('../tasks/copy-hooks')(this.config);
    var addPlatforms  = require('../tasks/add-platforms')(this.config);
    var updateConfig  = require('../tasks/update-config-xml')(this.config);

    return createProject().then(copyHooks).then(addPlatforms).then(updateConfig);
  },
  setupEmber: function() {
    var createProject      = require('../tasks/create-ember-project')(this.config);
    var installBowerDeps   = require('../tasks/install-bower-dependencies')(this.config);
    var installNpmDeps     = require('../tasks/install-npm-dependencies')(this.config);
    var removeDefaultFiles = require('../tasks/remove-default-ember-cli-files')(this.config);
    var copyEmberTmpls     = require('../tasks/copy-ember-templates')(this.config);

    return createProject().then(installBowerDeps).then(installNpmDeps).then(removeDefaultFiles).then(copyEmberTmpls);
  },
  linkEnvironment: function() {
    var self = this;

    return new Promise(function(resolve, reject){
      try {
        var root = self.config.get('root');

        self.config.delete('root');
        // Hack to not write root since I don't need it after project is
        // created
        // It must be written for Project.closest to work below
        self.config.flush();
        self.config.set('root', root)

        // TODO: this is duplication of the path listed in
        // tasks/build. I'd like to remove it
        var link = linkEnv(Project.closest(root), 'ember/tmp/output');

        link().then(resolve, reject);

      } catch(e) {
        reject(e);<commit_msg>fix default symlink path changed in https://github.com/stefanpenner/ember-cli/pull/1034<commit_after>'use strict';

var path        = require('path');
var chalk       = require('chalk');
var Config      = require('../utils/config');
var Command     = require('../models/command');
var Project     = require('../models/project');
var linkEnv     = require('../tasks/link-environment');
var stringUtils = require('../utils/string');
var ui          = require('../ui');
var Promise     = require('../ext/promise');

module.exports = Command.extend({
  name: 'new',
  description: 'Creates a cordova project with an ember-cli project inside with preinstalled dependencies and files for easy app development. If the git option is supplied it will initialize a git repo and commit the initial setup.',
  commandSuffix: '<app-name> <reverse.style.domain> <options...>',
  optionsHelp: [
    '--directory|-d  (Default: project name)',
    '--git|-g'
  ],
  parseArgs: function() {
    this.args.name = this.rawArgs[1];
    this.args.id   = this.rawArgs[2];
  },
  validateArgs: function() {
    if(this.args.name && this.args.id) {
      return true;
    }
  },
  parseOptions: function() {
    this.options.dirName = this.options.directory || this.options.d || this.args.name;
    this.options.dirName = stringUtils.dasherize(this.options.dirName);
    this.options.git     = this.options.hasOwnProperty('git') || this.options.hasOwnProperty('g') || false;
  },
  run: function() {
    var root = path.join(process.cwd(), this.options.dirName);
    var configPath  = path.join(root, '.ember-cdv');

    this.config = new Config(configPath, {
      root:          path.join(process.cwd(), this.options.dirName),
      name:          this.args.name,
      modulePrefix:  stringUtils.dasherize(this.args.name),
      id:            this.args.id
    });

    this.setupCordova()
      .then(this.setupEmber.bind(this))
      .then(this.linkEnvironment.bind(this))
      .then(this.initializeGit.bind(this))
      .then(function() {
        ui.write(chalk.cyan('\n\n-------------------\n'));
        ui.write(chalk.green('All Done. Enjoy :)\n'));
        ui.write(chalk.cyan('-------------------\n'));
      })
      .catch(function(err){
        ui.write(chalk.red('\nError thrown while setting up project:\n\n'));
        ui.write(err);
      });
  },
  setupCordova: function() {
    var createProject = require('../tasks/create-cordova-project')(this.config);
    var copyHooks     = require('../tasks/copy-hooks')(this.config);
    var addPlatforms  = require('../tasks/add-platforms')(this.config);
    var updateConfig  = require('../tasks/update-config-xml')(this.config);

    return createProject().then(copyHooks).then(addPlatforms).then(updateConfig);
  },
  setupEmber: function() {
    var createProject      = require('../tasks/create-ember-project')(this.config);
    var installBowerDeps   = require('../tasks/install-bower-dependencies')(this.config);
    var installNpmDeps     = require('../tasks/install-npm-dependencies')(this.config);
    var removeDefaultFiles = require('../tasks/remove-default-ember-cli-files')(this.config);
    var copyEmberTmpls     = require('../tasks/copy-ember-templates')(this.config);

    return createProject().then(installBowerDeps).then(installNpmDeps).then(removeDefaultFiles).then(copyEmberTmpls);
  },
  linkEnvironment: function() {
    var self = this;

    return new Promise(function(resolve, reject){
      try {
        var root = self.config.get('root');

        self.config.delete('root');
        // Hack to not write root since I don't need it after project is
        // created
        // It must be written for Project.closest to work below
        self.config.flush();
        self.config.set('root', root)

        // TODO: this is duplication of the path listed in
        // tasks/build. I'd like to remove it
        var link = linkEnv(Project.closest(root), 'ember/dist');

        link().then(resolve, reject);

      } catch(e) {
        reject(e);
{'fraction_non_alphanumeric': 0.16926167754897037, 'fraction_numerical': 0.0010045203415369162, 'mean_word_length': 2.80736137667304, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7277496', 'n_tokens_mistral': 2431, 'n_tokens_neox': 2397, 'n_words': 489}