forked from Outburn-IL/IL-DGMC-IG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validateExamples.js
54 lines (49 loc) · 1.94 KB
/
validateExamples.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
import {
getJreBin,
getValidatorPath,
getExamplesFolder,
readSushiConfig,
getFshOutputFolder,
getDependencies,
getValidationOutputPath,
readValidationResults,
extractErrorSummary
} from "./utils.js";
import { execa } from 'execa';
const examplesFolder = getExamplesFolder();
const igFolder = getFshOutputFolder();
const java = getJreBin();
const jar = getValidatorPath();
const sushiConfig = readSushiConfig();
const outputPathJson = getValidationOutputPath() + '.ex.json'
const outputPathHtml = getValidationOutputPath() + '.ex.html'
const getFhirVersion = () => {
return sushiConfig?.fhirVersion;
};
const readResults = async () => {
const results = readValidationResults(outputPathJson);
const errorSummary = await extractErrorSummary(results);
return errorSummary;
}
const runValidate = async () => {
if (java && jar) {
const command = `"${java}" -Dfile.encoding=UTF-8 -jar "${jar}" "${examplesFolder}" -version ${getFhirVersion()} -jurisdiction global -ig "${igFolder}" ${getDependencies(sushiConfig)} -output ${outputPathJson} -html-output ${outputPathHtml}`;
const subprocess = execa(command);
subprocess.stdout.pipe(process.stdout);
await subprocess;
const errors = await readResults();
const message = `Finished validating examples. Found ${(errors.fatal ?? 0) + (errors.error ?? 0)} errors (${errors.fatal ?? 0} fatal) and ${errors.warning ?? 0} warnings`;
console.log(message)
if (errors?.error || errors?.fatal) {
throw new Error(`Validation failed! See detailed results in: ${outputPathHtml}`)
} else if (errors?.warning) {
console.log(`Validation finished with warnings. Please see detailed results in: ${outputPathHtml}`)
} else {
console.log('Successful validation!')
}
return true
} else {
throw new Error('Failed to find JRE :(')
}
};
runValidate();