polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
160 lines ⢠7.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetupHandler = void 0;
const base_handler_1 = require("./base.handler");
const sdk_1 = require("../sdk");
const scene_config_loader_1 = require("../setup/scene-config-loader");
const scene_executor_1 = require("../setup/scene-executor");
const output_renderer_1 = require("../setup/output-renderer");
class SetupHandler extends base_handler_1.BaseHandler {
constructor(authConfig, serviceConfig) {
super();
this.authConfig = authConfig;
this.serviceConfig = serviceConfig;
this.loader = new scene_config_loader_1.SceneConfigLoader();
this.renderer = new output_renderer_1.OutputRenderer();
}
async setup(options) {
return this.executeWithErrorHandling(async () => {
if (!options.scene || options.scene.trim() === '') {
throw new Error('Scene name is required');
}
if (options.output && !['table', 'json'].includes(options.output)) {
throw new Error('Output format must be "table" or "json"');
}
const config = await this.loader.loadScene(options.scene);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.serviceConfig.baseUrl);
const executor = new scene_executor_1.SceneExecutor(client);
if (options.onProgress) {
executor.setProgressCallback(options.onProgress);
}
const execOptions = {
dryRun: options.dryRun ?? false,
};
if (options.onProgress) {
execOptions.onProgress = options.onProgress;
}
const result = await executor.execute(config, execOptions);
const outputs = this.buildOutputs(result);
if (options.output === 'json') {
console.log(JSON.stringify({
success: result.success,
scene: config.name,
resources: result.resources,
duration: result.duration,
dryRun: result.dryRun,
}, null, 2));
}
else if (options.dryRun) {
console.log(this.renderer.renderDryRunOutput(config, result.resources));
}
else {
const renderOpts = {};
if (options.output) {
renderOpts.format = options.output;
}
if (result.duration !== undefined && result.duration !== null) {
renderOpts.duration = result.duration;
}
const summary = this.renderer.renderSummary(config, result.resources, renderOpts);
console.log(summary);
if (config.nextSteps && config.nextSteps.length > 0) {
const nextSteps = this.renderer.renderNextSteps(config.nextSteps, outputs);
console.log(nextSteps);
}
}
}, 'setup');
}
async listScenes(options = {}) {
return this.executeWithErrorHandling(async () => {
const scenes = this.loader.listAllScenes();
if (options.output === 'json') {
const result = {
builtin: scenes.builtin.map(name => this.loader.getSceneInfo(name)),
user: scenes.user.map(name => this.loader.getSceneInfo(name)),
};
console.log(JSON.stringify(result, null, 2));
return;
}
if (scenes.builtin.length === 0 && scenes.user.length === 0) {
console.log('No scenes available.');
console.log('');
console.log('Built-in scenes are provided in the setup-scenes directory.');
console.log('You can also create custom scenes in ~/.polyv/scenes/');
return;
}
console.log('\nš Available Scenes:\n');
if (scenes.builtin.length > 0) {
console.log('Built-in scenes:');
for (const name of scenes.builtin) {
const info = this.loader.getSceneInfo(name);
const icon = info.icon || 'š¦';
const desc = info.description || '';
console.log(` ${icon} ${name} - ${desc}`);
}
console.log('');
}
if (scenes.user.length > 0) {
console.log('Custom scenes (~/.polyv/scenes/):');
for (const name of scenes.user) {
const info = this.loader.getSceneInfo(name);
const icon = info.icon || 'š§';
const desc = info.description || '';
console.log(` ${icon} ${name} - ${desc}`);
}
console.log('');
}
console.log('Usage:');
console.log(' polyv-live-cli setup <scene-name>');
console.log('');
console.log('Example:');
console.log(' polyv-live-cli setup e-commerce');
}, 'setup.list');
}
async listScenesDetailed(options = {}) {
return this.executeWithErrorHandling(async () => {
const scenes = this.loader.listAllScenes();
if (options.output === 'json') {
const result = {
builtin: scenes.builtin.map(name => this.loader.getSceneInfo(name)),
user: scenes.user.map(name => this.loader.getSceneInfo(name)),
};
console.log(JSON.stringify(result, null, 2));
return;
}
console.log('\nš Available Scenes (Detailed):\n');
const allScenes = [
...scenes.builtin.map(name => ({ name, type: 'builtin' })),
...scenes.user.map(name => ({ name, type: 'user' })),
];
for (const { name, type } of allScenes) {
const info = this.loader.getSceneInfo(name);
const icon = info.icon || (type === 'builtin' ? 'š¦' : 'š§');
const typeLabel = type === 'builtin' ? 'Built-in' : 'Custom';
console.log(`${icon} ${name} (${typeLabel})`);
if (info.description) {
console.log(` Description: ${info.description}`);
}
if (info.category) {
console.log(` Category: ${info.category}`);
}
if (info.resources !== undefined) {
console.log(` Resources: ${info.resources}`);
}
if (info.tags && info.tags.length > 0) {
console.log(` Tags: ${info.tags.join(', ')}`);
}
console.log('');
}
}, 'setup.listDetailed');
}
buildOutputs(result) {
const outputs = {};
for (const resource of result.resources) {
outputs[resource.id] = resource.output;
}
return outputs;
}
}
exports.SetupHandler = SetupHandler;
//# sourceMappingURL=setup.handler.js.map