Skip to content
Snippets Groups Projects
Unverified Commit 24593da7 authored by Anjan Kaur's avatar Anjan Kaur Committed by GitHub
Browse files

Merge pull request #65 from robinvenneman/feature/57-suppress-schema-output

Feature/57 suppress schema output
parents 45bd5646 c40e2dc2
Branches
Tags
No related merge requests found
...@@ -32,7 +32,7 @@ var argv = require('optimist') ...@@ -32,7 +32,7 @@ var argv = require('optimist')
.alias('s', 'metaSchema') .alias('s', 'metaSchema')
.describe('s', 'Custom meta schema path to validate schemas') .describe('s', 'Custom meta schema path to validate schemas')
.alias('x', 'schema-out') .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') .alias('e', 'schema-extension')
.describe('e', 'JSON Schema file extension eg. schema.json or json') .describe('e', 'JSON Schema file extension eg. schema.json or json')
.alias('n', 'no-readme') .alias('n', 'no-readme')
...@@ -56,7 +56,7 @@ var schemaPathMap = {}; ...@@ -56,7 +56,7 @@ var schemaPathMap = {};
var metaElements = {}; var metaElements = {};
var schemaPath = path.resolve(argv.d); var schemaPath = path.resolve(argv.d);
var outDir = path.resolve(argv.o); 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); var target = fs.statSync(schemaPath);
const readme = argv.n !== true; const readme = argv.n !== true;
const schemaExtension = argv.e || 'schema.json'; const schemaExtension = argv.e || 'schema.json';
......
...@@ -388,13 +388,12 @@ Schema.setSchemaPathMap=function(schemaMap){ ...@@ -388,13 +388,12 @@ Schema.setSchemaPathMap=function(schemaMap){
* @param {*} schemaMap * @param {*} schemaMap
* @param {*} schemaPath * @param {*} schemaPath
* @param {string} docDir - where documentation will be generated * @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 {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 {boolean} readme - generate a README.md directory listing
* @param {map} docs - a map of documentation links for headers * @param {map} docs - a map of documentation links for headers
*/ */
Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme, docs) { Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme, docs) {
schemaDir = schemaDir ? schemaDir : docDir;
smap=schemaMap; smap=schemaMap;
let keys = Object.keys(schemaMap); let keys = Object.keys(schemaMap);
return Promise.mapSeries(keys, schemaKey => { return Promise.mapSeries(keys, schemaKey => {
...@@ -420,9 +419,11 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements ...@@ -420,9 +419,11 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements
return { mSchema:mSchema, wSchema:allSchema, dep:wmap }; return { mSchema:mSchema, wSchema:allSchema, dep:wmap };
}); });
}).then(object => { }).then(object => {
return Promise.all([ const outputTasks = [ markdownWriter(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep, docs) ];
markdownWriter(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep, docs), if (schemaDir !== '') {
schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir) ]); outputTasks.push(schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir));
}
return Promise.all(outputTasks);
}).catch(err => { }).catch(err => {
logger.error('Error occured in processing schema at path %s', sPath); logger.error('Error occured in processing schema at path %s', sPath);
logger.error(err); // should we exit here or allow processing of other schemas? logger.error(err); // should we exit here or allow processing of other schemas?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment