@@ -16,17 +16,23 @@ const avrodocDebug = debug("avrodoc:avrodoc");
1616 * @param {Array<string> } inputfiles an array with resolved filenames to be read and parsed and eventually added to the avrodoc
1717 * @param {string } outputfile the html file that should be written
1818 */
19- async function createAvroDoc ( extra_less_files , inputfiles , outputfile ) {
19+ async function createAvroDoc (
20+ extra_less_files ,
21+ inputfiles ,
22+ outputfile ,
23+ ignoreInvalid
24+ ) {
2025 avrodocDebug ( `Creating ${ outputfile } from ` , inputfiles ) ;
21- let schemata = inputfiles . map ( function ( filename ) {
22- return {
23- json : readJSON ( filename ) ,
24- filename : filename ,
25- } ;
26- } ) ;
26+ let schemata = inputfiles
27+ . map ( ( filename ) => {
28+ const json = readJSON ( filename , ignoreInvalid ) ;
29+ return json != null ? { json, filename } : null ;
30+ } )
31+ . filter ( ( s ) => s != null ) ;
32+
2733 const html = await topLevelHTML ( extra_less_files , {
2834 inline : true ,
29- schemata : schemata ,
35+ schemata,
3036 } ) ;
3137 return await writeAvroDoc ( outputfile , html ) ;
3238}
@@ -50,16 +56,20 @@ async function writeAvroDoc(output, html) {
5056/**
5157 * Reads in the given file and parses as json
5258 * @param {string } filename to be read
59+ * @param {boolean } ignoreInvalid should we ignore invalid JSON files
5360 * @returns {object } with parsed AVRO
5461 */
55- function readJSON ( filename ) {
62+ function readJSON ( filename , ignoreInvalid ) {
5663 let json , parsed ;
5764 avrodocDebug ( "Parsing " , filename ) ;
5865 json = fs . readFileSync ( path . resolve ( process . cwd ( ) , filename ) , "utf-8" ) ;
5966 try {
6067 parsed = JSON . parse ( json ) ;
6168 } catch ( e ) {
62- console . error ( "Not a valid json file: " + filename ) ;
69+ console . error ( "Not a valid JSON file: " + filename ) ;
70+ if ( ignoreInvalid ) {
71+ return ;
72+ }
6373 process . exit ( 1 ) ;
6474 }
6575 return parsed ;
0 commit comments