diff --git a/cli.js b/cli.js index 4b1cbbd9d9c41ead7338987c917376a5b7b139fb..12bfd97f0233eb33d4a900ee91e74e943f72ee08 100644 --- a/cli.js +++ b/cli.js @@ -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.'); diff --git a/lib/schema.js b/lib/schema.js index 56d7e6c90b6cd3bb14394819821678bc83afda15..c329ab64adca3127b21c84e5422787b892c1aa91 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -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.'); + } }); };