polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
151 lines • 5.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputRenderer = void 0;
const variable_resolver_1 = require("./variable-resolver");
class OutputRenderer {
constructor() {
this.spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
this.spinnerIndex = 0;
this.resolver = new variable_resolver_1.VariableResolver();
}
renderSummary(config, resources, options = {}) {
if (options.format === 'json') {
return this.renderSummaryJson(config, resources, options);
}
return this.renderSummaryTable(config, resources, options);
}
renderNextSteps(nextSteps, outputs) {
if (!nextSteps || nextSteps.length === 0) {
return 'No next steps available.';
}
const lines = ['\n📋 Next Steps:', ''];
nextSteps.forEach((step, index) => {
try {
const resolvedCommand = this.resolver.renderTemplate(step.command, outputs);
lines.push(`${index + 1}. ${step.description}`);
lines.push(` $ ${resolvedCommand}`);
lines.push('');
}
catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
lines.push(`${index + 1}. ${step.description} (error: ${errorMsg})`);
lines.push('');
}
});
return lines.join('\n');
}
renderProgress(event) {
const { phase, resourceId, resourceType, showSpinner, current, total } = event;
let icon = '';
let action = '';
switch (phase) {
case 'creating':
icon = showSpinner ? this.getNextSpinnerFrame() : '⏳';
action = 'Creating';
break;
case 'created':
icon = '✅';
action = 'Created';
break;
case 'rolling_back':
icon = '↩️';
action = 'Rolling back';
break;
case 'rolled_back':
icon = '🔙';
action = 'Rolled back';
break;
}
let progress = '';
if (current !== undefined && total !== undefined) {
progress = ` (${current}/${total})`;
}
return `${icon} ${action} ${resourceType}: ${resourceId}${progress}`;
}
renderError(error, context = {}, options = {}) {
if (options.format === 'json') {
return JSON.stringify({
success: false,
error: error.message,
...context,
}, null, 2);
}
const lines = ['\n❌ Error:', '', error.message];
if (context.failedAt) {
lines.push(``);
lines.push(`Failed at: ${context.failedAt}`);
}
if (context.rolledBack && context.rolledBack.length > 0) {
lines.push('');
lines.push('Rolled back resources:');
context.rolledBack.forEach(id => {
lines.push(` - ${id}`);
});
}
if (context.suggestion) {
lines.push('');
lines.push(`💡 Suggestion: ${context.suggestion}`);
}
return lines.join('\n');
}
renderTemplate(template, outputs) {
return this.resolver.renderTemplate(template, outputs);
}
renderDryRunOutput(config, resources) {
const lines = [
'\n🔍 Dry Run - No resources will be created',
'',
`Scene: ${config.name}`,
`Description: ${config.description || 'N/A'}`,
'',
`Resources to be created: ${resources.length}`,
'',
];
lines.push('Execution order:');
resources.forEach((resource, index) => {
lines.push(` ${index + 1}. ${resource.type}: ${resource.id}`);
});
return lines.join('\n');
}
renderSummaryTable(config, resources, options) {
const icon = config.metadata?.icon || '📦';
const lines = [
`\n${icon} Scene "${config.name}" configured successfully!`,
'',
];
lines.push('Created resources:');
lines.push('');
resources.forEach(resource => {
lines.push(` ${resource.type}: ${resource.id}`);
for (const [key, value] of Object.entries(resource.output)) {
lines.push(` - ${key}: ${value}`);
}
lines.push('');
});
if (options.duration !== undefined) {
const seconds = (options.duration / 1000).toFixed(2);
lines.push(`Duration: ${seconds}s`);
}
return lines.join('\n');
}
renderSummaryJson(config, resources, options) {
return JSON.stringify({
success: true,
scene: config.name,
resources: resources.map(r => ({
id: r.id,
type: r.type,
output: r.output,
status: r.status,
})),
duration: options.duration,
}, null, 2);
}
getNextSpinnerFrame() {
const frame = this.spinnerFrames[this.spinnerIndex] ?? '⠋';
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
return frame;
}
}
exports.OutputRenderer = OutputRenderer;
//# sourceMappingURL=output-renderer.js.map