<commit_before>'use strict';

var _ = require('lodash');
var fs = require('fs');
var path = require('path');

var npmDependencies = require('./npm-dependencies');
var prompt = require('../../../prompt');

var TEMPLATE_ROOT = path.resolve(__dirname, '../../../../templates/init/functions/javascript/');
var INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'index.js'), 'utf8');
var PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.lint.json'), 'utf8');
var PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.nolint.json'), 'utf8');
var ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'eslint.json'), 'utf8');

module.exports = function(setup, config) {
  return prompt(setup.functions, [
    {
      name: 'lint',
      type: 'confirm',
      message: 'Do you want to use ESLint to catch probable bugs and enforce style?',
      default: true
    }
  ]).then(function() {
    if (setup.functions.lint) {
      _.set(setup, 'config.functions.predeploy', ['npm --prefix $RESOURCE_DIR run lint']);
      return config.askWriteProjectFile('functions/package.json', PACKAGE_LINTING_TEMPLATE).then(function() {
        config.askWriteProjectFile('functions/.eslintrc.json', ESLINT_TEMPLATE);
      });
    }
    return config.askWriteProjectFile('functions/package.json', PACKAGE_NO_LINTING_TEMPLATE);
  }).then(function() {
    return config.askWriteProjectFile('functions/src/index.js', INDEX_TEMPLATE);
  }).then(function() {
    return npmDependencies.askInstallDependencies(setup, config);
  });
};<commit_msg>Fix index.js location for non-typescript init. (#612)<commit_after>'use strict';

var _ = require('lodash');
var fs = require('fs');
var path = require('path');

var npmDependencies = require('./npm-dependencies');
var prompt = require('../../../prompt');

var TEMPLATE_ROOT = path.resolve(__dirname, '../../../../templates/init/functions/javascript/');
var INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'index.js'), 'utf8');
var PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.lint.json'), 'utf8');
var PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.nolint.json'), 'utf8');
var ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'eslint.json'), 'utf8');

module.exports = function(setup, config) {
  return prompt(setup.functions, [
    {
      name: 'lint',
      type: 'confirm',
      message: 'Do you want to use ESLint to catch probable bugs and enforce style?',
      default: true
    }
  ]).then(function() {
    if (setup.functions.lint) {
      _.set(setup, 'config.functions.predeploy', ['npm --prefix $RESOURCE_DIR run lint']);
      return config.askWriteProjectFile('functions/package.json', PACKAGE_LINTING_TEMPLATE).then(function() {
        config.askWriteProjectFile('functions/.eslintrc.json', ESLINT_TEMPLATE);
      });
    }
    return config.askWriteProjectFile('functions/package.json', PACKAGE_NO_LINTING_TEMPLATE);
  }).then(function() {
    return config.askWriteProjectFile('functions/index.js', INDEX_TEMPLATE);
  }).then(function() {
    return npmDependencies.askInstallDependencies(setup, config);
  });
};
{'fraction_non_alphanumeric': 0.16313162819713037, 'fraction_numerical': 0.0034310667498440423, 'mean_word_length': 4.676106194690266, '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': '6426945', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1037, 'n_words': 188}