diff --git a/lib/generator.js b/lib/generator.js index edb392d6f..c5f16374b 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -28,7 +28,8 @@ const { exists, fetchSpec, getInvalidOptions, - isReactTemplate + isReactTemplate, + isJsFile, } = require('./utils'); const { registerFilters } = require('./filtersRegistry'); const { registerHooks } = require('./hooksRegistry'); @@ -637,6 +638,7 @@ class Generator { if (!valid) return log.debug(`${relativeSourceFile} was not generated because condition specified for this file in template configuration in conditionalFiles matched`); } } + if (this.isNonRenderableFile(relativeSourceFile)) return await copyFile(sourceFile, targetFile); await this.renderAndWriteToFile(asyncapiDocument, sourceFile, targetFile); @@ -686,8 +688,11 @@ class Generator { * @return {boolean} */ isNonRenderableFile(fileName) { - if (!Array.isArray(this.templateConfig.nonRenderableFiles)) return false; - return this.templateConfig.nonRenderableFiles.some(globExp => minimatch(fileName, globExp)); + const nonRenderableFiles = this.templateConfig.nonRenderableFiles || []; + if (!Array.isArray(nonRenderableFiles)) return false; + if (nonRenderableFiles.some(globExp => minimatch(fileName, globExp))) return true; + if (isReactTemplate(this.templateConfig) && !isJsFile(fileName)) return true; + return false; } /** diff --git a/lib/utils.js b/lib/utils.js index 5f3de0aca..791dc3062 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -111,9 +111,9 @@ utils.fetchSpec = (link) => { }; /** - * Checks if given string is URL and if not, we assume it is file path + * Checks if given string is URL and if not, we assume it is file path * - * @param {String} str Information representing file path or url + * @param {String} str information representing file path or url * @returns {Boolean} */ utils.isFilePath = (str) => { @@ -121,7 +121,18 @@ utils.isFilePath = (str) => { }; /** - * Get version of the generator + * Checks if given file path is JS file + * + * @param {String} filename information representing file path + * @returns {Boolean} + */ +utils.isJsFile = (filepath) => { + const ext = filepath.split('.').pop() || ''; + return ['js', 'jsx', 'cjs'].includes(ext); +}; + +/** + * Get version of the generator * * @returns {String} */