Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy non-JS files in the React templates by default #472

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const {
exists,
fetchSpec,
getInvalidOptions,
isReactTemplate
isReactTemplate,
isJsFile,
} = require('./utils');
const { registerFilters } = require('./filtersRegistry');
const { registerHooks } = require('./hooksRegistry');
Expand Down Expand Up @@ -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);
magicmatatjahu marked this conversation as resolved.
Show resolved Hide resolved

await this.renderAndWriteToFile(asyncapiDocument, sourceFile, targetFile);
Expand Down Expand Up @@ -687,7 +689,9 @@ class Generator {
*/
isNonRenderableFile(fileName) {
if (!Array.isArray(this.templateConfig.nonRenderableFiles)) return false;
return this.templateConfig.nonRenderableFiles.some(globExp => minimatch(fileName, globExp));
if (this.templateConfig.nonRenderableFiles.some(globExp => minimatch(fileName, globExp))) return true;
if (isReactTemplate(this.templateConfig) && !isJsFile(fileName)) return true;
return false;
}

/**
Expand Down
17 changes: 14 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,28 @@ 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) => {
return !url.parse(str).hostname;
};

/**
* 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);
derberg marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Get version of the generator
*
* @returns {String}
*/
Expand Down