import { readFileSync } from 'fs' ; import { resolve } from 'path' ; import { createLogger } from '@sap-cloud-sdk/util' ; import { Directory , SourceFile , SourceFileStructure } from 'ts-morph' ; import { getCopyrightHeader } from '@sap-cloud-sdk/generator-common/internal' ; const logger = createLogger ( { package : 'generator' , messageContext : 'file-generator' } ) ; internal export function sourceFile ( directory , relativePath , content , overwrite ) { const file = directory . createSourceFile ( `${ relativePath }.ts` , addFileComment ( content ) , { overwrite } ) ; file . formatText ( { insertSpaceAfterCommaDelimiter : true } ) ; return file ; } internal export function otherFile ( directory , relativePath , content , overwrite ) { return directory . createSourceFile ( relativePath , content , { overwrite } ) ; } internal export function copyFile ( fromPath , toRelativePath , toDirectory , overwrite ) { try { const fileContent = readFileSync ( resolve ( fromPath ) , { encoding : 'utf8' } ) ; toDirectory . createSourceFile ( toRelativePath , fileContent , { overwrite } ) ; } catch ( err ) { logger . error ( err ) ; } } function addFileComment ( content ) { content . leadingTrivia = getCopyrightHeader ( ) ; return content ; }