mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
31 lines
765 B
TypeScript
31 lines
765 B
TypeScript
import { FunctionInfo } from '../lambda/types'
|
|
|
|
export function buildFunctionContent(func: FunctionInfo, imports: string[], types: string[]): string {
|
|
let content = ''
|
|
|
|
if (imports.length > 0) {
|
|
content += imports.join('\n') + '\n\n'
|
|
}
|
|
|
|
if (types.length > 0) {
|
|
content += types.join('\n') + '\n\n'
|
|
}
|
|
|
|
if (func.comments.length > 0) {
|
|
content += func.comments.join('\n') + '\n'
|
|
}
|
|
|
|
const asyncKeyword = func.isAsync ? 'async ' : ''
|
|
const exportKeyword = 'export '
|
|
|
|
content += `${exportKeyword}${asyncKeyword}function ${func.name}${func.params}${func.returnType} {\n`
|
|
|
|
const bodyLines = func.body.split('\n')
|
|
const actualBody = bodyLines.slice(1, -1).join('\n')
|
|
|
|
content += actualBody + '\n'
|
|
content += '}\n'
|
|
|
|
return content
|
|
}
|