UNPKG

@devicecloud.dev/dcd

Version:

Better cloud maestro testing

172 lines (171 loc) 5.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dividers = exports.colors = exports.symbols = void 0; exports.formatStatus = formatStatus; exports.sectionHeader = sectionHeader; exports.keyValue = keyValue; exports.listItem = listItem; exports.formatUrl = formatUrl; exports.formatId = formatId; exports.formatTestSummary = formatTestSummary; exports.box = box; exports.getConsoleUrl = getConsoleUrl; const chalk = require("chalk"); /** * Centralized styling utilities for CLI output * Provides consistent, developer-friendly visual formatting */ /** * Status symbols with associated colors */ exports.symbols = { cancelled: chalk.gray('⊘'), error: chalk.red('✗'), info: chalk.blue('ℹ'), pending: chalk.yellow('⏸'), queued: chalk.gray('⏳'), running: chalk.blue('▶'), success: chalk.green('✓'), unknown: chalk.gray('?'), warning: chalk.yellow('⚠'), }; /** * Color utility functions for semantic styling */ exports.colors = { bold: chalk.bold, dim: chalk.gray, error: chalk.red, highlight: chalk.cyan, info: chalk.blue, success: chalk.green, url: chalk.cyan.underline, warning: chalk.yellow, }; /** * Dividers for visual separation */ exports.dividers = { heavy: chalk.gray('═'.repeat(80)), light: chalk.gray('─'.repeat(80)), short: chalk.gray('─'.repeat(40)), }; /** * Format a status with appropriate symbol and color * @param status - The status string to format * @returns Formatted status string with color and symbol */ function formatStatus(status) { const statusUpper = status.toUpperCase(); switch (statusUpper) { case 'PASSED': { return `${exports.symbols.success} ${exports.colors.success(status)}`; } case 'FAILED': { return `${exports.symbols.error} ${exports.colors.error(status)}`; } case 'RUNNING': { return `${exports.symbols.running} ${exports.colors.info(status)}`; } case 'PENDING': { return `${exports.symbols.pending} ${exports.colors.warning(status)}`; } case 'QUEUED': { return `${exports.symbols.queued} ${exports.colors.dim(status)}`; } case 'CANCELLED': { return `${exports.symbols.cancelled} ${exports.colors.dim(status)}`; } default: { return `${exports.symbols.unknown} ${exports.colors.dim(status)}`; } } } /** * Format a section header * @param title - The title of the section * @returns Formatted section header */ function sectionHeader(title) { return `\n${exports.colors.bold(title)}\n${exports.dividers.light}`; } /** * Format a key-value pair with optional icon * @param icon - Icon to display before the key * @param key - The key name * @param value - The value to display * @returns Formatted key-value string */ function keyValue(icon, key, value) { return `${icon} ${exports.colors.dim(key + ':')} ${exports.colors.highlight(value)}`; } /** * Format a list item * @param text - The text of the list item * @param prefix - The prefix character (default: '•') * @returns Formatted list item */ function listItem(text, prefix = '•') { return `${exports.colors.dim(prefix)} ${text}`; } /** * Format a URL * @param url - The URL to format * @returns Formatted URL with styling */ function formatUrl(url) { return exports.colors.url(url); } /** * Format an ID or identifier * @param id - The ID to format * @returns Formatted ID with highlighting */ function formatId(id) { return exports.colors.highlight(id); } /** * Format a test summary line * @param summary - Object containing test counts * @returns Formatted summary string */ function formatTestSummary(summary) { const parts = [ chalk.bold(`${summary.completed}/${summary.total}`), exports.colors.success(`✓ ${summary.passed}`), exports.colors.error(`✗ ${summary.failed}`), exports.colors.info(`▶ ${summary.running}`), exports.colors.warning(`⏸ ${summary.pending}`), exports.colors.dim(`⏳ ${summary.queued}`), ]; return parts.join(' │ '); } /** * Format a box with content * @param content - The content to display in the box * @returns Formatted box with borders */ function box(content) { const lines = content.split('\n'); const maxLength = Math.max(...lines.map((l) => l.length)); const top = chalk.gray('┌' + '─'.repeat(maxLength + 2) + '┐'); const bottom = chalk.gray('└' + '─'.repeat(maxLength + 2) + '┘'); const middle = lines .map((line) => chalk.gray('│ ') + line.padEnd(maxLength) + chalk.gray(' │')) .join('\n'); return `${top}\n${middle}\n${bottom}`; } /** * Generate console URL based on API URL * If a non-default API URL is used, prepends "dev." to the console subdomain * @param apiUrl - The API URL being used * @param uploadId - The upload ID * @param resultId - The result ID * @returns The appropriate console URL */ function getConsoleUrl(apiUrl, uploadId, resultId) { const DEFAULT_API_URL = 'https://api.devicecloud.dev'; const isDefaultApi = apiUrl === DEFAULT_API_URL; const consoleSubdomain = isDefaultApi ? 'console' : 'dev.console'; return `https://${consoleSubdomain}.devicecloud.dev/results?upload=${uploadId}&result=${resultId}`; }