Skip to content

Commit

Permalink
fix: skipping if has a no OAS file
Browse files Browse the repository at this point in the history
  • Loading branch information
adantoscano committed Oct 4, 2023
1 parent 20514f8 commit a6c3456
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/services/find-oas-from-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,30 @@ async function isOas(filePath) {
return oasRegEx.test(firstLine);
}

export default async function findOasFromDir(startPath) {
const findOasFromDir = async (startPath, acc) => {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return [];
}

const files = fs.readdirSync(startPath);
return files.reduce(async (acc, file) => {
const oasFiles = acc || [];

for(const file of files) {
const filePath = path.join(startPath, file);
const stat = fs.lstatSync(filePath);
if (stat.isDirectory()) {
return [...(await acc), ...(await findOasFromDir(filePath))];
}
if (file.endsWith('.yaml') && (await isOas(filePath))) {
return [...(await acc), {
await findOasFromDir(filePath, oasFiles);
} else if (file.endsWith('.yaml') && (await isOas(filePath))) {
oasFiles.push({
filename: file,
path: startPath,
filePath,
}]
})
}
return []
}, []);
};
}
console.log(oasFiles);
return oasFiles;
};

export default findOasFromDir

0 comments on commit a6c3456

Please # to comment.