diff --git a/cli.js b/cli.js index 679ca00aabde3df3924e34835a595b56434f7a2a..a193fe05297ca36ec49acb40528614bf280a7335 100755 --- a/cli.js +++ b/cli.js @@ -32,7 +32,7 @@ var argv = require('optimist') .alias('s', 'metaSchema') .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') + .describe('x', 'output JSON Schema files including description and validated examples in the _new folder at output directory, or suppress with -') .alias('e', 'schema-extension') .describe('e', 'JSON Schema file extension eg. schema.json or json') .alias('n', 'no-readme') @@ -56,7 +56,7 @@ var schemaPathMap = {}; var metaElements = {}; var schemaPath = path.resolve(argv.d); var outDir = path.resolve(argv.o); -var schemaDir = argv.x ? path.resolve(argv.x) : outDir; +var schemaDir = argv.x === '-' ? '' : argv.x ? path.resolve(argv.x) : outDir; var target = fs.statSync(schemaPath); const readme = argv.n !== true; const schemaExtension = argv.e || 'schema.json'; diff --git a/lib/schema.js b/lib/schema.js index 90c7219b6a70abd88f097fa492b7e7457924d5d6..a17a3ecb3e59542debc243c6e55d47ca4f07a1f2 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -388,13 +388,12 @@ Schema.setSchemaPathMap=function(schemaMap){ * @param {*} schemaMap * @param {*} schemaPath * @param {string} docDir - where documentation will be generated - * @param {string} schemaDir - where schemas will be generated, if null, `docDir` will be used + * @param {string} schemaDir - where schemas will be generated, if not set, no schema's will be output * @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 * @param {map} docs - a map of documentation links for headers */ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme, docs) { - schemaDir = schemaDir ? schemaDir : docDir; smap=schemaMap; let keys = Object.keys(schemaMap); return Promise.mapSeries(keys, schemaKey => { @@ -420,9 +419,11 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements return { mSchema:mSchema, wSchema:allSchema, dep:wmap }; }); }).then(object => { - return Promise.all([ - markdownWriter(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep, docs), - schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir) ]); + const outputTasks = [ markdownWriter(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep, docs) ]; + if (schemaDir !== '') { + outputTasks.push(schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir)); + } + return Promise.all(outputTasks); }).catch(err => { logger.error('Error occured in processing schema at path %s', sPath); logger.error(err); // should we exit here or allow processing of other schemas?