chore: fixes parse prd to show loading indicator in cli.

This commit is contained in:
Eyal Toledano
2025-05-03 00:04:45 -04:00
parent 25ca1a45a0
commit a48d1f13e2

View File

@@ -10,6 +10,7 @@ import boxen from 'boxen';
import fs from 'fs';
import https from 'https';
import inquirer from 'inquirer';
import ora from 'ora'; // Import ora
import { log, readJSON } from './utils.js';
import {
@@ -519,31 +520,36 @@ function registerCommands(programInstance) {
// Helper function to check if tasks.json exists and confirm overwrite
async function confirmOverwriteIfNeeded() {
if (fs.existsSync(outputPath) && !force && !append) {
const overwrite = await confirmTaskOverwrite(outputPath); // Calls inquirer prompt
if (fs.existsSync(outputPath) && !useForce && !useAppend) {
const overwrite = await confirmTaskOverwrite(outputPath);
if (!overwrite) {
log('info', 'Operation cancelled.');
return false; // Exit if user selects 'N'
return false;
}
// If user confirms 'y', we should set useForce = true for the parsePRD call
// Only overwrite if not appending
useForce = true;
}
return true;
}
// If no input file specified, check for default PRD location
let spinner;
try {
if (!inputFile) {
if (fs.existsSync(defaultPrdPath)) {
console.log(chalk.blue(`Using default PRD file: ${defaultPrdPath}`));
// Check for existing tasks.json before proceeding
console.log(
chalk.blue(`Using default PRD file path: ${defaultPrdPath}`)
);
if (!(await confirmOverwriteIfNeeded())) return;
console.log(chalk.blue(`Generating ${numTasks} tasks...`));
spinner = ora('Parsing PRD and generating tasks...').start();
await parsePRD(defaultPrdPath, outputPath, numTasks, {
useAppend,
useForce
});
spinner.succeed('Tasks generated successfully!');
return;
}
@@ -585,7 +591,13 @@ function registerCommands(programInstance) {
return;
}
// Check for existing tasks.json before proceeding with specified input file
if (!fs.existsSync(inputFile)) {
console.error(
chalk.red(`Error: Input PRD file not found: ${inputFile}`)
);
process.exit(1);
}
if (!(await confirmOverwriteIfNeeded())) return;
console.log(chalk.blue(`Parsing PRD file: ${inputFile}`));
@@ -594,7 +606,20 @@ function registerCommands(programInstance) {
console.log(chalk.blue('Appending to existing tasks...'));
}
await parsePRD(inputFile, outputPath, numTasks, { append });
spinner = ora('Parsing PRD and generating tasks...').start();
await parsePRD(inputFile, outputPath, numTasks, {
append: useAppend,
force: useForce
});
spinner.succeed('Tasks generated successfully!');
} catch (error) {
if (spinner) {
spinner.fail(`Error parsing PRD: ${error.message}`);
} else {
console.error(chalk.red(`Error parsing PRD: ${error.message}`));
}
process.exit(1);
}
});
// update command