UNPKG

@ordino.ai/cli

Version:
314 lines (313 loc) • 15.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkCypressFiles = checkCypressFiles; exports.checkNodeVersion = checkNodeVersion; exports.checkNodeVersionOnly = checkNodeVersionOnly; exports.checkNpmVersion = checkNpmVersion; exports.checkNpmVersionOnly = checkNpmVersionOnly; exports.checkPlaywrightBrowsers = checkPlaywrightBrowsers; exports.checkPlaywrightFiles = checkPlaywrightFiles; exports.displayVersionCheck = displayVersionCheck; var _child_process = require("child_process"); var _printMessage = require("./printMessage.util"); var _versionRequirements = require("../config/version-requirements"); var _fs = _interopRequireDefault(require("fs")); var _path = _interopRequireDefault(require("path")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function parseVersion(versionString) { var match = versionString.match(/^v?(\d+)\.(\d+)\.(\d+)/); if (!match) { throw new Error("Invalid version format: ".concat(versionString)); } return { major: parseInt(match[1], 10), minor: parseInt(match[2], 10), patch: parseInt(match[3], 10) }; } function compareVersions(required, actual) { if (actual.major > required.major) return true; if (actual.major < required.major) return false; if (actual.minor > required.minor) return true; if (actual.minor < required.minor) return false; return actual.patch >= required.patch; } function getNodeVersion() { try { var nodeVersion = (0, _child_process.execSync)("node --version", { encoding: "utf8" }).trim(); return parseVersion(nodeVersion); } catch (error) { throw new Error("Failed to get Node.js version. Please ensure Node.js is installed and accessible."); } } function getNpmVersion() { try { var npmVersion = (0, _child_process.execSync)("npm --version", { encoding: "utf8" }).trim(); return parseVersion(npmVersion); } catch (error) { throw new Error("Failed to get npm version. Please ensure npm is installed and accessible."); } } function checkNodeVersion() { var requiredVersions = (0, _versionRequirements.getVersionRequirements)(); var result = { compatible: false, version: { major: 0, minor: 0, patch: 0 } }; try { result.version = getNodeVersion(); result.compatible = compareVersions(requiredVersions.node, result.version); } catch (error) { result.error = error instanceof Error ? error.message : "Unknown error checking Node.js version"; } return result; } function checkNpmVersion() { var requiredVersions = (0, _versionRequirements.getVersionRequirements)(); var result = { compatible: false, version: { major: 0, minor: 0, patch: 0 } }; try { result.version = getNpmVersion(); result.compatible = compareVersions(requiredVersions.npm, result.version); } catch (error) { result.error = error instanceof Error ? error.message : "Unknown error checking npm version"; } return result; } function checkNodeVersionOnly() { var nodeCheck = checkNodeVersion(); var requiredVersionsStrings = (0, _versionRequirements.getVersionRequirementsAsStrings)(); (0, _printMessage.printMessage)("\nšŸ” Checking Node.js version...", "36", true); (0, _printMessage.printMessage)("Current: ".concat(nodeCheck.version.major, ".").concat(nodeCheck.version.minor, ".").concat(nodeCheck.version.patch), nodeCheck.compatible ? "32" : "31", false); (0, _printMessage.printMessage)("Required: ".concat(requiredVersionsStrings.node), "33", false); if (nodeCheck.error) { (0, _printMessage.printMessage)("\u274C Error checking Node.js version: ".concat(nodeCheck.error), "31", true); return false; } if (nodeCheck.compatible) { (0, _printMessage.printMessage)("āœ… Node.js version is compatible!", "32", true); return true; } else { (0, _printMessage.printMessage)("āŒ Node.js version is not compatible:", "31", true); (0, _printMessage.printMessage)(" • Download from: https://nodejs.org/", "36", false); (0, _printMessage.printMessage)(" • Or use Node Version Manager (nvm):", "36", false); (0, _printMessage.printMessage)(" - Windows: nvm install latest", "36", false); (0, _printMessage.printMessage)(" - macOS/Linux: nvm install node", "36", false); (0, _printMessage.printMessage)(" • Or use package manager:", "36", false); (0, _printMessage.printMessage)(" - Windows (Chocolatey): choco install nodejs", "36", false); (0, _printMessage.printMessage)(" - macOS (Homebrew): brew install node", "36", false); (0, _printMessage.printMessage)(" - Linux (apt): sudo apt update && sudo apt install nodejs", "36", false); return false; } } function checkNpmVersionOnly() { var npmCheck = checkNpmVersion(); var requiredVersionsStrings = (0, _versionRequirements.getVersionRequirementsAsStrings)(); (0, _printMessage.printMessage)("\nšŸ” Checking npm version...", "36", true); (0, _printMessage.printMessage)("Current: ".concat(npmCheck.version.major, ".").concat(npmCheck.version.minor, ".").concat(npmCheck.version.patch), npmCheck.compatible ? "32" : "31", false); (0, _printMessage.printMessage)("Required: ".concat(requiredVersionsStrings.npm), "33", false); if (npmCheck.error) { (0, _printMessage.printMessage)("\u274C Error checking npm version: ".concat(npmCheck.error), "31", true); return false; } if (npmCheck.compatible) { (0, _printMessage.printMessage)("āœ… npm version is compatible!", "32", true); return true; } else { (0, _printMessage.printMessage)("āŒ npm version is not compatible:", "31", true); (0, _printMessage.printMessage)(" • Update npm globally: npm install -g npm@latest", "36", false); (0, _printMessage.printMessage)(" • Or use Node Version Manager (nvm):", "36", false); (0, _printMessage.printMessage)(" - nvm install-latest-npm", "36", false); (0, _printMessage.printMessage)(" • Or reinstall Node.js (includes latest npm):", "36", false); (0, _printMessage.printMessage)(" - Download from: https://nodejs.org/", "36", false); return false; } } function displayVersionCheck() { var nodeCompatible = checkNodeVersionOnly(); var npmCompatible = checkNpmVersionOnly(); return nodeCompatible && npmCompatible; } function checkConfigFile() { var currentDir = process.cwd(); var configPath = _path["default"].join(currentDir, "ordino.config.ts"); var configExists = _fs["default"].existsSync(configPath); (0, _printMessage.printMessage)("ordino.config.ts: ".concat(configExists ? "āœ… Found" : "āŒ Not found"), configExists ? "32" : "31", false); return configExists; } function checkInitializeFile() { var currentDir = process.cwd(); var initializePath = _path["default"].join(currentDir, "ordino.initialize.js"); var initializeExists = _fs["default"].existsSync(initializePath); (0, _printMessage.printMessage)("ordino.initialize.js: ".concat(initializeExists ? "āœ… Found" : "āŒ Not found"), initializeExists ? "32" : "31", false); return initializeExists; } function parsePlaywrightDryRunOutput(output) { var browsers = []; var lines = output.split('\n'); var currentBrowser = {}; var _iterator = _createForOfIteratorHelper(lines), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var line = _step.value; var trimmedLine = line.trim(); var browserMatch = trimmedLine.match(/^browser:\s+(\S+)/); if (browserMatch) { if (currentBrowser.name && currentBrowser.installLocation) { browsers.push(currentBrowser); } currentBrowser = { name: browserMatch[1] }; continue; } var locationMatch = trimmedLine.match(/^Install location:\s+(.+)/); if (locationMatch && currentBrowser.name) { currentBrowser.installLocation = locationMatch[1].trim(); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } if (currentBrowser.name && currentBrowser.installLocation) { browsers.push(currentBrowser); } return browsers; } function extractBrowserVersionFromPath(installLocation) { var match = installLocation.match(/[\\\/]([^\\\/]+)-(\d+)$/); if (match) { return match[2]; } return null; } function checkPlaywrightBrowsers(cwd) { var showInstallInstructions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; try { var playwrightVersion = (0, _child_process.execSync)("npx playwright --version", { encoding: "utf8", stdio: "pipe", timeout: 10000, cwd: cwd }).trim(); var dryRunOutput = (0, _child_process.execSync)("npx playwright install --dry-run", { encoding: "utf8", stdio: "pipe", timeout: 15000, cwd: cwd }); var browsers = parsePlaywrightDryRunOutput(dryRunOutput); var platform = process.platform; var playwrightDir = ''; if (platform === 'win32') { var userHome = process.env.USERPROFILE || ''; playwrightDir = _path["default"].join(userHome, 'AppData', 'Local', 'ms-playwright'); } else if (platform === 'darwin') { var _userHome = process.env.HOME || ''; playwrightDir = _path["default"].join(_userHome, 'Library', 'Caches', 'ms-playwright'); } else if (platform === 'linux') { var _userHome2 = process.env.HOME || ''; playwrightDir = _path["default"].join(_userHome2, '.cache', 'ms-playwright'); } else { (0, _printMessage.printMessage)("Playwright browser binaries: \u274C Not installed (".concat(playwrightVersion, ") - Unsupported platform"), "31", false); return false; } if (!_fs["default"].existsSync(playwrightDir)) { (0, _printMessage.printMessage)("Playwright browser binaries: \u274C Not installed (".concat(playwrightVersion, ")"), "31", false); if (showInstallInstructions) { (0, _printMessage.printMessage)(" • Installation required: Navigate to your project folder and run 'npx playwright install'", "36", false); (0, _printMessage.printMessage)(" • After installation: Run 'ordino init' again to continue setup", "36", false); } return false; } var chromiumRelatedBrowsers = browsers.filter(function (browser) { return browser.name === 'chromium' || browser.name === 'chrome' || browser.name === 'msedge' || browser.name.includes('chromium'); }); if (chromiumRelatedBrowsers.length === 0) { (0, _printMessage.printMessage)("Playwright browser binaries: \u274C No chromium-related browsers found in dry-run (".concat(playwrightVersion, ")"), "31", false); if (showInstallInstructions) { (0, _printMessage.printMessage)(" • Installation required: Navigate to your project folder and run 'npx playwright install chromium'", "36", false); (0, _printMessage.printMessage)(" • After installation: Run 'ordino init' again to continue setup", "36", false); } return false; } var missingBrowsers = []; var availableBrowsers = []; chromiumRelatedBrowsers.forEach(function (browser) { if (_fs["default"].existsSync(browser.installLocation)) { var version = extractBrowserVersionFromPath(browser.installLocation); var browserVersion = version ? "".concat(browser.name, "-").concat(version) : browser.name; availableBrowsers.push(browserVersion); } else { missingBrowsers.push(browser.name); } }); if (missingBrowsers.length > 0) { (0, _printMessage.printMessage)("Playwright browser binaries: \u274C Some chromium-related binaries missing (".concat(playwrightVersion, ")"), "31", false); (0, _printMessage.printMessage)(" \u2022 Missing: ".concat(missingBrowsers.join(', ')), "31", false); if (availableBrowsers.length > 0) { (0, _printMessage.printMessage)(" \u2022 Available: ".concat(availableBrowsers.join(', ')), "36", false); } if (showInstallInstructions) { (0, _printMessage.printMessage)(" • Installation required: Navigate to your project folder and run 'npx playwright install'", "36", false); (0, _printMessage.printMessage)(" • After installation: Run 'ordino init' again to continue setup", "36", false); } return false; } (0, _printMessage.printMessage)("Playwright browser binaries: \u2705 All chromium-related browsers installed (".concat(playwrightVersion, ")"), "32", false); availableBrowsers.forEach(function (browserVersion) { (0, _printMessage.printMessage)(" \u2022 Found: ".concat(browserVersion), "36", false); }); return true; } catch (error) { (0, _printMessage.printMessage)("Playwright browser binaries: āŒ Not installed", "31", false); if (showInstallInstructions) { (0, _printMessage.printMessage)(" • Installation required: Navigate to your project folder and run 'npx playwright install'", "36", false); (0, _printMessage.printMessage)(" • After installation: Run 'ordino init' again to continue setup", "36", false); } return false; } } function checkCypressFiles() { (0, _printMessage.printMessage)("\nšŸ” Checking Cypress configuration files...", "36", true); var configExists = checkConfigFile(); var initializeExists = checkInitializeFile(); if (configExists && initializeExists) { (0, _printMessage.printMessage)("āœ… All Cypress configuration files are present!", "32", true); return true; } return false; } function checkPlaywrightFiles() { (0, _printMessage.printMessage)("\nšŸ” Checking Playwright configuration files...", "36", true); var configExists = checkConfigFile(); var initializeExists = checkInitializeFile(); var browsersInstalled = checkPlaywrightBrowsers(undefined, false); if (configExists && initializeExists && browsersInstalled) { (0, _printMessage.printMessage)("āœ… All Playwright configuration files and browsers are present!", "32", true); return true; } return false; }