UNPKG

locadot

Version:

Secure your local development environment with HTTPS and custom domains like dev.localhost.

129 lines (128 loc) 4.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const localhost_1 = __importDefault(require("./localhost")); const proxy_1 = __importDefault(require("../proxy")); const locadot_file_1 = __importDefault(require("./locadot-file")); const constants_1 = __importDefault(require("../constants")); const startup_1 = __importDefault(require("../utils/startup")); class Commands { static async add(argv) { if (!localhost_1.default.isValidLocalhostDomain(argv.host)) { console.error(constants_1.default.proxyInfo.invalidHost); process.exit(1); } if (await localhost_1.default.isLocalhostOpen(argv.host, argv.port)) { console.error(constants_1.default.proxyInfo.hostExist); process.exit(1); } try { await proxy_1.default.addProxy(argv.host, argv.port); } catch (error) { console.error(error); } } static async remove(argv) { if (!localhost_1.default.isValidLocalhostDomain(argv.host)) { console.error(constants_1.default.proxyInfo.invalidHost); process.exit(1); } try { await proxy_1.default.removeProxy(argv.host); } catch (error) { console.error(error); } } static async update(argv) { if (!localhost_1.default.isValidLocalhostDomain(argv.host)) { console.error(constants_1.default.proxyInfo.invalidHost); process.exit(1); } if (!(await localhost_1.default.isLocalhostOpen(argv.host, argv.port))) { console.error(constants_1.default.proxyInfo.hostNotFound); process.exit(1); } try { await proxy_1.default.updateProxy(argv.host, argv.port); } catch (error) { console.error(error); } } static async stop() { try { await proxy_1.default.stopProxy(); } catch (error) { } } static async clearHosts() { try { await locadot_file_1.default.removeAllRegistry(); } catch (error) { } } static async kill() { try { await proxy_1.default.killProxy(); } catch (error) { } } static async restart() { await proxy_1.default.restartProxy(); console.log("☑️ Proxy successfully restarted."); } static async getRegistry() { try { const registry = await locadot_file_1.default.getRegistry(); Object.entries(registry).forEach(([value, key]) => console.log(`Port: ${key} => ${value} \n`)); console.log(`☑️ Total: ${Object.keys(registry).length}.`); } catch (error) { } } static watchLogs() { try { locadot_file_1.default.watchLogs(); } catch (error) { } } static async clearLogs() { try { await locadot_file_1.default.clearLogs(); console.log("☑️ Logs successfully cleared."); } catch (error) { } } static async logPath() { console.log(constants_1.default.paths.LOGS); } static async hostPath() { console.log(constants_1.default.paths.REGISTRY_FILE); } static async configPath() { console.log(constants_1.default.paths.REGISTRY_FILE); console.log(constants_1.default.paths.LOGS); } static async enableStartup() { try { await startup_1.default.enable(); } catch (error) { } } static async disableStartup() { try { await startup_1.default.disable(); } catch (error) { } } static async statusStartup() { try { await startup_1.default.status(); } catch (error) { } } } exports.default = Commands;