src/cli/commands/analisar.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import ora from 'ora';
import { analisarSite } from '../../core/pipeline.js';
import { renderTerminal } from '../../report/render-terminal.js';
import { renderJson } from '../../report/render-json.js';
export interface OpcoesAnalisar {
completo?: boolean;
lighthouse?: boolean;
json?: boolean;
}
export async function comandoAnalisar(url: string, opcoes: OpcoesAnalisar): Promise<void> {
const modo = opcoes.completo ? 'completo' : 'rapido';
if (opcoes.json) {
const rep = await analisarSite(url, { modo, lighthouse: opcoes.lighthouse });
process.stdout.write(renderJson(rep) + '\n');
return;
}
const spinner = ora({ text: 'analisando…', stream: process.stderr }).start();
try {
const rep = await analisarSite(url, {
modo,
lighthouse: opcoes.lighthouse,
aoProgredir: (etapa) => (spinner.text = etapa),
});
spinner.stop();
process.stdout.write(renderTerminal(rep) + '\n');
} catch (erro) {
spinner.fail(`Falha ao analisar: ${(erro as Error).message}`);
process.exitCode = 1;
}
}
|