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

106 lines (86 loc) 2.52 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _defineProperty2() { const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); _defineProperty2 = function () { return data; }; return data; } function _ttyTable() { const data = _interopRequireDefault(require("tty-table")); _ttyTable = function () { return data; }; return data; } function _scope() { const data = require("../../../api/scope"); _scope = function () { return data; }; return data; } class CatScope { constructor() { (0, _defineProperty2().default)(this, "name", 'cat-scope [scopePath]'); (0, _defineProperty2().default)(this, "description", 'cat a scope and show all the contents'); (0, _defineProperty2().default)(this, "private", true); (0, _defineProperty2().default)(this, "alias", ''); (0, _defineProperty2().default)(this, "opts", [['f', 'full', 'show all of the objects in the scope'], ['j', 'json', 'print the objects as a json format'], ['e', 'json-extra', 'add hash and object type to the json']]); } action([scopePath], { full, json, jsonExtra }) { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! return (0, _scope().catScope)(scopePath || process.cwd(), full).then(payload => ({ payload, full, json, jsonExtra })); } report({ payload, full, json, jsonExtra }) { if (jsonExtra) { payload.forEach(obj => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! obj.hash = obj.hash().toString(); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! obj.type = obj.constructor.name; }); return JSON.stringify(payload, null, 2); } if (json) { return JSON.stringify(payload, null, 2); } if (!full) { const header = [{ value: 'Id', width: 70, headerColor: 'cyan' }, { value: 'Object', width: 50, headerColor: 'cyan' }]; const opts = { align: 'left' }; const table = new (_ttyTable().default)(header, [], opts); payload.forEach(co => table.push([co.id(), `obj: ${co.hash().toString()}`])); return table.render(); } return payload.map(co => `> ${co.hash().toString()}\n\n${co.id()}\n`).join('\n'); } } exports.default = CatScope;