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
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,8 @@ var argv = require('optimist') ...@@ -33,6 +33,8 @@ var argv = require('optimist')
.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')
.alias('n', 'no-readme')
.describe('n', 'Do not generate a README.md file in the output directory')
.check(function(args) { .check(function(args) {
if (!fs.existsSync(args.input)) { if (!fs.existsSync(args.input)) {
throw 'Input file "' + args.input + '" does not exist!'; throw 'Input file "' + args.input + '" does not exist!';
...@@ -51,6 +53,7 @@ var schemaPath = path.resolve(argv.d); ...@@ -51,6 +53,7 @@ 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 ? path.resolve(argv.x) : outDir;
var target = fs.statSync(schemaPath); var target = fs.statSync(schemaPath);
const readme = argv.n !== true;
if (argv.s){ if (argv.s){
ajv.addMetaSchema(require(path.resolve(argv.s))); ajv.addMetaSchema(require(path.resolve(argv.s)));
...@@ -87,7 +90,7 @@ if (target.isDirectory()) { ...@@ -87,7 +90,7 @@ if (target.isDirectory()) {
return Promise.reduce(files, readSchemaFile, schemaPathMap) return Promise.reduce(files, readSchemaFile, schemaPathMap)
.then(schemaMap => { .then(schemaMap => {
logger.info('finished reading all *.schema.json files in %s, beginning processing….', schemaPath); 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(() => { .then(() => {
logger.info('Processing complete.'); logger.info('Processing complete.');
......
...@@ -390,8 +390,9 @@ Schema.setSchemaPathMap=function(schemaMap){ ...@@ -390,8 +390,9 @@ Schema.setSchemaPathMap=function(schemaMap){
* @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 null, `docDir` will be used
* @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
*/ */
Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements) { Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme) {
schemaDir = schemaDir ? schemaDir : docDir; schemaDir = schemaDir ? schemaDir : docDir;
smap=schemaMap; smap=schemaMap;
let keys = Object.keys(schemaMap); let keys = Object.keys(schemaMap);
...@@ -423,9 +424,13 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements ...@@ -423,9 +424,13 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements
schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir) ]); schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir) ]);
}); });
}).then(result => { }).then(result => {
console.log('Output processed. Trying to make a README.md now'); if (readme) {
const markdowns = result.map(r => { return r[0];}); console.log('Output processed. Trying to make a README.md now');
return readmeWriter(markdowns, schemaMap, docDir, schemaPath); 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