greenlock-express.js/lib/compat.js

38 lines
819 B
JavaScript
Raw Normal View History

2019-06-03 09:47:07 +00:00
"use strict";
2019-06-03 09:34:52 +00:00
function requireBluebird() {
2019-06-03 09:47:07 +00:00
try {
return require("bluebird");
} catch (e) {
console.error("");
console.error("DON'T PANIC. You're running an old version of node with incomplete Promise support.");
console.error("EASY FIX: `npm install --save bluebird`");
console.error("");
throw e;
}
2019-06-03 09:34:52 +00:00
}
2019-06-03 09:47:07 +00:00
if ("undefined" === typeof Promise) {
global.Promise = requireBluebird();
2019-06-03 09:34:52 +00:00
}
2019-06-03 09:47:07 +00:00
if ("function" !== typeof require("util").promisify) {
require("util").promisify = requireBluebird().promisify;
2019-06-03 09:34:52 +00:00
}
if (!console.debug) {
2019-06-03 09:47:07 +00:00
console.debug = console.log;
2019-06-03 09:34:52 +00:00
}
2019-06-03 09:47:07 +00:00
var fs = require("fs");
2019-06-03 09:34:52 +00:00
var fsAsync = {};
2019-06-03 09:47:07 +00:00
Object.keys(fs).forEach(function(key) {
var fn = fs[key];
if ("function" !== typeof fn || !/[a-z]/.test(key[0])) {
return;
}
fsAsync[key] = require("util").promisify(fn);
2019-06-03 09:34:52 +00:00
});
exports.fsAsync = fsAsync;