Skip to content

Commit

Permalink
feat: find yamls from a dir
Browse files Browse the repository at this point in the history
  • Loading branch information
adantoscano committed Oct 3, 2023
1 parent 612f97f commit 367edbd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/services/find-oas-from-dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import path from 'path';
import * as fs from 'fs';

export default function fromDir(startPath) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return [];
}

const files = fs.readdirSync(startPath);
return files.reduce((acc, file) => {
const filename = path.join(startPath, file);
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
return [...acc, ...fromDir(filename)]; //recurse
} else if (filename.endsWith('.yaml')) {
console.log('-- found: ', filename);
return [...acc, {
filename: file,
path: startPath
}]
};
}, []);
};

0 comments on commit 367edbd

Please # to comment.