Skip to content

Commit

Permalink
feat: add checks to verify Extension of files (#795)
Browse files Browse the repository at this point in the history
Co-authored-by: Aayush <[email protected]>
  • Loading branch information
AayushSaini101 and aayushRedHat authored Sep 12, 2023
1 parent 9d49cbe commit 2837e15
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit 2837e15

Please sign in to comment.