UNPKG

pot-js

Version:

Process management module

105 lines (71 loc) 4.33 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _potLogger = require('pot-logger'); var _createTable = require('../utils/createTable'); var _createTable2 = _interopRequireDefault(_createTable); var _lodash = require('lodash'); var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); var _PrepareCli = require('../utils/PrepareCli'); var _cli = require('../Schemas/cli'); var _logSymbols = require('log-symbols'); var _logSymbols2 = _interopRequireDefault(_logSymbols); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } const defaultCells = [['name', state => state.name], ['instance', state => state.instanceId], ['started', state => state.monitor.startedLocal], ['status', state => state.monitor.status], ['crashes', state => state.monitor.crashes], ['entry', state => state.entry], ['args', state => state.args], ['execPath', state => state.execPath], ['execArgs', state => state.execArgs], ['production', state => state.production], ['daemon', state => state.daemon], ['fork', state => state.fork], ['cwd', state => state.cwd], ['baseDir', state => state.baseDir], ['logsDir', state => state.logsDir], ['watch', state => state.watch.enable], ['maxRestarts', state => state.maxRestarts], ['pid', state => state.pid], ['ppid', state => state.ppid], ['memory', state => state.memoryUsage.styled]]; const show = (() => { var _ref = _asyncToGenerator(function* () { let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; (0, _PrepareCli.prepareRun)(_cli.show, options); var _options$cells = options.cells; const cells = _options$cells === undefined ? defaultCells : _options$cells; var _ref2 = yield (0, _PrepareCli.prepareTarget)(options); const connection = _ref2.connection; const table = (0, _createTable2.default)({ padding: 4 }); let stateList = yield Promise.all(connection.instances.map(function (instance) { return instance.getInfoVerbose(); })); stateList = stateList.filter(Boolean); if (!stateList.length) { return _potLogger.logger.warn('No process'); } table.push(['']); stateList.forEach(function (state) { table.push(['']); table.push([_chalk2.default.bgRed(` ${state.displayName} `)]); table.push(['']); cells.forEach(function (cell) { if (Array.isArray(cell)) { var _cell = _slicedToArray(cell, 2); const key = _cell[0], getValue = _cell[1]; const value = function () { const res = getValue(state, _chalk2.default); const val = res === undefined ? '' : res; if ((0, _lodash.isBoolean)(val)) { return val ? _logSymbols2.default.success : _logSymbols2.default.error; } else if ((0, _lodash.isObject)(val)) { return JSON.stringify(val); } return val.toString(); }(); table.push([_chalk2.default.blue(key), value]); } else { table.push([cell]); } }); table.push(['']); }); table.push(['']); console.log(table.toString()); }); function show() { return _ref.apply(this, arguments); } return show; })(); show.defaultCells = defaultCells; exports.default = show;