Skip to content

Commit

Permalink
update generator.js and react.js
Browse files Browse the repository at this point in the history
- don't reuse methods from generator for now
  • Loading branch information
lmgyuan committed May 24, 2024
1 parent 3e7afe7 commit b3b29a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ class Generator {
}
});
});
// // PR 1162: set log level during construction to avoid asynchronous issues
// this.setLogLevel();
}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/renderer/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
};

0 comments on commit b3b29a1

Please sign in to comment.