@@ -4,19 +4,36 @@ import path from 'path';
44import { execSync } from 'child_process' ;
55import chalk from 'chalk' ;
66import { displayLogo } from './asciiLogo.js' ;
7+ import MongoSpinner from './spinner.js' ;
8+ import { celebrate } from './celebration.js' ;
9+ import FunProgressBar from './progressBar.js' ;
710
8- export function createRagApp ( projectName ) {
9- const projectPath = path . resolve ( process . cwd ( ) , projectName ) ;
11+ export async function createRagApp ( projectName ) {
12+ const spinner = new MongoSpinner ( ) ;
13+ const progressBar = new FunProgressBar ( ) ;
14+
15+ // Display the ASCII logo
1016 displayLogo ( ) ;
11-
17+
18+ const projectPath = path . resolve ( process . cwd ( ) , projectName ) ;
1219
1320 if ( fs . existsSync ( projectPath ) ) {
1421 console . error ( chalk . red ( `Error: Directory "${ projectName } " already exists.` ) ) ;
1522 process . exit ( 1 ) ;
1623 }
1724
1825 console . log ( chalk . green ( `\n🚀 Creating a new RAG app in ${ projectPath } \n` ) ) ;
26+
27+ // Start the creation process with spinner
28+ spinner . start ( 'Initializing your RAG app' ) ;
1929 fs . mkdirSync ( projectPath , { recursive : true } ) ;
30+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
31+ spinner . stop ( true ) ;
32+
33+ // Show progress while creating files
34+ console . log ( chalk . cyan ( '\nPreparing your MongoDB RAG environment...' ) ) ;
35+ let currentProgress = 0 ;
36+ progressBar . update ( currentProgress ) ;
2037
2138 // Step 1: Create package.json
2239 fs . writeFileSync ( path . join ( projectPath , 'package.json' ) , JSON . stringify ( {
@@ -35,8 +52,10 @@ export function createRagApp(projectName) {
3552 "mongodb-rag" : "^0.15.0"
3653 }
3754 } , null , 2 ) ) ;
55+ currentProgress += 0.25 ;
56+ progressBar . update ( currentProgress ) ;
3857
39- // Step 2: Create .env file with corrected variables
58+ // Step 2: Create .env file
4059 fs . writeFileSync ( path . join ( projectPath , '.env' ) , `
4160MONGODB_URI=mongodb+srv://your_user:your_password@your-cluster.mongodb.net/mongorag
4261PORT=5000
@@ -49,8 +68,10 @@ EMBEDDING_MODEL=text-embedding-3-small # Adjust for different providers
4968# MongoDB Vector Search Index
5069VECTOR_INDEX=default
5170 ` ) ;
71+ currentProgress += 0.25 ;
72+ progressBar . update ( currentProgress ) ;
5273
53- // Step 3: Create server.js with environment-aware embedding configuration
74+ // Step 3: Create server.js
5475 fs . writeFileSync ( path . join ( projectPath , 'server.js' ) , `
5576import express from 'express';
5677import cors from 'cors';
@@ -101,13 +122,26 @@ app.listen(process.env.PORT || 5000, () => {
101122 console.log(\`🚀 Server running on port \${process.env.PORT || 5000}\`);
102123});
103124 ` ) ;
125+ currentProgress += 0.25 ;
126+ progressBar . update ( currentProgress ) ;
104127
105- // Step 4: Install dependencies
128+ // Step 4: Install dependencies with spinner
106129 console . log ( chalk . blue ( `\n📦 Installing dependencies...\n` ) ) ;
130+ spinner . start ( 'Installing packages' ) ;
107131 execSync ( `cd ${ projectPath } && npm install` , { stdio : 'inherit' } ) ;
108-
109- console . log ( chalk . green ( `\n✅ Project created successfully!` ) ) ;
110- console . log ( chalk . yellow ( `\nNext steps:` ) ) ;
111- console . log ( chalk . cyan ( ` cd ${ projectName } ` ) ) ;
112- console . log ( chalk . cyan ( ` npm run dev` ) ) ;
113- }
132+ spinner . stop ( true ) ;
133+ currentProgress = 1 ;
134+ progressBar . update ( currentProgress ) ;
135+
136+ // Show celebration
137+ await new Promise ( resolve => setTimeout ( resolve , 500 ) ) ;
138+ celebrate ( 'RAG App Created Successfully! 🎉' ) ;
139+
140+ // Show next steps after celebration (keeping original format)
141+ setTimeout ( ( ) => {
142+ console . log ( chalk . green ( `\n✅ Project created successfully!` ) ) ;
143+ console . log ( chalk . yellow ( `\nNext steps:` ) ) ;
144+ console . log ( chalk . cyan ( ` cd ${ projectName } ` ) ) ;
145+ console . log ( chalk . cyan ( ` npm run dev` ) ) ;
146+ } , 2500 ) ;
147+ }
0 commit comments