UNPKG

@borduhh/avro-typescript-generator

Version:
50 lines (49 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateConfig = exports.loadConfig = void 0; const fs_1 = require("fs"); const path_1 = require("path"); /** * Loads the configuration file * * @param configPath The path the configuration file * @returns The configuration object */ const loadConfig = (configPath) => new Promise((resolve, reject) => { (0, fs_1.readFile)(configPath, (err, data) => { if (err) reject(err); try { const parsedData = data.toString(); return resolve(parsedData); } catch (err) { reject(err); } }); }); exports.loadConfig = loadConfig; /** * Validates configuration file and retrieves only options we need * @param config Parsed configuration * @returns A valid configuration */ const validateConfig = (config) => { const inputPath = config.inputPath; if (!inputPath || typeof inputPath !== 'string') throw new Error('Invalid input path. Please add a valid input path in your config file.'); if (config.logicalTypes) Object.keys(config.logicalTypes).forEach((key) => { const logicalTypeValue = config.logicalTypes[key]; if (typeof logicalTypeValue !== 'string' || typeof logicalTypeValue !== 'number' || typeof logicalTypeValue !== 'boolean') throw new Error(`Type ${typeof logicalTypeValue} for ${key} is invalid. Logical types must be converted to strings, numbers, or booleans.`); }); return { inputPath: (0, path_1.join)(__dirname, '../../', config.inputPath), outputDir: (0, path_1.join)(__dirname, '../../', config.outputDir) || (0, path_1.join)(__dirname, '../../', './types'), logicalTypes: { ...config.logicalTypes }, }; }; exports.validateConfig = validateConfig;