Skip to content
Snippets Groups Projects
Commit 9ca105c4 authored by Lars Trieloff's avatar Lars Trieloff
Browse files

Add option to omit README. Fixes #13

parent 6e1c6598
Branches
Tags
No related merge requests found
......@@ -33,6 +33,8 @@ var argv = require('optimist')
.describe('s', 'Custom meta schema path to validate schemas')
.alias('x', 'schema-out')
.describe('x', 'output JSON Schema files including description and validated examples in the _new folder at output directory')
.alias('n', 'no-readme')
.describe('n', 'Do not generate a README.md file in the output directory')
.check(function(args) {
if (!fs.existsSync(args.input)) {
throw 'Input file "' + args.input + '" does not exist!';
......@@ -51,6 +53,7 @@ var schemaPath = path.resolve(argv.d);
var outDir = path.resolve(argv.o);
var schemaDir = argv.x ? path.resolve(argv.x) : outDir;
var target = fs.statSync(schemaPath);
const readme = argv.n !== true;
if (argv.s){
ajv.addMetaSchema(require(path.resolve(argv.s)));
......@@ -87,7 +90,7 @@ if (target.isDirectory()) {
return Promise.reduce(files, readSchemaFile, schemaPathMap)
.then(schemaMap => {
logger.info('finished reading all *.schema.json files in %s, beginning processing….', schemaPath);
return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements);
return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, readme);
})
.then(() => {
logger.info('Processing complete.');
......
......@@ -390,8 +390,9 @@ Schema.setSchemaPathMap=function(schemaMap){
* @param {string} docDir - where documentation will be generated
* @param {string} schemaDir - where schemas will be generated, if null, `docDir` will be used
* @param {map} metaElements - a map of additional YAML frontmatter to be added to the generated Markdown
* @param {boolean} readme - generate a README.md directory listing
*/
Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements) {
Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme) {
schemaDir = schemaDir ? schemaDir : docDir;
smap=schemaMap;
let keys = Object.keys(schemaMap);
......@@ -423,9 +424,13 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements
schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir) ]);
});
}).then(result => {
console.log('Output processed. Trying to make a README.md now');
const markdowns = result.map(r => { return r[0];});
return readmeWriter(markdowns, schemaMap, docDir, schemaPath);
if (readme) {
console.log('Output processed. Trying to make a README.md now');
const markdowns = result.map(r => { return r[0];});
return readmeWriter(markdowns, schemaMap, docDir, schemaPath);
} else {
console.log('Output processed.');
}
});
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment