UNPKG

1.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.xmlLint = void 0;
4const path_1 = require("path");
5const child_process_1 = require("child_process");
6const errors_1 = require("./errors");
7/**
8 * Verify the passed in xml is valid. Requires xmllib be installed
9 * @param xml what you want validated
10 * @return {Promise<void>} resolves on valid rejects [error stderr]
11 */
12function xmlLint(xml) {
13 const args = [
14 '--schema',
15 path_1.resolve(__dirname, '..', '..', 'schema', 'all.xsd'),
16 '--noout',
17 '-',
18 ];
19 if (typeof xml === 'string') {
20 args[args.length - 1] = xml;
21 }
22 return new Promise((resolve, reject) => {
23 child_process_1.execFile('which', ['xmllint'], (error, stdout, stderr) => {
24 if (error) {
25 reject([new errors_1.XMLLintUnavailable()]);
26 return;
27 }
28 const xmllint = child_process_1.execFile('xmllint', args, (error, stdout, stderr) => {
29 if (error) {
30 reject([error, stderr]);
31 }
32 resolve();
33 });
34 if (xmllint.stdout) {
35 xmllint.stdout.unpipe();
36 if (typeof xml !== 'string' && xml && xmllint.stdin) {
37 xml.pipe(xmllint.stdin);
38 }
39 }
40 });
41 });
42}
43exports.xmlLint = xmlLint;