2019-03-23 06:38:24 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const upath = require('upath');
|
|
|
|
const { getOptions } = require('../lib/config/definitions');
|
|
|
|
|
|
|
|
const schema = {
|
|
|
|
title: 'JSON schema for Renovate config files (https://renovatebot.com/)',
|
|
|
|
$schema: 'http://json-schema.org/draft-04/schema#',
|
|
|
|
type: 'object',
|
|
|
|
properties: {},
|
|
|
|
};
|
|
|
|
const options = getOptions();
|
2020-02-06 14:29:20 +00:00
|
|
|
options.sort((a, b) => {
|
|
|
|
if (a.name < b.name) return -1;
|
|
|
|
if (a.name > b.name) return 1;
|
|
|
|
return 0;
|
|
|
|
});
|
2019-03-23 06:38:24 +00:00
|
|
|
const properties = {};
|
|
|
|
|
|
|
|
function createSingleConfig(option) {
|
|
|
|
const temp = {};
|
2019-03-23 07:41:08 +00:00
|
|
|
if (option.description) {
|
|
|
|
temp.description = option.description;
|
|
|
|
}
|
2019-03-31 06:01:06 +00:00
|
|
|
temp.type = option.type;
|
2019-03-23 07:44:18 +00:00
|
|
|
if (temp.type === 'array') {
|
|
|
|
if (option.subType) {
|
|
|
|
temp.items = {
|
2019-03-31 06:01:06 +00:00
|
|
|
type: option.subType,
|
2019-03-23 07:44:18 +00:00
|
|
|
};
|
|
|
|
if (option.format) {
|
|
|
|
temp.items.format = option.format;
|
|
|
|
}
|
|
|
|
if (option.allowedValues) {
|
|
|
|
temp.items.enum = option.allowedValues;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-23 07:27:46 +00:00
|
|
|
if (option.format) {
|
2019-03-23 07:44:18 +00:00
|
|
|
temp.format = option.format;
|
|
|
|
}
|
|
|
|
if (option.allowedValues) {
|
|
|
|
temp.enum = option.allowedValues;
|
2019-03-23 07:27:46 +00:00
|
|
|
}
|
2019-03-23 06:38:24 +00:00
|
|
|
}
|
2019-03-23 07:15:09 +00:00
|
|
|
if (option.default !== undefined) {
|
2019-03-23 06:38:24 +00:00
|
|
|
temp.default = option.default;
|
|
|
|
}
|
2019-11-24 11:32:00 +00:00
|
|
|
if (option.additionalProperties !== undefined) {
|
|
|
|
temp.additionalProperties = option.additionalProperties;
|
|
|
|
}
|
2019-03-31 07:16:29 +00:00
|
|
|
if (temp.type === 'object' && !option.freeChoice) {
|
2019-03-23 07:43:00 +00:00
|
|
|
temp.$ref = '#';
|
|
|
|
}
|
2019-03-23 06:38:24 +00:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createSchemaForParentConfigs() {
|
|
|
|
for (const option of options) {
|
|
|
|
if (!option.parent) {
|
|
|
|
properties[option.name] = createSingleConfig(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addChildrenArrayInParents() {
|
|
|
|
for (const option of options) {
|
|
|
|
if (option.parent) {
|
|
|
|
properties[option.parent].items = {
|
|
|
|
allOf: [
|
|
|
|
{
|
|
|
|
type: 'object',
|
|
|
|
properties: {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createSchemaForChildConfigs() {
|
|
|
|
for (const option of options) {
|
|
|
|
if (option.parent) {
|
|
|
|
properties[option.parent].items.allOf[0].properties[
|
|
|
|
option.name
|
|
|
|
] = createSingleConfig(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateSchema() {
|
|
|
|
createSchemaForParentConfigs();
|
|
|
|
addChildrenArrayInParents();
|
|
|
|
createSchemaForChildConfigs();
|
|
|
|
schema.properties = properties;
|
|
|
|
fs.writeFileSync(
|
|
|
|
upath.join(__dirname, '../renovate-schema.json'),
|
|
|
|
JSON.stringify(schema, null, 2),
|
|
|
|
'utf-8'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
generateSchema();
|