meadowbrook
Version:
Alternative meyda cli
35 lines (33 loc) • 847 B
JavaScript
const jsyaml = require("js-yaml");
const ajv = new (require("ajv"))();
const fs = require("fs");
const path = require("path");
const VIEW = {
usage: null,
schema_json: null
};
const usageYaml = fs.readFileSync(path.join(__dirname, "help.yml"), "utf8");
try {
jsyaml.load(usageYaml);
} catch (e) {
throw "Help file is not valid yaml: " + e.message;
}
VIEW.usage = usageYaml;
const outFileSchema = fs.readFileSync(
path.join(__dirname, "out-schema.yml"),
"utf8"
);
let outFileSchemaObj;
try {
outFileSchemaObj = jsyaml.load(outFileSchema);
} catch (e) {
throw "Out schema not valid yaml: " + e.message;
}
try {
ajv.compile(outFileSchemaObj);
} catch (e) {
throw "Out schema not valid schema: " + e.message;
}
VIEW.schema_yaml = outFileSchema;
VIEW.schema_json = JSON.stringify(outFileSchemaObj, null, 2);
module.exports = VIEW;