<commit_before>const path = require('path');
const inquirer = require('inquirer');
const Generator = require('yeoman-generator');
const {toAppId, toName, isValidAppId} = require('./utilities.js');

const VERSION_REGEXP = /'([2-3]\..*)'/;

const PROJECT_TYPES = [
  new inquirer.Separator('   '),
  {
    name: 'Compiled (recommended)',
    short: 'Compiled',
    value: 'ts',
  },
  new inquirer.Separator(
    'Modern JavaScript, JSX and/or TypeScript.'
  ),
  new inquirer.Separator('   '),
  {
    name: 'Vanilla',
    value: 'js'
  },
  new inquirer.Separator('Runs JavaScript files as-is. No ES6 Modules, async/await or JSX.')
];

const IDE_TYPES = [{
  name: 'None',
  value: 'none'
}, {
  name: 'Visual Studio Code',
  value: 'vsc'
}];

const TEST_TYPES = [{
  name: 'None',
  value: 'none'
}, {
  name: 'Mocha with sinon/chai',
  short: 'Mocha',
  value: 'mocha',
}];

module.exports = class extends Generator {

  prompting() {
    return this.prompt([
      {
        type: 'list',
        name: 'tabris_version',
        message: 'Tabris.js Version',
        choices: ['3.x', '2.x']
      }, {
        type: 'input',
        name: 'app_name',
        message: 'App name as it appears on the device\'s home screen:\n',
        default: toName(this.appname)
      }, {
        type: 'input',
        name: 'app_id',
        message: 'App ID',
        default: answers => toAppId(this.user, answers.app_name),
        validate: input => isValidAppId(input) ||
          'Invalid App ID, use alphanumeric characters and periods only, EG: com.domain.app'
      }, {
        type: 'list',
        name: 'proj_type',
        message: 'Type of project?',
        choices: PROJECT_TYPES
      }, {
        type: 'list',
        name: 'ide_type',
        message: 'Additional IDE configuration? (e.g. launch options)',
        choices: IDE_TYPES
      }, {
        name: 'tests',
        type: 'list',
        message: 'Configure unit tests?',
        choices: TEST_TYPES,
        when: answers => answers.proj_type === 'ts' && answers.tabris_version === '3.x'
      }
    ]).then(answers => {
      const main = answers.proj_type === 'js' ? 'src/app.js' : 'dist';
      const author_name = this.user.git.name() || '<NAME>';
      const author_email = this.user.git.email() || '<EMAIL>';
      const tests = answers.tests || 'none';
      const tabris_install_version = this._npmVersion('tabris@' + answers.tabris_version).pop();
      const tabris_doc_url = 'https://tabrisjs.com/documentation/' + this._removePatch(tabris_install_version);
      this._props = Object.assign(answers, {
        main,
        author_name,
        author_email,
        tests,
        tabris_install_version,
        tabris_doc_url
      });
    });
  }

  writing() {
    this.sourceRoot(path.join(path.dirname(this.resolved), 'templates-' + this._props.tabris_version));
    this.fs.copyTpl(
      this.templatePath('_package.json'),
      this.destinationPath('package.json'),
      this._props
    );
    this.fs.copyTpl(
      this.templatePath('cordova'),
      this.destinationPath('cordova'),
      this._props
    );
    this.fs.copyTpl(
      this.templatePath('_tabrisignore'),
      this.destinationPath('.tabrisignore'),
      this._props
    );
    this.fs.copyTpl(
      this.templatePath('_README.md'),
      this.destinationPath('README.md'),
      this._props
    );
    if (this._props.proj_type === 'ts') {
      this.fs.copyTpl(
        this.templatePath('ts/_gitignore'),
        this.destinationPath('.gitignore')
      );
      this.fs.copyTpl(
        this.templatePath('ts/src'),
        this.destinationPath('src'),
        this._props
      );
      this.fs.copyTpl(
        this.templatePath('ts/tsconfig.json'),
        this.destinationPath('tsconfig.json')
      );
      this.fs.copyTpl(
        this.templatePath('ts/tslint.json'),
        this.destinationPath('tslint.json')
      );
      if (this._props.tests === 'mocha') {
        this.fs.copyTpl(
          this.templatePath('ts/test'),
          this.destinationPath('test'),
          this._props
        );
      }
    } else if (this._props.proj_type === 'js') {
      this.fs.copyTpl(
        this.templatePath('js/_gitignore'),
        this.destinationPath('.gitignore')
      );
      this.fs.copyTpl(
        this.templatePath('js/.eslintrc'),
        this.destinationPath('.eslintrc')
      );
      this.fs.copyTpl(
        this.templatePath('js/src'),
        this.destinationPath('src'),
        this._props
      );
    }
    if (this._props.ide_type === 'vsc') {
      this.fs.copyTpl(
        this.templatePath('.vscode'),
        this.destinationPath('.vscode'),
        this._props
      );
    }
  }

  install() {
    this.npmInstall(['tabris@' + this._props.tabris_version + ' || 3.0.0-rc1'], {
      save: true
    });
    if (this._props.proj_type === 'js') {<commit_msg>Install pre-relase tabris module with pinned version<commit_after>const path = require('path');
const inquirer = require('inquirer');
const Generator = require('yeoman-generator');
const {toAppId, toName, isValidAppId} = require('./utilities.js');

const VERSION_REGEXP = /'([2-3]\..*)'/;

const PROJECT_TYPES = [
  new inquirer.Separator('   '),
  {
    name: 'Compiled (recommended)',
    short: 'Compiled',
    value: 'ts',
  },
  new inquirer.Separator(
    'Modern JavaScript, JSX and/or TypeScript.'
  ),
  new inquirer.Separator('   '),
  {
    name: 'Vanilla',
    value: 'js'
  },
  new inquirer.Separator('Runs JavaScript files as-is. No ES6 Modules, async/await or JSX.')
];

const IDE_TYPES = [{
  name: 'None',
  value: 'none'
}, {
  name: 'Visual Studio Code',
  value: 'vsc'
}];

const TEST_TYPES = [{
  name: 'None',
  value: 'none'
}, {
  name: 'Mocha with sinon/chai',
  short: 'Mocha',
  value: 'mocha',
}];

module.exports = class extends Generator {

  prompting() {
    return this.prompt([
      {
        type: 'list',
        name: 'tabris_version',
        message: 'Tabris.js Version',
        choices: ['3.x', '2.x']
      }, {
        type: 'input',
        name: 'app_name',
        message: 'App name as it appears on the device\'s home screen:\n',
        default: toName(this.appname)
      }, {
        type: 'input',
        name: 'app_id',
        message: 'App ID',
        default: answers => toAppId(this.user, answers.app_name),
        validate: input => isValidAppId(input) ||
          'Invalid App ID, use alphanumeric characters and periods only, EG: com.domain.app'
      }, {
        type: 'list',
        name: 'proj_type',
        message: 'Type of project?',
        choices: PROJECT_TYPES
      }, {
        type: 'list',
        name: 'ide_type',
        message: 'Additional IDE configuration? (e.g. launch options)',
        choices: IDE_TYPES
      }, {
        name: 'tests',
        type: 'list',
        message: 'Configure unit tests?',
        choices: TEST_TYPES,
        when: answers => answers.proj_type === 'ts' && answers.tabris_version === '3.x'
      }
    ]).then(answers => {
      const main = answers.proj_type === 'js' ? 'src/app.js' : 'dist';
      const author_name = this.user.git.name() || '<NAME>';
      const author_email = this.user.git.email() || '<EMAIL>';
      const tests = answers.tests || 'none';
      const tabris_install_version = this._npmVersion('tabris@' + answers.tabris_version).pop();
      const tabris_doc_url = 'https://tabrisjs.com/documentation/' + this._removePatch(tabris_install_version);
      this._props = Object.assign(answers, {
        main,
        author_name,
        author_email,
        tests,
        tabris_install_version,
        tabris_doc_url
      });
    });
  }

  writing() {
    this.sourceRoot(path.join(path.dirname(this.resolved), 'templates-' + this._props.tabris_version));
    this.fs.copyTpl(
      this.templatePath('_package.json'),
      this.destinationPath('package.json'),
      this._props
    );
    this.fs.copyTpl(
      this.templatePath('cordova'),
      this.destinationPath('cordova'),
      this._props
    );
    this.fs.copyTpl(
      this.templatePath('_tabrisignore'),
      this.destinationPath('.tabrisignore'),
      this._props
    );
    this.fs.copyTpl(
      this.templatePath('_README.md'),
      this.destinationPath('README.md'),
      this._props
    );
    if (this._props.proj_type === 'ts') {
      this.fs.copyTpl(
        this.templatePath('ts/_gitignore'),
        this.destinationPath('.gitignore')
      );
      this.fs.copyTpl(
        this.templatePath('ts/src'),
        this.destinationPath('src'),
        this._props
      );
      this.fs.copyTpl(
        this.templatePath('ts/tsconfig.json'),
        this.destinationPath('tsconfig.json')
      );
      this.fs.copyTpl(
        this.templatePath('ts/tslint.json'),
        this.destinationPath('tslint.json')
      );
      if (this._props.tests === 'mocha') {
        this.fs.copyTpl(
          this.templatePath('ts/test'),
          this.destinationPath('test'),
          this._props
        );
      }
    } else if (this._props.proj_type === 'js') {
      this.fs.copyTpl(
        this.templatePath('js/_gitignore'),
        this.destinationPath('.gitignore')
      );
      this.fs.copyTpl(
        this.templatePath('js/.eslintrc'),
        this.destinationPath('.eslintrc')
      );
      this.fs.copyTpl(
        this.templatePath('js/src'),
        this.destinationPath('src'),
        this._props
      );
    }
    if (this._props.ide_type === 'vsc') {
      this.fs.copyTpl(
        this.templatePath('.vscode'),
        this.destinationPath('.vscode'),
        this._props
      );
    }
  }

  install() {
    const version = this._props.tabris_install_version;
    const preRelease = version.indexOf('-') !== -1;
    this.npmInstall(['tabris@' + version], {
      ['save' + (preRelease ? 'Exact' : 'Prod')]: true
    });
    if (this._props.proj_type === 'js') {
{'fraction_non_alphanumeric': 0.16076128771006276, 'fraction_numerical': 0.0017209961530674225, 'mean_word_length': 2.360204081632653, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '1949970', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3222, 'n_words': 583}