import { EnumMemberStructure , OptionalKind , Project } from "ts-morph" ; import path from "path" ; import { generateTypeGraphQLImport } from "./imports" ; import { enumsFolderName } from "./config" ; import { DMMF } from "./dmmf/types" ; import { convertNewLines } from "./helpers" ; export default function generateEnumFromDef ( project , baseDirPath , enumDef ) { const dirPath = path . resolve ( baseDirPath , enumsFolderName ) ; const filePath = path . resolve ( dirPath , `${ enumDef . typeName }.ts` ) ; const sourceFile = project . createSourceFile ( filePath , undefined , { overwrite : true , } ) ; generateTypeGraphQLImport ( sourceFile ) ; sourceFile . addEnum ( { isExported : true , name : enumDef . typeName , ... ( enumDef . docs && { docs : [ { description : convertNewLines ( enumDef . docs ) } ] , } ) , members : enumDef . valuesMap . map < OptionalKind < EnumMemberStructure > > ( ( { name , value } ) => ( { name , value , } ) ) , } ) ; sourceFile . addStatements ( [ `TypeGraphQL.registerEnumType(${ enumDef . typeName }, {
      name: "${ enumDef . typeName }",
      description: ${ enumDef . docs ? `"${ enumDef . docs }"` : "undefined" },
    });` , ] ) ; }