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

feat: add checks to verify Extension of files #795

Merged
merged 6 commits into from
Sep 12, 2023
Merged
Changes from all 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
17 changes: 15 additions & 2 deletions src/commands/new/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,21 @@ export default class NewFile extends Command {
async createAsyncapiFile(fileName:string, selectedTemplate:string) {
const asyncApiFile = await readFile(resolve(__dirname, '../../../assets/examples/', selectedTemplate), { encoding: 'utf8' });

const fileNameHasFileExtension = fileName.includes('.');
const fileNameToWriteToDisk = fileNameHasFileExtension ? fileName : `${fileName}.yaml`;
let fileNameToWriteToDisk;

if (!fileName.includes('.')) {
fileNameToWriteToDisk=`${fileName}.yaml`;
} else {
const extension=fileName.split('.')[1];

if (extension==='yml'||extension==='yaml'||extension==='json') {
fileNameToWriteToDisk=fileName;
} else {
console.log('CLI Support only yml, yaml and json extension for file');

return;
}
}

try {
const content = await readFile(fileNameToWriteToDisk, { encoding: 'utf8' });
Expand Down