<commit_before>import { Command, arg, format } from '@prisma/cli'
import { isError } from 'util'
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import { printError, printFix } from '../prompt/utils/print'

export const defaultSchema = `// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// The \`datasource\` block is used to specify the connection to your DB.
// Set the \`provider\` field to match your DB type: "postgresql", "mysql" or "sqlite".
// The \`url\` field must contain the connection string to your DB.
// Learn more about connection strings for your DB: https://pris.ly/connection-strings
datasource db {
  provider = "postgresql" // other options are: "mysql" and "sqlite"
  url      = "postgresql://johndoe:johndoe@localhost:5432/mydb?schema=public"
}
// Other examples for connection strings are:
// SQLite: url = "sqlite:./dev.db"
// MySQL:  url = "mysql://johndoe:johndoe@localhost:3306/mydb"
// You can also use environment variables to specify the connection string: https://pris.ly/prisma-schema#using-environment-variables

// By adding the \`generator\` block, you specify that you want to generate Prisma's DB client.
// The client is generated by runnning the \`prisma generate\` command and will be located in \`node_modules/@prisma\` and can be imported in your code as:
// import { Prisma Client } from '@prisma/client'
generator client {
  provider = "prisma-client-js"
}

// Next steps:
// 1. Add your DB connection string as the \`url\` of the \`datasource\` block
// 2. Run \`prisma2 introspect\` to get your data model into the schema
// 3. Run \`prisma2 generate\` to generate Prisma Client JS
// 4. Start using Prisma Client JS in your application`

export class Init implements Command {
  static new(): Init {
    return new Init()
  }

  private constructor() {}

  async parse(argv: string[]): Promise<any> {
    // parse the arguments according to the spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
    })

    if (isError(args)) {
      return null
    }

    if (args['--help']) {
      return this.help()
    }

    const outputDirName = args._[0]
    const outputDir = outputDirName ? path.join(process.cwd(), outputDirName) : process.cwd()
    const prismaFolder = path.join(outputDir, 'prisma')

    if (fs.existsSync(path.join(outputDir, 'schema.prisma'))) {
      console.log(printError(`File ${chalk.bold('schema.prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (fs.existsSync(prismaFolder)) {
      console.log(printError(`Folder ${chalk.bold('prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (fs.existsSync(path.join(prismaFolder, 'schema.prisma'))) {
      console.log(printError(`File ${chalk.bold('prisma/schema.prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (fs.existsSync(path.join(prismaFolder, 'schema.prisma'))) {
      console.log(printError(`File ${chalk.bold('prisma/schema.prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (!fs.existsSync(outputDir)) {
      fs.mkdirSync(outputDir)
    }

    if (!fs.existsSync(prismaFolder)) {
      fs.mkdirSync(prismaFolder)
    }

    fs.writeFileSync(path.join(prismaFolder, 'schema.prisma'), defaultSchema)

    return format(`We created ${chalk.green('prisma/schema.prisma')} for you.
      Edit it with your favorite editor to update your database connection so Prisma can connect to it.

      When done, run ${chalk.green('prisma2 introspect')} to test the connection and introspect the data model from your existing database.
      Then run ${chalk.green('prisma2 generate')} to generate a Prisma Client based on this data model that can be used in your application.

      More information in our documentation:
      http://tbd
    `)
  }

  help() {
    return console.log(
      format(`<commit_msg>Add getting started link<commit_after>import { Command, arg, format } from '@prisma/cli'
import { isError } from 'util'
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import { printError, printFix } from '../prompt/utils/print'

export const defaultSchema = `// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// The \`datasource\` block is used to specify the connection to your DB.
// Set the \`provider\` field to match your DB type: "postgresql", "mysql" or "sqlite".
// The \`url\` field must contain the connection string to your DB.
// Learn more about connection strings for your DB: https://pris.ly/connection-strings
datasource db {
  provider = "postgresql" // other options are: "mysql" and "sqlite"
  url      = "postgresql://johndoe:johndoe@localhost:5432/mydb?schema=public"
}
// Other examples for connection strings are:
// SQLite: url = "sqlite:./dev.db"
// MySQL:  url = "mysql://johndoe:johndoe@localhost:3306/mydb"
// You can also use environment variables to specify the connection string: https://pris.ly/prisma-schema#using-environment-variables

// By adding the \`generator\` block, you specify that you want to generate Prisma's DB client.
// The client is generated by runnning the \`prisma generate\` command and will be located in \`node_modules/@prisma\` and can be imported in your code as:
// import { Prisma Client } from '@prisma/client'
generator client {
  provider = "prisma-client-js"
}

// Next steps:
// 1. Add your DB connection string as the \`url\` of the \`datasource\` block
// 2. Run \`prisma2 introspect\` to get your data model into the schema
// 3. Run \`prisma2 generate\` to generate Prisma Client JS
// 4. Start using Prisma Client JS in your application`

export class Init implements Command {
  static new(): Init {
    return new Init()
  }

  private constructor() {}

  async parse(argv: string[]): Promise<any> {
    // parse the arguments according to the spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
    })

    if (isError(args)) {
      return null
    }

    if (args['--help']) {
      return this.help()
    }

    const outputDirName = args._[0]
    const outputDir = outputDirName ? path.join(process.cwd(), outputDirName) : process.cwd()
    const prismaFolder = path.join(outputDir, 'prisma')

    if (fs.existsSync(path.join(outputDir, 'schema.prisma'))) {
      console.log(printError(`File ${chalk.bold('schema.prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (fs.existsSync(prismaFolder)) {
      console.log(printError(`Folder ${chalk.bold('prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (fs.existsSync(path.join(prismaFolder, 'schema.prisma'))) {
      console.log(printError(`File ${chalk.bold('prisma/schema.prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (fs.existsSync(path.join(prismaFolder, 'schema.prisma'))) {
      console.log(printError(`File ${chalk.bold('prisma/schema.prisma')} already exists in your project.
        Please try again in a project that is not yet using Prisma.
      `))
      process.exit(1)
    }

    if (!fs.existsSync(outputDir)) {
      fs.mkdirSync(outputDir)
    }

    if (!fs.existsSync(prismaFolder)) {
      fs.mkdirSync(prismaFolder)
    }

    fs.writeFileSync(path.join(prismaFolder, 'schema.prisma'), defaultSchema)

    return format(`We created ${chalk.green('prisma/schema.prisma')} for you.
      Edit it with your favorite editor to update your database connection so Prisma can connect to it.

      When done, run ${chalk.green('prisma2 introspect')} to test the connection and introspect the data model from your existing database.
      Then run ${chalk.green('prisma2 generate')} to generate a Prisma Client based on this data model that can be used in your application.

      More information in our documentation:
      https://pris.ly/getting-started
    `)
  }

  help() {
    return console.log(
      format(`
{'fraction_non_alphanumeric': 0.1211943793911007, 'fraction_numerical': 0.004918032786885246, 'mean_word_length': 3.188818048062776, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 7, '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': '3090117', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2561, 'n_words': 886}