novu
Version:
Novu CLI. Run Novu Studio and sync workflows with Novu Cloud
45 lines (44 loc) • 1.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOnline = getOnline;
const child_process_1 = require("child_process");
const promises_1 = __importDefault(require("dns/promises"));
const url_1 = __importDefault(require("url"));
function getProxy() {
if (process.env.https_proxy) {
return process.env.https_proxy;
}
try {
const httpsProxy = (0, child_process_1.execSync)('npm config get https-proxy').toString().trim();
return httpsProxy !== 'null' ? httpsProxy : undefined;
}
catch (e) {
return;
}
}
async function getOnline() {
try {
await promises_1.default.lookup('registry.yarnpkg.com');
return true;
}
catch (_a) {
const proxy = getProxy();
if (!proxy) {
return false;
}
const { hostname } = url_1.default.parse(proxy);
if (!hostname) {
return false;
}
try {
await promises_1.default.lookup(hostname);
return true;
}
catch (_b) {
return false;
}
}
}