11/* libs */
22import { oraPromise } from "ora" ;
33import { mkdir , writeFile } from "node:fs/promises" ;
4- import { execa } from "execa" ;
54import inquirer from "inquirer" ;
65import path from "node:path" ;
76import chalk from "chalk" ;
@@ -10,7 +9,7 @@ import chalk from "chalk";
109import { DEV_MODE } from "@/constants" ;
1110
1211/* extras */
13- import { existsAsync } from "@/utils/extras" ;
12+ import { existsAsync , runCommandAsync } from "@/utils/extras" ;
1413
1514/* types */
1615import type { T_PackageManager } from "@/@types/index" ;
@@ -78,52 +77,38 @@ export class TaskMaster {
7877 throw new Error ( "Invalid package manager" ) ;
7978 }
8079
81- await execa ( command , args , {
82- stdio : "inherit" ,
83- env : process . env ,
84- } ) ;
80+ await runCommandAsync ( command , args , false , false ) ;
8581 } , oraOptions ) ;
8682 }
8783
8884 /**
8985 * @description - Initializes the task-master AI by creating a PRD file
86+ * @note 1 - This function doesn't use oraPromise as it is not a long-running task
9087 */
9188 async initAsync ( ) {
9289 const prdFile = DEV_MODE ? "PRD-test.md" : "PRD.md" ;
9390 const prdDestination = DEV_MODE ? "tests" : "docs" ;
9491 const prdFilePath = path . join ( prdDestination , prdFile ) ;
9592
9693 if ( await existsAsync ( prdFilePath ) ) {
97- console . log ( chalk . yellow ( `PRD file already exists at ${ prdFilePath } .` ) ) ;
98- await execa ( "task-master" , [ "init" ] , { stdio : "inherit" } ) ;
99- }
100-
101- try {
102- await oraPromise (
103- async ( ) => {
104- await mkdir ( prdDestination , { recursive : true } ) ;
105- await writeFile ( prdFilePath , "" ) ;
106- } ,
107- {
108- text : "Generating PRD file ..." ,
109- successText : `PRD file created at ${ prdFilePath } ` ,
110- failText : ( error ) => `Failed to create PRD file: ${ error . message } ` ,
111- } ,
94+ console . log (
95+ chalk . yellow (
96+ `PRD file already exists at ${ prdFilePath } , skipping generation.` ,
97+ ) ,
11298 ) ;
113- } catch ( error : unknown ) {
114- const errorMessage =
115- error instanceof Error ? error . message : String ( error ) ;
116- console . error ( chalk . red ( `Error creating PRD file: ${ errorMessage } ` ) ) ;
117- throw error ;
99+ } else {
100+ await mkdir ( prdDestination , { recursive : true } ) ;
101+ await writeFile ( prdFilePath , "" ) ;
102+ console . log ( chalk . green ( `PRD file created at ${ prdFilePath } .` ) ) ;
118103 }
119104
120- await execa ( "task-master" , [ "init" ] , { stdio : "inherit" } ) ;
105+ await runCommandAsync ( "task-master" , [ "init" ] , false , false ) ;
121106 }
122107
123108 /**
124109 * @description - Configures the AI models for task-master AI
125110 */
126111 async configAsync ( ) {
127- await execa ( "task-master" , [ "models" , "--setup" ] , { stdio : "inherit" } ) ;
112+ await runCommandAsync ( "task-master" , [ "models" , "--setup" ] , true , false ) ;
128113 }
129114}
0 commit comments