From 00e5e1ce2df6eb07fd6782ff03dada20e173fb1b Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Fri, 10 May 2024 15:06:56 +1000 Subject: [PATCH 1/2] Added stringify to the output so that long lists of problems don't get abbreviated --- ldac-check.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ldac-check.js b/ldac-check.js index aea79bc..f78cdc2 100755 --- a/ldac-check.js +++ b/ldac-check.js @@ -22,15 +22,16 @@ program program.parse(process.argv); + function main(cratePath, options) { try { const opt = { alwaysAsArray: true, link: true }; const crate = new ROCrate(JSON.parse(fs.readFileSync(cratePath, 'utf8')), opt); var result = LdacProfile.validate(crate); if (options.errors) { - console.log(result.errors); + console.log(JSON.stringify(result.errors, null, 4)); } else { - console.log(result); + console.log(JSON.stringify(result, null, 4)); } } catch (error) { if (error.code === 'ENOENT') { From c0dc27d5b5d58543d77c80fb89943be6bc9f6d0f Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Fri, 10 May 2024 15:36:25 +1000 Subject: [PATCH 2/2] Added option to collate output by the error/warning etc --- ldac-check.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/ldac-check.js b/ldac-check.js index f78cdc2..92d4f61 100755 --- a/ldac-check.js +++ b/ldac-check.js @@ -17,21 +17,46 @@ program .version(version) .argument('', 'Path to the RO-Crate metadata file') .option('-e, --errors', 'Output errors only') + .option('-c, --collate', 'Collate errors and warnings') .action(main); program.parse(process.argv); +function collate(result) { + const collated = {}; + for( const k in result ) { + collated[k] = {}; + result[k].map((o) => { + if( !(o.clause in collated[k]) ) { + collated[k][o.clause] = []; + } + collated[k][o.clause].push(o.entity); + }); + for( const clause in collated[k] ) { + collated[k][clause].sort(); + } + } + return collated; +} + + +function print_results(result) { + console.log(JSON.stringify(result, null, 4)); +} + + function main(cratePath, options) { try { const opt = { alwaysAsArray: true, link: true }; const crate = new ROCrate(JSON.parse(fs.readFileSync(cratePath, 'utf8')), opt); - var result = LdacProfile.validate(crate); - if (options.errors) { - console.log(JSON.stringify(result.errors, null, 4)); + const result = LdacProfile.validate(crate); + if (options.collate) { + const collated = collate(result); + print_results(options.errors ? collated.errors : collated); } else { - console.log(JSON.stringify(result, null, 4)); + print_results(options.errors ? result.errors : result) } } catch (error) { if (error.code === 'ENOENT') {