From a03846f9ad6ee0b75c85ab93b172cdca35a60904 Mon Sep 17 00:00:00 2001 From: Govinda Raju Date: Wed, 21 Oct 2020 11:08:51 -0700 Subject: [PATCH] chore: interaction model generator can now also write to standard output --- .../InteractionModelGenerator.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/interactionModelGeneration/InteractionModelGenerator.ts b/src/interactionModelGeneration/InteractionModelGenerator.ts index 3bc2741..9b77c2e 100644 --- a/src/interactionModelGeneration/InteractionModelGenerator.ts +++ b/src/interactionModelGeneration/InteractionModelGenerator.ts @@ -293,15 +293,20 @@ export class InteractionModelGenerator { } /** - * Build the interaction model and write to disk. + * Build the interaction model and write to disk or standard output. * - * @param filename - Filename + * @param filename - Filename(optional) */ - buildAndWrite(filename: string) { + buildAndWrite(filename?: string) { const interactionModelJson: string = JSON.stringify(this.build(), null, 2); - const path: string = join(process.cwd(), filename); - fs.writeFileSync(path, interactionModelJson); - log.info(`Wrote interactionModel: ${path}`); + if (filename === undefined) { + process.stdout.write(interactionModelJson); + log.info('Wrote to standard output'); + } else { + const path: string = join(process.cwd(), filename); + fs.writeFileSync(path, interactionModelJson); + log.info(`Wrote interactionModel: ${path}`); + } } }