UNPKG

@amplitude/ampli

Version:

Amplitude CLI

43 lines (42 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = require("chalk"); const TerminalWriter_1 = require("../stdout/TerminalWriter"); const compareByName_1 = require("../util/sort/compareByName"); const runtime_1 = require("../util/runtime"); const { bold: b, red, cyan } = chalk_1.default; function SourcesInfo(sources, activeSourceId) { const stdout = new TerminalWriter_1.default(); stdout.println(cyan('Sources:')); if (sources.length < 1) { stdout.println(red(` → ${red('(none)')}`)); } else { stdout.println([...sources].sort(compareByName_1.default) .map(s => ` → ${s.name}${getSourceString(activeSourceId != null && activeSourceId === s.id, s.runtime)}`) .join('\n')); } } exports.default = SourcesInfo; function getSourceString(isCurrentSource, runtime) { const parts = []; if (isCurrentSource) { parts.push(b('current')); } const isSupported = runtime_1.isSupportedRuntime(runtime.id) || runtime_1.isPlatformOnlyRuntime(runtime.id); if (!isSupported) { parts.push(b('not supported')); } if (isCurrentSource) { if (runtime_1.isPlatformOnlyRuntime(runtime.id)) { parts.push(`use ${b('ampli configure')} to configure the source`); } else { parts.push(`using ${b(runtime_1.getRuntimeDisplayString(runtime))}`); } } if (parts.length > 0) { return ` (${parts.join(', ')})`; } return ''; }