import { writeFileSync } from "fs" ; import { logErrorMessage } from "office-addin-cli" ; import { generateCustomFunctionsMetadata } from "./generate" ; export async function generate ( inputPath , outputPath ) { try { if ( ! inputPath ) { throw new Error ( "You need to provide the path to the source file for custom functions." ) ; } const results = await generateCustomFunctionsMetadata ( inputPath ) ; if ( results . errors . length > 0 ) { console . error ( "Errors found:" ) ; results . errors . forEach ( ( err ) => console . log ( err ) ) ; } else { if ( outputPath ) { try { writeFileSync ( outputPath , results . metadataJson ) ; } catch ( err ) { throw new Error ( `Cannot write to file: ${ outputPath }.` ) ; } } else { console . log ( results . metadataJson ) ; } } } catch ( err ) { logErrorMessage ( err ) ; } }