Skip to content

Commit

Permalink
feat: allow using yaml files as input
Browse files Browse the repository at this point in the history
  • Loading branch information
affanshahid committed Jan 8, 2024
1 parent 083e72b commit 3b703e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions bin/getNamespaces.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const fs = require('fs')
const path = require('path')
const YAML = require('yaml')

const parsers = {
'.json': JSON.parse,
'.yml': YAML.parse,
'.yaml': YAML.parse
}

const getFiles = (srcpath) => {
return fs.readdirSync(srcpath).filter((file) => {
return !fs.statSync(path.join(srcpath, file)).isDirectory()
}).filter((file) => path.extname(file) === '.json').map((file) => path.join(srcpath, file))
}).filter((file) => Object.keys(parsers).includes(path.extname(file))).map((file) => path.join(srcpath, file))
}

const getDirectories = (srcpath) => {
Expand All @@ -26,7 +33,8 @@ module.exports = (p) => {
const allFiles = getAllFiles(p)

return allFiles.map((file) => {
const namespace = JSON.parse(fs.readFileSync(file, 'utf-8'))
const parse = parsers[path.extname(file)]
const namespace = parse(fs.readFileSync(file, 'utf-8'))
const sepFile = file.split(path.sep)
const fileName = sepFile[sepFile.length - 1]
const name = path.parse(fileName).name
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
},
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.23.2"
"@babel/runtime": "^7.23.2",
"yaml": "^2.3.4"
},
"devDependencies": {
"@babel/core": "^7.23.3",
Expand Down

0 comments on commit 3b703e8

Please sign in to comment.