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 fs from 'fs';
import https from 'https'; import https from 'https';
import inquirer from 'inquirer'; import inquirer from 'inquirer';
import ora from 'ora'; // Import ora
import { log, readJSON } from './utils.js'; import { log, readJSON } from './utils.js';
import { import {
@@ -519,82 +520,106 @@ function registerCommands(programInstance) {
// Helper function to check if tasks.json exists and confirm overwrite // Helper function to check if tasks.json exists and confirm overwrite
async function confirmOverwriteIfNeeded() { async function confirmOverwriteIfNeeded() {
if (fs.existsSync(outputPath) && !force && !append) { if (fs.existsSync(outputPath) && !useForce && !useAppend) {
const overwrite = await confirmTaskOverwrite(outputPath); // Calls inquirer prompt const overwrite = await confirmTaskOverwrite(outputPath);
if (!overwrite) { if (!overwrite) {
log('info', 'Operation cancelled.'); 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 // If user confirms 'y', we should set useForce = true for the parsePRD call
// Only overwrite if not appending
useForce = true; useForce = true;
} }
return true; return true;
} }
// If no input file specified, check for default PRD location let spinner;
if (!inputFile) {
if (fs.existsSync(defaultPrdPath)) {
console.log(chalk.blue(`Using default PRD file: ${defaultPrdPath}`));
// Check for existing tasks.json before proceeding try {
if (!(await confirmOverwriteIfNeeded())) return; if (!inputFile) {
if (fs.existsSync(defaultPrdPath)) {
console.log(
chalk.blue(`Using default PRD file path: ${defaultPrdPath}`)
);
if (!(await confirmOverwriteIfNeeded())) return;
console.log(chalk.blue(`Generating ${numTasks} tasks...`)); console.log(chalk.blue(`Generating ${numTasks} tasks...`));
await parsePRD(defaultPrdPath, outputPath, numTasks, { spinner = ora('Parsing PRD and generating tasks...').start();
useAppend, await parsePRD(defaultPrdPath, outputPath, numTasks, {
useForce useAppend,
}); useForce
});
spinner.succeed('Tasks generated successfully!');
return;
}
console.log(
chalk.yellow(
'No PRD file specified and default PRD file not found at scripts/prd.txt.'
)
);
console.log(
boxen(
chalk.white.bold('Parse PRD Help') +
'\n\n' +
chalk.cyan('Usage:') +
'\n' +
` task-master parse-prd <prd-file.txt> [options]\n\n` +
chalk.cyan('Options:') +
'\n' +
' -i, --input <file> Path to the PRD file (alternative to positional argument)\n' +
' -o, --output <file> Output file path (default: "tasks/tasks.json")\n' +
' -n, --num-tasks <number> Number of tasks to generate (default: 10)\n' +
' -f, --force Skip confirmation when overwriting existing tasks\n' +
' --append Append new tasks to existing tasks.json instead of overwriting\n\n' +
chalk.cyan('Example:') +
'\n' +
' task-master parse-prd requirements.txt --num-tasks 15\n' +
' task-master parse-prd --input=requirements.txt\n' +
' task-master parse-prd --force\n' +
' task-master parse-prd requirements_v2.txt --append\n\n' +
chalk.yellow('Note: This command will:') +
'\n' +
' 1. Look for a PRD file at scripts/prd.txt by default\n' +
' 2. Use the file specified by --input or positional argument if provided\n' +
' 3. Generate tasks from the PRD and either:\n' +
' - Overwrite any existing tasks.json file (default)\n' +
' - Append to existing tasks.json if --append is used',
{ padding: 1, borderColor: 'blue', borderStyle: 'round' }
)
);
return; return;
} }
console.log( if (!fs.existsSync(inputFile)) {
chalk.yellow( console.error(
'No PRD file specified and default PRD file not found at scripts/prd.txt.' chalk.red(`Error: Input PRD file not found: ${inputFile}`)
) );
); process.exit(1);
console.log( }
boxen(
chalk.white.bold('Parse PRD Help') + if (!(await confirmOverwriteIfNeeded())) return;
'\n\n' +
chalk.cyan('Usage:') + console.log(chalk.blue(`Parsing PRD file: ${inputFile}`));
'\n' + console.log(chalk.blue(`Generating ${numTasks} tasks...`));
` task-master parse-prd <prd-file.txt> [options]\n\n` + if (append) {
chalk.cyan('Options:') + console.log(chalk.blue('Appending to existing tasks...'));
'\n' + }
' -i, --input <file> Path to the PRD file (alternative to positional argument)\n' +
' -o, --output <file> Output file path (default: "tasks/tasks.json")\n' + spinner = ora('Parsing PRD and generating tasks...').start();
' -n, --num-tasks <number> Number of tasks to generate (default: 10)\n' + await parsePRD(inputFile, outputPath, numTasks, {
' -f, --force Skip confirmation when overwriting existing tasks\n' + append: useAppend,
' --append Append new tasks to existing tasks.json instead of overwriting\n\n' + force: useForce
chalk.cyan('Example:') + });
'\n' + spinner.succeed('Tasks generated successfully!');
' task-master parse-prd requirements.txt --num-tasks 15\n' + } catch (error) {
' task-master parse-prd --input=requirements.txt\n' + if (spinner) {
' task-master parse-prd --force\n' + spinner.fail(`Error parsing PRD: ${error.message}`);
' task-master parse-prd requirements_v2.txt --append\n\n' + } else {
chalk.yellow('Note: This command will:') + console.error(chalk.red(`Error parsing PRD: ${error.message}`));
'\n' + }
' 1. Look for a PRD file at scripts/prd.txt by default\n' + process.exit(1);
' 2. Use the file specified by --input or positional argument if provided\n' +
' 3. Generate tasks from the PRD and either:\n' +
' - Overwrite any existing tasks.json file (default)\n' +
' - Append to existing tasks.json if --append is used',
{ padding: 1, borderColor: 'blue', borderStyle: 'round' }
)
);
return;
} }
// Check for existing tasks.json before proceeding with specified input file
if (!(await confirmOverwriteIfNeeded())) return;
console.log(chalk.blue(`Parsing PRD file: ${inputFile}`));
console.log(chalk.blue(`Generating ${numTasks} tasks...`));
if (append) {
console.log(chalk.blue('Appending to existing tasks...'));
}
await parsePRD(inputFile, outputPath, numTasks, { append });
}); });
// update command // update command