From 9ca105c4c360f2ecb38ddd06c5a51dbfe026825b Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Wed, 13 Dec 2017 16:30:52 +0000 Subject: [PATCH] Add option to omit README. Fixes #13 --- cli.js | 5 ++++- lib/schema.js | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cli.js b/cli.js index 4b1cbbd..12bfd97 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 56d7e6c..c329ab6 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.'); + } }); }; -- GitLab