From 3b703e8d203b0882fd0abd8d0f49c7802e946f69 Mon Sep 17 00:00:00 2001 From: Affan Shahid Date: Mon, 8 Jan 2024 09:12:49 +0500 Subject: [PATCH] feat: allow using yaml files as input --- bin/getNamespaces.js | 12 ++++++++++-- package.json | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/getNamespaces.js b/bin/getNamespaces.js index cc52965..4d861d3 100755 --- a/bin/getNamespaces.js +++ b/bin/getNamespaces.js @@ -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) => { @@ -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 diff --git a/package.json b/package.json index f8f5e14..3043593 100644 --- a/package.json +++ b/package.json @@ -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",