<commit_before>// CONFIGURE SUB TASK
// configure is called at the init sub task time
// - configureScript checks if there is no such global sh script bin/configure.sh
// to execute
// - configureProject merges all the config files (package.json, .teleport.json and gitignore)
// found also in the templates and located at the first level of the project folder.
// - configureServer does the same kind of task but in each server folder level.

import childProcess from 'child_process'
import fs from 'fs'
import { flatten, merge, uniq } from 'lodash'
import mkdirp from 'mkdirp'
import path from 'path'

import { getGitignores,
  getPackage,
  writeGitignore,
  writePackage
} from '../utils/functions'

export function configure () {
  const { project } = this
  // script
  if (fs.existsSync(path.join(this.project.dir, 'bin/configure.sh'))) {
    this.configureScript()
  }
  // project
  this.configureProject()
  // servers
  this.program.method = 'configureServer'
  this.mapInServers()
  // info
  this.consoleInfo(`Your ${project.package.name} project was successfully configured!`)
}

export function configureScript () {
  const command = `cd ${this.project.dir} && sh bin/configure.sh`
  this.consoleInfo('Let\'s configure the project')
  this.consoleLog(command)
  childProcess.execSync(command, { stdio: [0, 1, 2] })
}

export function configureProject () {
  const { project } = this
  this.configureProjectConfig()
  this.configureProjectPackage()
  this.configureProjectGitignore()
  this.write(project)
}

export function configureProjectConfig () {
  // unpack
  const { project } = this
  // init again the config
  project.config.templateNames = this.getTemplateNames()

  // merge
  project.config = merge(
    project.config,
    ...project.config.templateNames
      .map(templateName => {
        const templateDir = path.join(project.nodeModulesDir, templateName)
        let templateConfig = this.getConfig(templateDir)
        // remove attributes that are specific to the project
        delete templateConfig.templateNames
        if (templateConfig.backend) {
          delete templateConfig.backend.siteName
        }
        return templateConfig
      })
    )
}

export function configureProjectPackage () {
  const { project } = this
  const templateDependencies = this.getTemplateDependencies()
  if (Object.keys(templateDependencies).length > 0) {
    project.package = merge(project.package, {
      devDependencies: templateDependencies<commit_msg>added a default type if no one specified<commit_after>// CONFIGURE SUB TASK
// configure is called at the init sub task time
// - configureScript checks if there is no such global sh script bin/configure.sh
// to execute
// - configureProject merges all the config files (package.json, .teleport.json and gitignore)
// found also in the templates and located at the first level of the project folder.
// - configureServer does the same kind of task but in each server folder level.

import childProcess from 'child_process'
import fs from 'fs'
import { flatten, merge, uniq } from 'lodash'
import mkdirp from 'mkdirp'
import path from 'path'

import { getGitignores,
  getPackage,
  writeGitignore,
  writePackage
} from '../utils/functions'

export function configure () {
  const { project } = this
  // script
  if (fs.existsSync(path.join(this.project.dir, 'bin/configure.sh'))) {
    this.configureScript()
  }
  // project
  this.configureProject()
  // servers
  this.program.method = 'configureServer'
  this.mapInServers()
  // info
  this.consoleInfo(`Your ${project.package.name} project was successfully configured!`)
}

export function configureScript () {
  const command = `cd ${this.project.dir} && sh bin/configure.sh`
  this.consoleInfo('Let\'s configure the project')
  this.consoleLog(command)
  childProcess.execSync(command, { stdio: [0, 1, 2] })
}

export function configureProject () {
  const { project } = this
  this.configureProjectConfig()
  this.configureProjectPackage()
  this.configureProjectGitignore()
  this.write(project)
}

export function configureProjectConfig () {
  // unpack
  const { project } = this
  // init again the config
  project.config.templateNames = this.getTemplateNames()

  // merge
  project.config = merge(
    project.config,
    ...project.config.templateNames
      .map(templateName => {
        const templateDir = path.join(project.nodeModulesDir, templateName)
        let templateConfig = this.getConfig(templateDir)
        // remove attributes that are specific to the project
        delete templateConfig.templateNames
        if (templateConfig.backend) {
          delete templateConfig.backend.siteName
        }
        return templateConfig
      })
    )

  // add a default localhost type if there was not a platfomr template
  // that did taht already
  if (typeof project.config.typesByName === 'undefined') {
    project.config.typesByName = {
      localhost: {}
    }
  }
}

export function configureProjectPackage () {
  const { project } = this
  const templateDependencies = this.getTemplateDependencies()
  if (Object.keys(templateDependencies).length > 0) {
    project.package = merge(project.package, {
      devDependencies: templateDependencies
{'fraction_non_alphanumeric': 0.10011485451761103, 'fraction_numerical': 0.0015313935681470138, 'mean_word_length': 3.5355902777777777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5033085', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1418, 'n_words': 436}