Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(function() {
if (argv.inputfile) {
// read input from the file, then process
return fs.readFile(argv.inputfile, 'utf8');
}
// Send a message to stderr if there is no input for a while, since the
// convention that --pageName must be used with
var fetch = Promise.async(function *(page, revid, opts) {
var prefix = opts.prefix || null;
var domain = opts.domain || null;
if (!prefix && !domain) {
domain = "en.wikipedia.org";
}
var parsoidOptions = {};
if (ScriptUtils.booleanOption(opts.config)) {
var p = (typeof (opts.config) === 'string') ?
path.resolve('.', opts.config) :
path.resolve(__dirname, '../config.yaml');
// Assuming Parsoid is the first service in the list
parsoidOptions = yaml.load(yield fs.readFile(p, 'utf8')).services[0].conf;
}
ScriptUtils.setTemplatingAndProcessingFlags(parsoidOptions, opts);
ScriptUtils.setDebuggingFlags(parsoidOptions, opts);
if (parsoidOptions.localsettings) {
parsoidOptions.localsettings = path.resolve(__dirname, parsoidOptions.localsettings);
}
var pc = new ParsoidConfig(null, parsoidOptions);
if (!prefix) {
// domain has been provided
prefix = pc.getPrefixFor(domain);
} else if (!domain) {
// prefix has been set
domain = pc.mwApiMap.get(prefix).domain;
} else if (!(prefix || domain)) {
domain = 'en.wikipedia.org';
}
var parsoidOptions = {
linting: argv.linting,
loadWMF: argv.loadWMF,
useWorker: argv.useWorker,
};
if (ScriptUtils.booleanOption(argv.config)) {
var p = (typeof (argv.config) === 'string') ?
path.resolve('.', argv.config) :
path.resolve(__dirname, '../config.yaml');
// Assuming Parsoid is the first service in the list
parsoidOptions = yaml.load(yield fs.readFile(p, 'utf8')).services[0].conf;
}
ScriptUtils.setTemplatingAndProcessingFlags(parsoidOptions, argv);
ScriptUtils.setDebuggingFlags(parsoidOptions, argv);
// Offline shortcut
if (argv.offline) {
parsoidOptions.fetchConfig = false;
parsoidOptions.fetchTemplates = false;
parsoidOptions.fetchImageInfo = false;
parsoidOptions.usePHPPreProcessor = false;
parsoidOptions.expandExtensions = false;
}
if (parsoidOptions.localsettings) {
parsoidOptions.localsettings = path.resolve(__dirname, parsoidOptions.localsettings);
function compareSvg2Png(svg, png, expected, diff, done, msg) {
mkdirp.sync(path.dirname(png));
var ecb = function (err) {
console.log(err);
should(err).not.ok;
done();
};
fs.readFile(svg)
.then(svg2png)
.then(function (buffer) {
fs.writeFile(png, buffer)
.then(function () {
imageDiff({
actualImage: png,
expectedImage: expected,
diffImage: diff
}, function (err, imagesAreSame) {
should(err).not.ok;
should.ok(imagesAreSame, msg);
done();
});
})
.catch(ecb);
})
function readFixture(fixture) {
return fs.readFile(fixturePath(fixture));
}
it('should render output files properly', async () => {
await child_process.execFile(pathToExecutable, args).promise;
const contents = await fs.readFile(testOutputFile, 'utf8');
expect(contents).toEqual(outputFileContents);
});
return Promise.resolve().then(() => {
options = normalizeFromFileOptions(filename, options);
return fs.readFile(filename).then(buffer => {
return new JSDOM(buffer, options);
});
});
}
return Promise.resolve().then(() => {
options = normalizeFromFileOptions(filename, options);
return fs.readFile(filename).then(buffer => {
return new JSDOM(buffer, options);
});
});
}
var computeSHA1 = Promise.async(function *(targetName) {
var targetPath = path.join(testDir, targetName);
if (!(yield fs.exists(targetPath))) {
return "";
}
var contents = yield fs.readFile(targetPath);
return crypto.createHash('sha1').update(contents).digest('hex')
.toLowerCase();
});
return Promise.resolve().then(() => {
options = normalizeFromFileOptions(filename, options);
return fs.readFile(filename).then(buffer => {
return new JSDOM(buffer, options);
});
});
}