UNPKG

rex-server

Version:

Rex Server is a Node.js-based reverse proxy server available as an npm package. It allows you to handle HTTP and HTTPS traffic, route requests to upstream servers, and manage worker processes efficiently. With its CLI interface, Rex makes it easy to confi

29 lines (28 loc) 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const fs_1 = require("fs"); try { // Path to the `package.json` file const pkgJsonPath = path_1.default.resolve(__dirname, '../../', 'package.json'); // Read and parse `package.json` to get the current version const { version } = JSON.parse((0, fs_1.readFileSync)(pkgJsonPath).toString()); // Path to the `conf.ts` file (after compilation, it should be a `conf.js` file) const confPath = path_1.default.resolve(__dirname, '../../dist', 'conf', 'conf.js'); // Replace the version and executable command in `conf.js` file const jsCommand = `SPAWN_COMMAND : { cmd: "node", args: [path_1.default.resolve(__dirname,'..','index.js')] }`; let conf = (0, fs_1.readFileSync)(confPath).toString() .replace(/\b\d+\.\d+\.\d+\b/g, version) // Replaces the version number .replace(/SPAWN_COMMAND\s*:\s*\{\s*cmd\s*:\s*'ts-node',\s*args\s*:\s*\[\s*"-r",\s*".*?",\s*(path_1\.default\.resolve\([^)]*\)|path\.resolve\([^)]*\))\s*\]\s*\}/, jsCommand); // Replaces the TypeScript command with the JavaScript command // Write the updated content back to `conf.js` (0, fs_1.writeFileSync)(confPath, conf); } catch (error) { console.error("ERROR_WHILE_UPDATING_CONF_WITH_VERSION_&_COMMAND", error); }