import { Project , SourceFile } from "ts-morph" ; import * as fs from 'fs' ; import * as path from 'path' ; import * as hbs from "handlebars" ; import { getAutorestOptions , getSession } from "../../autorestSession" ; import { ClientDetails } from "../../models/clientDetails" ; import { SampleDetails } from "../../models/sampleDetails" ; param clientDetails param project export function generateSamples ( clientDetails , project ) { const samples = clientDetails . samples ; const session = getSession ( ) ; if ( ! samples ) { session . error ( "No samples are found! " , [ ] ) ; } for ( const sample of samples as SampleDetails [ ] ) { try { const file = fs . readFileSync ( path . join ( __dirname , "../static/samples.ts.hbs" ) , { encoding : "utf-8" } ) ; const readmeFileContents = hbs . compile ( file , { noEscape : true } ) ; project . createSourceFile ( `samples-dev/${ sample . sampleFunctionName }.ts` , readmeFileContents ( sample ) , { overwrite : true } ) ; } catch ( error ) { session . error ( "An error was encountered while handling sample generation" , [ sample . sampleFunctionName ] ) ; throw error ; } } }