access-sniff
Version:
A node/iojs library & CLI for HTML_Codesniffer
67 lines (49 loc) • 1.7 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _oldApi = require('jsdom/lib/old-api');
var _oldApi2 = _interopRequireDefault(_oldApi);
var _bluebird = require('bluebird');
var _bluebird2 = _interopRequireDefault(_bluebird);
var _validator = require('validator');
var _validator2 = _interopRequireDefault(_validator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var scriptPath = _path2.default.join(__dirname, '../HTMLCS.min.js');
var RunJsDomInstance = function RunJsDomInstance(file, accessibilityLevel) {
return new _bluebird2.default(function (resolve, reject) {
var messages = [];
var vConsole = _oldApi2.default.createVirtualConsole();
var jsDomOptions = {
scripts: [scriptPath],
virtualConsole: vConsole,
done: function done(err, window) {
if (err) {
reject(err);
}
window.HTMLCS_RUNNER.run(accessibilityLevel);
}
};
if (_validator2.default.isURL(file)) {
reject('JsDom Cannot render urls, please set the browser option to true');
} else if (_fs2.default.existsSync(file)) {
jsDomOptions.file = file;
} else {
jsDomOptions.html = file;
}
vConsole.on('log', function (message) {
if (message === 'done') {
resolve(messages);
} else {
messages.push([accessibilityLevel, message]);
}
});
_oldApi2.default.env(jsDomOptions);
});
};
exports.default = RunJsDomInstance;
;