@releaseotto/core
Version:
OTTO performs your action on new versioning of APIs, packages, schemas, etc. Keepings things nice and neatly automated.
69 lines • 2.37 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = void 0;
const fs = __importStar(require("fs"));
const ajv_1 = __importDefault(require("ajv"));
const ajv = new ajv_1.default();
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.
*/
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");
}
exports.loadConfig = loadConfig;
//# sourceMappingURL=input.js.map