@qualweb/cli
Version:
QualWeb evaluator command line interface
63 lines • 3.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addWcagTechniqueOptionsToCommand = addWcagTechniqueOptionsToCommand;
const node_fs_1 = __importDefault(require("node:fs"));
const commander_1 = require("commander");
const techniques_json_1 = __importDefault(require("@qualweb/wcag-techniques/lib/techniques.json"));
const types_1 = require("../types");
function wcagTechniquesListParseHelper(value, previousValue) {
if (!previousValue)
previousValue = { error: [], ok: [] };
const allWcagTechniques = Object.values(techniques_json_1.default);
if (/^QW-WCAG-T\d+$/i.exec(value)) {
value = value.toUpperCase();
const foundWcagTechnique = allWcagTechniques.find(rule => rule.code === value);
if (foundWcagTechnique) {
previousValue.ok.push(foundWcagTechnique.code);
}
else {
previousValue.error.push(value);
}
}
else {
value = value.toUpperCase();
const foundTechnique = allWcagTechniques.find(rule => rule.mapping === value);
if (foundTechnique) {
previousValue.ok.push(foundTechnique.code);
}
else if (node_fs_1.default.existsSync(value)) {
const fileContents = node_fs_1.default.readFileSync(value, 'utf8')
.split(/\r?\n/)
.map(line => line.trim())
.filter(line => line.length > 0);
return fileContents.reduce((prev, current) => wcagTechniquesListParseHelper(current, prev), previousValue);
}
else {
previousValue.error.push(value);
}
}
return previousValue;
}
function addWcagTechniqueOptionsToCommand(command) {
const wcagTechniqueIncludeOption = new commander_1.Option('--wcag-techniques <techniques...>', 'Which WCAG techniques to execute. Can be multiple. If a path to a FILE, it will be read as a newline-separated list of techniques.')
.argParser(wcagTechniquesListParseHelper)
.implies({ module: [types_1.ModuleOptionsEnum.WCAGTechniques] });
const wcagTechniqueExcludeOption = new commander_1.Option('--exclude-wcag <techniques...>', 'Which WCAG techniques to not execute. Can be multiple. If a path to a FILE, it will be read as a newline-separated list of techniques.')
.argParser(wcagTechniquesListParseHelper)
.implies({ module: [types_1.ModuleOptionsEnum.WCAGTechniques] });
const wcagTechniqueLevelOption = new commander_1.Option('--wcag-levels <levels...>', 'Which conformance levels to test for WCAG techniques. Will include all techniques that match the level. Can be multiple.')
.choices(Object.values(types_1.ConformanceLevelEnum))
.implies({ module: [types_1.ModuleOptionsEnum.WCAGTechniques] });
const wcagTechniquePrincipleOption = new commander_1.Option('--wcag-principles <principles...>', 'Which principles to test for in WCAG techniques. Only techniques matching the principle will be tested.')
.choices(Object.values(types_1.PrincipleEnum))
.implies({ module: [types_1.ModuleOptionsEnum.WCAGTechniques] });
command.addOption(wcagTechniqueIncludeOption);
command.addOption(wcagTechniqueExcludeOption);
command.addOption(wcagTechniqueLevelOption);
command.addOption(wcagTechniquePrincipleOption);
return command;
}
//# sourceMappingURL=wcagTechniques.js.map