UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

133 lines (106 loc) 3.44 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _chalk() { const data = _interopRequireDefault(require("chalk")); _chalk = function () { return data; }; return data; } function _ramda() { const data = _interopRequireDefault(require("ramda")); _ramda = function () { return data; }; return data; } function _semver() { const data = _interopRequireDefault(require("semver")); _semver = function () { return data; }; return data; } function _ttyTable() { const data = _interopRequireDefault(require("tty-table")); _ttyTable = function () { return data; }; return data; } var _default = (listScopeResults, json, showRemoteVersion) => { const header = [{ value: 'component ID', width: 70, headerColor: 'cyan', headerAlign: 'left' }, { value: showRemoteVersion ? 'local version' : 'local version', width: 9, headerColor: 'cyan', headerAlign: 'left' }, { value: 'used version', width: 9, headerColor: 'cyan', headerAlign: 'left' }]; if (showRemoteVersion) { header.push({ value: 'remote version', width: 9, headerColor: 'cyan', headerAlign: 'left' }); } const opts = { align: 'left' }; function tabulateComponent(listScopeResult) { const id = listScopeResult.id.toStringWithoutVersion(); let version = listScopeResult.id.version; if (!json && showRemoteVersion) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const color = listScopeResult.remoteVersion && _semver().default.gt(listScopeResult.remoteVersion, version) ? 'red' : null; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! version = color ? _chalk().default[color](version) : version; } const data = { id: _chalk().default.white(`${id}${listScopeResult.deprecated ? ' [Deprecated]' : ''}`), // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! localVersion: version, currentVersion: listScopeResult.currentlyUsedVersion || 'N/A' }; if (showRemoteVersion) { let remoteVersion = listScopeResult.remoteVersion || 'N/A'; const color = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion listScopeResult.remoteVersion && _semver().default.gt(listScopeResult.id.version, listScopeResult.remoteVersion) ? 'red' : null; remoteVersion = color ? _chalk().default[color](remoteVersion) : remoteVersion; data.remoteVersion = remoteVersion; } return data; } function toJsonComponent(listScopeResult) { const id = listScopeResult.id.toStringWithoutVersion(); const version = listScopeResult.id.version; const data = { id, localVersion: version, deprecated: listScopeResult.deprecated, currentVersion: listScopeResult.currentlyUsedVersion || 'N/A', remoteVersion: listScopeResult.remoteVersion || 'N/A' }; return data; } if (json) { const jsonResults = listScopeResults.map(toJsonComponent); return JSON.stringify(jsonResults, null, 2); } const rows = listScopeResults.map(tabulateComponent); const table = new (_ttyTable().default)(header, rows.map(row => _ramda().default.values(row)), opts); return table.render(); }; exports.default = _default;