-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
69 lines (57 loc) · 2.02 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Packages
const fs = require('fs');
// const path = require('path');
const chalk = require('chalk');
const config = require('./config');
// Application code
const validator = require('./validator/schematron-validator');
const server = require('./server');
const example = fs.readFileSync('./test/example.xml', 'utf-8');
// Configuration
const basePath = config.basePath;
var schematronFile = '';
// check for schematron
if (!fs.existsSync(config.schematronPath)){
console.log(chalk.red('ERROR:') + ' you need to have schematron as listed in config');
return '';
}
else {
schematronFile = fs.readFileSync(config.schematronPath, 'utf-8');
console.log(schematronFile.length + ' schematron length check');
}
// check for voc.xml
if (!fs.existsSync(config.vocPath)){
console.log(chalk.red('ERROR:') + ' you need to have voc.xml as listed in config');
return '';
}
// check for repos folder
if (!fs.existsSync('./repos')){
console.log(chalk.red('ERROR:') + ' you need to have creates repos directory in main project folder');
return '';
}
// check for GitHub repo. If exists, pull then start server
if (!fs.existsSync(basePath)){
console.log(chalk.red('ERROR:') + ' you need to have cloned https://github.com/HL7/C-CDA-Examples to repos folder');
return '';
}
// Gets all XML paths from files in repository
const checkStatus = () => {
console.log('checking that validation passes on example file');
var results = validator(example, schematronFile);
if (!results || !results.schema || !results.schema.pass) {
console.log(chalk.red('ERROR:') + ' the sample schema validation did not pass. Check environment.');
return '';
}
else if (!results || !results.schematron || results.schematron.errorCount !== 0){
console.log(chalk.red('ERROR:') + ' the sample schematron validation did not pass. Check environment.');
return '';
}
else {
console.log(chalk.green('Sample XML validation returned no errors!'));
startServer();
}
};
const startServer = () => {
server(config, schematronFile);
};
checkStatus();