-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-project.js
More file actions
212 lines (176 loc) · 5.98 KB
/
setup-project.js
File metadata and controls
212 lines (176 loc) · 5.98 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env node
/**
* RAG Q&A Chatbot Setup Script
* Author: Aaryan Choudhary
*
* This script helps users set up the project quickly by:
* 1. Checking system requirements
* 2. Installing dependencies
* 3. Setting up environment configuration
* 4. Creating necessary directories
* 5. Running initial tests
*/
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
console.log('🚀 RAG Q&A Chatbot Setup');
console.log('========================');
console.log('Author: Aaryan Choudhary\n');
const steps = [
'Checking system requirements',
'Setting up environment configuration',
'Creating required directories',
'Installing dependencies',
'Running system tests',
'Setup complete'
];
let currentStep = 0;
function logStep(message) {
currentStep++;
console.log(`\n[${currentStep}/${steps.length}] ${message}`);
}
function logSuccess(message) {
console.log(` ✅ ${message}`);
}
function logError(message) {
console.log(` ❌ ${message}`);
}
function logInfo(message) {
console.log(` ℹ️ ${message}`);
}
function checkSystemRequirements() {
logStep('Checking system requirements');
// Check Node.js version
const nodeVersion = process.version;
const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
if (majorVersion >= 18) {
logSuccess(`Node.js ${nodeVersion} (compatible)`);
} else {
logError(`Node.js ${nodeVersion} (requires v18+)`);
process.exit(1);
}
// Check npm availability
try {
const npmVersion = execSync('npm --version', { encoding: 'utf8' }).trim();
logSuccess(`npm ${npmVersion} available`);
} catch (error) {
logError('npm not found');
process.exit(1);
}
// Check git availability (optional)
try {
const gitVersion = execSync('git --version', { encoding: 'utf8' }).trim();
logSuccess(`${gitVersion} available`);
} catch (error) {
logInfo('Git not found (optional for development)');
}
}
function setupEnvironment() {
logStep('Setting up environment configuration');
const envPath = '.env';
const envExamplePath = '.env.example';
if (fs.existsSync(envPath)) {
logInfo('.env file already exists, skipping creation');
} else if (fs.existsSync(envExamplePath)) {
fs.copyFileSync(envExamplePath, envPath);
logSuccess('Created .env file from template');
logInfo('Please edit .env file to add your API keys');
} else {
// Create basic .env file
const basicEnv = `# RAG Q&A Chatbot Configuration
PORT=3000
NODE_ENV=development
# Add your API keys here (optional)
# OPENAI_API_KEY=your_key_here
# GOOGLE_API_KEY=your_key_here
# ANTHROPIC_API_KEY=your_key_here
# COHERE_API_KEY=your_key_here
# HUGGINGFACE_API_KEY=your_key_here
# Security settings
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
`;
fs.writeFileSync(envPath, basicEnv);
logSuccess('Created basic .env file');
}
}
function createDirectories() {
logStep('Creating required directories');
const directories = ['uploads', 'logs'];
directories.forEach(dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
logSuccess(`Created ${dir}/ directory`);
} else {
logInfo(`${dir}/ directory already exists`);
}
});
// Create .gitkeep files to ensure directories are tracked
directories.forEach(dir => {
const gitkeepPath = path.join(dir, '.gitkeep');
if (!fs.existsSync(gitkeepPath)) {
fs.writeFileSync(gitkeepPath, '');
logSuccess(`Added .gitkeep to ${dir}/`);
}
});
}
function installDependencies() {
logStep('Installing dependencies');
try {
logInfo('Installing npm packages...');
execSync('npm install', { stdio: 'inherit' });
logSuccess('Dependencies installed successfully');
} catch (error) {
logError('Failed to install dependencies');
logInfo('You can try manual installation with: npm install');
process.exit(1);
}
}
function runTests() {
logStep('Running system tests');
try {
logInfo('Running basic functionality tests...');
execSync('npm test', { stdio: 'inherit' });
logSuccess('All tests passed');
} catch (error) {
logError('Some tests failed, but setup can continue');
logInfo('You can run tests manually later with: npm test');
}
}
function setupComplete() {
logStep('Setup complete');
console.log('\n🎉 Setup completed successfully!\n');
console.log('Next steps:');
console.log('1. Edit .env file to add your API keys (optional)');
console.log('2. Start the server: npm start');
console.log('3. Open your browser: http://localhost:3000');
console.log('4. Upload documents and start chatting!\n');
console.log('Available commands:');
console.log(' npm start - Start the production server');
console.log(' npm run dev - Start development server with auto-reload');
console.log(' npm test - Run system tests');
console.log(' npm run help - Show additional commands\n');
console.log('Documentation:');
console.log(' README.md - Main documentation');
console.log(' DEPLOYMENT.md - Deployment guide');
console.log(' PROJECT_SUMMARY.md - Technical overview\n');
console.log('Support:');
console.log(' GitHub Issues - Report bugs or request features');
console.log(' Email - Contact Aaryan Choudhary for support\n');
console.log('Happy chatting! 🤖');
}
// Run setup steps
async function runSetup() {
try {
checkSystemRequirements();
setupEnvironment();
createDirectories();
installDependencies();
runTests();
setupComplete();
} catch (error) {
console.error('\n❌ Setup failed:', error.message);
process.exit(1);
}
}
runSetup();