2015-04-01 19:56:08 +00:00
|
|
|
var path = require("path");
|
|
|
|
var fs = require("fs");
|
2018-02-27 17:36:02 +00:00
|
|
|
var url = require("url");
|
2015-04-01 19:56:08 +00:00
|
|
|
|
|
|
|
// We want to load Readability and JSDOMParser, which aren't set up as commonjs libraries,
|
|
|
|
// and so we need to do some hocus-pocus with 'vm' to import them on a separate scope
|
|
|
|
// (identical) scope context.
|
|
|
|
var vm = require("vm");
|
|
|
|
var readabilityPath = path.join(__dirname, "Readability.js");
|
|
|
|
var jsdomPath = path.join(__dirname, "JSDOMParser.js");
|
|
|
|
|
|
|
|
|
|
|
|
var scopeContext = {};
|
|
|
|
// We generally expect dump() and console.{whatever} to work, so make these available
|
|
|
|
// in the scope we're using:
|
2016-07-19 20:44:27 +00:00
|
|
|
scopeContext.dump = console.log;
|
2015-04-01 19:56:08 +00:00
|
|
|
scopeContext.console = console;
|
2018-02-27 17:36:02 +00:00
|
|
|
scopeContext.URL = url.URL;
|
2015-04-01 19:56:08 +00:00
|
|
|
|
|
|
|
// Actually load files. NB: if either of the files has parse errors,
|
|
|
|
// node is dumb and shows you a syntax error *at this callsite* . Don't try to find
|
|
|
|
// a syntax error on this line, there isn't one. Go look in the file it's loading instead.
|
|
|
|
vm.runInNewContext(fs.readFileSync(jsdomPath), scopeContext, jsdomPath);
|
|
|
|
vm.runInNewContext(fs.readFileSync(readabilityPath), scopeContext, readabilityPath);
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Readability: scopeContext.Readability,
|
|
|
|
JSDOMParser: scopeContext.JSDOMParser
|
|
|
|
};
|