-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
78 lines (63 loc) · 2.12 KB
/
setup.js
File metadata and controls
78 lines (63 loc) · 2.12 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
const { spawn } = require('child_process');
const fs = require('fs-extra');
const path = require('path');
async function runCommand(command, args, cwd = process.cwd()) {
return new Promise((resolve, reject) => {
console.log(`Running: ${command} ${args.join(' ')} in ${cwd}`);
const process = spawn(command, args, {
cwd,
stdio: 'inherit',
shell: true
});
process.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Command failed with code ${code}`));
}
});
});
}
async function setup() {
console.log('🚀 Setting up Study Tracker with File Persistence\n');
try {
// Install frontend dependencies
console.log('📦 Installing frontend dependencies...');
await runCommand('npm', ['install']);
// Create server directory and install backend dependencies
console.log('\n📦 Installing backend dependencies...');
await fs.ensureDir('server');
await runCommand('npm', ['install'], path.join(process.cwd(), 'server'));
// Create data directory for file storage
console.log('\n📁 Creating data directory...');
await fs.ensureDir('server/data');
// Create test setup file
console.log('\n🧪 Setting up test environment...');
const setupTestsContent = `
import '@testing-library/jest-dom';
// Mock localStorage
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
};
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
});
// Mock fetch
global.fetch = jest.fn();
`;
await fs.writeFile('src/setupTests.ts', setupTestsContent.trim());
console.log('\n✅ Setup completed successfully!');
console.log('\n📋 Next steps:');
console.log('1. Start the backend server: cd server && npm start');
console.log('2. Start the frontend app: npm start');
console.log('3. Run tests: node test-runner.js');
console.log('\n🎯 The app will now persist data to JSON files in server/data/');
} catch (error) {
console.error('❌ Setup failed:', error.message);
process.exit(1);
}
}
setup();