forked from Language-Research-Technology/ldac-profile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldac-check.js
executable file
·43 lines (38 loc) · 1.13 KB
/
ldac-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env node
/**
* A CLI that uses the ldac profile validator to check an RO-Crate metadata document.
*/
const { program } = require('commander');
const fs = require('fs');
const path = require('path');
const { ROCrate } = require('ro-crate');
const { LdacProfile } = require('./index.js');
const { version } = require('./package.json');
program
.showHelpAfterError()
.description(
'Checks an RO-Crate metadata document; a (ro-crate-metadata.json) file'
)
.version(version)
.argument('<path>', 'Path to the RO-Crate metadata file')
.option('-e, --errors', 'Output errors only')
.action(main);
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);
} else {
console.log(result);
}
} catch (error) {
if (error.code === 'ENOENT') {
console.error(`Error: File not found - '${cratePath}'`);
} else {
console.error(error);
}
}
}