@releaseotto/core
Version:
OTTO performs your action on new versioning of APIs, packages, schemas, etc. Keepings things nice and neatly automated.
39 lines • 1.03 kB
JavaScript
import * as fs from 'fs';
import Ajv from "ajv";
const ajv = new Ajv();
function loadFromFile(location) {
return require(location);
}
function validateConfig(input, schema) {
const validate = ajv.compile(schema);
if (validate(input)) {
return true;
}
else {
console.log(validate.errors);
throw new Error("Not a valid Otto config file", { cause: validate.errors });
}
}
/**
* Load otto config file based on either data or location.
*/
export function loadConfig(input, schema) {
if (typeof input === 'string') {
const isFile = fs.existsSync(input);
let jsonObj;
if (isFile) {
jsonObj = loadFromFile(input);
}
else {
jsonObj = JSON.parse(input);
}
if (validateConfig(jsonObj, schema)) {
return jsonObj;
}
}
else if (typeof input === 'object') {
return input;
}
throw new Error("Unable to load otto configuration");
}
//# sourceMappingURL=input.js.map