-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalidate-document-definitions
executable file
·42 lines (29 loc) · 1.31 KB
/
validate-document-definitions
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
const commander = require('./lib/commander/index');
const docDefinitionsLoader = require('./src/loading/document-definitions-loader');
const docDefinitionsValidator = require('./src/validation/document-definitions-validator');
const errorStatus = 1;
const { version } = require('./package');
// Parse the commandline arguments
commander.arguments('<document_definitions_file>')
.version(version, '-v, --version')
.description('A utility for validating the structure and semantics of a synctos document definitions file.');
commander.on('--help', () => {
// Add some extra information after the main body of the usage/help text
console.info(`
For example: ${commander.name()} /path/to/my-doc-definitions.js
See the README for more information.`);
});
commander.parse(process.argv);
if (commander.args.length !== 1) {
commander.outputHelp();
process.exit(errorStatus);
}
const docDefinitionsFilename = commander.args[0];
const rawDocDefinitionsString = docDefinitionsLoader.load(docDefinitionsFilename);
const validationErrors = docDefinitionsValidator.validate(rawDocDefinitionsString, docDefinitionsFilename);
validationErrors.forEach((validationError) => {
console.error(validationError);
});
const exitStatus = (validationErrors.length > 0) ? errorStatus : 0;
process.exit(exitStatus);