From b3b29a1a61763813eb1413c6eb8b8d5c355acc87 Mon Sep 17 00:00:00 2001 From: lmgyuan Date: Fri, 24 May 2024 17:31:40 -0400 Subject: [PATCH] update generator.js and react.js - don't reuse methods from generator for now --- lib/generator.js | 5 +---- lib/renderer/react.js | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 1d9941c62..ab50cd75a 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -145,8 +145,6 @@ class Generator { } }); }); - // // PR 1162: set log level during construction to avoid asynchronous issues - // this.setLogLevel(); } /** @@ -199,7 +197,6 @@ class Generator { async generate(asyncapiDocument, parseOptions = {}) { this.validateAsyncAPIDocument(asyncapiDocument); await this.setupOutput(); - // PR 1162: always set log level during construction to avoid asynchronous issues this.setLogLevel(); await this.installAndSetupTemplate(); @@ -856,7 +853,7 @@ class Generator { if (renderContent === undefined) { return; } else if (isReactTemplate(this.templateConfig)) { - await saveRenderedReactContent(renderContent, outputPath, this.noOverwriteGlobs, this); + await saveRenderedReactContent(renderContent, outputPath, this.noOverwriteGlobs); } else { await writeFile(outputPath, renderContent); } diff --git a/lib/renderer/react.js b/lib/renderer/react.js index 45213e544..68cde621a 100644 --- a/lib/renderer/react.js +++ b/lib/renderer/react.js @@ -62,7 +62,7 @@ reactExport.renderReact = async (asyncapiDocument, filePath, extraTemplateData, * @param {String} outputPath Path to the file being rendered. * @param {String[]} noOverwriteGlobs globs to check for files that should not be overwritten. */ -const saveContentToFile = async (renderedContent, outputPath, noOverwriteGlobs = [], generator) => { +const saveContentToFile = async (renderedContent, outputPath, noOverwriteGlobs = []) => { let filePath = outputPath; // Might be the same as in the `fs` package, but is an active choice for our default file permission for any rendered files. let permissions = 0o666; @@ -88,7 +88,8 @@ const saveContentToFile = async (renderedContent, outputPath, noOverwriteGlobs = } // reuse methods from the generator.js to check if the file should be overwritten - const shouldOverwrite = await generator.shouldOverwriteFile(filePath); + // const shouldOverwrite = await generator.shouldOverwriteFile(filePath); + const shouldOverwrite = !noOverwriteGlobs.some(globExp => minimatch(filePath, globExp)) // Write the file only if it should not be skipped if (shouldOverwrite) { @@ -109,11 +110,11 @@ const saveContentToFile = async (renderedContent, outputPath, noOverwriteGlobs = * @param {String} outputPath Path to the file being rendered. * @param {String[]} noOverwriteGlobs globs to check for files that should not be overwritten. */ -reactExport.saveRenderedReactContent = async (renderedContent, outputPath, noOverwriteGlobs = [], generator) => { +reactExport.saveRenderedReactContent = async (renderedContent, outputPath, noOverwriteGlobs = []) => { // If the rendered content is an array, we need to save each file individually if (Array.isArray(renderedContent)) { return Promise.all(renderedContent.map(content => saveContentToFile(content, outputPath, noOverwriteGlobs))); } // Otherwise, we can save the single file - return saveContentToFile(renderedContent, outputPath, noOverwriteGlobs, generator); + return saveContentToFile(renderedContent, outputPath, noOverwriteGlobs); };