268 lines
6.4 KiB
PowerShell

# setup.ps1
$projectName = "ve-router-backend"
# Colors for output
$green = "`e[0;32m"
$blue = "`e[0;34m"
$nc = "`e[0m" # No Color
Write-Host "$blue Creating project structure for $projectName... $nc"
# Create project directory
New-Item -ItemType Directory -Force -Name $projectName
Set-Location -Path $projectName
# Create package.json
Write-Host "$blue Initializing package.json... $nc"
$packageJson = @"
{
"name": "ve-router-backend",
"version": "1.0.0",
"description": "Router Management System Backend",
"main": "dist/app.js",
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon src/app.ts",
"build": "tsc",
"test": "jest",
"lint": "eslint src/**/*.ts",
"format": "prettier --write \"src/**/*.ts\""
},
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mysql2": "^3.2.0",
"winston": "^3.8.2"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.37.0",
"jest": "^29.5.0",
"nodemon": "^2.0.22",
"prettier": "^2.8.7",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
}
}
"@
$packageJson | Out-File -FilePath "package.json" -Encoding UTF8
# Create directory structure
Write-Host "$blue Creating directory structure... $nc"
$dirs = @("src/config", "src/controllers", "src/middleware", "src/repositories", "src/routes", "src/services", "src/types", "src/utils", "tests/integration", "tests/unit/services")
$dirs | ForEach-Object { New-Item -ItemType Directory -Force -Path $_ }
# Create TypeScript configuration
Write-Host "$blue Creating TypeScript configuration... $nc"
$tsconfig = @"
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"baseUrl": "./src",
"paths": {
"@/*": ["*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "tests"]
}
"@
$tsconfig | Out-File -FilePath "tsconfig.json" -Encoding UTF8
# Create environment files
Write-Host "$blue Creating environment files... $nc"
$envExample = @"
NODE_ENV=development
PORT=3000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=ve_router_db
LOG_LEVEL=info
JWT_SECRET=your_jwt_secret
CORS_ORIGIN=http://localhost:3000
"
$envExample | Out-File -FilePath ".env.example" -Encoding UTF8
Copy-Item -Path ".env.example" -Destination ".env"
# Create .gitignore
Write-Host "$blue Creating .gitignore... $nc"
$gitignore = @"
node_modules/
dist/
.env
*.log
coverage/
.DS_Store
"
$gitignore | Out-File -FilePath ".gitignore" -Encoding UTF8
# Create source files
Write-Host "$blue Creating source files... $nc"
# Config files
$srcConfig = @"
import dotenv from 'dotenv';
dotenv.config();
export const config = {
env: process.env.NODE_ENV || 'development',
port: parseInt(process.env.PORT || '3000', 10),
db: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || '',
database: process.env.DB_NAME || 've_router_db'
},
logLevel: process.env.LOG_LEVEL || 'info',
jwtSecret: process.env.JWT_SECRET || 'your-secret-key',
corsOrigin: process.env.CORS_ORIGIN || 'http://localhost:3000'
};
"@
$srcConfig | Out-File -FilePath "src/config/config.ts" -Encoding UTF8
$srcDb = @"
import mysql from 'mysql2/promise';
import { config } from './config';
const pool = mysql.createPool({
host: config.db.host,
user: config.db.user,
password: config.db.password,
database: config.db.database,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
});
export default pool;
"@
$srcDb | Out-File -FilePath "src/config/db.ts" -Encoding UTF8
# Types
$srcTypes = @"
export interface Study {
siuid: string;
patientId: string;
accessionNumber: string;
patientName: string;
studyDate: string;
modality: string;
studyDescription: string;
}
export interface VM {
id: number;
status: string;
}
export type FilterType = 'all' | 'active' | 'critical' | 'diskAlert';
export interface RouterData {
id: number;
slNo: number;
routerId: string;
facility: string;
routerAlias: string;
lastSeen: string;
diskStatus: string;
diskUsage: number;
freeDisk: number;
totalDisk: number;
routerActivity: {
studies: Study[];
};
systemStatus: {
vpnStatus: string;
appStatus: string;
vms: VM[];
};
}
"@
$srcTypes | Out-File -FilePath "src/types/index.ts" -Encoding UTF8
# Create barrel files for each directory
Write-Host "$blue Creating barrel files... $nc"
$directories = @("controllers", "middleware", "repositories", "routes", "services", "utils")
foreach ($dir in $directories) {
"export * from './$dir';" | Out-File -FilePath "src/$dir/index.ts" -Encoding UTF8
}
# Create README.md
Write-Host "$blue Creating README.md... $nc"
$readme = @"
# VE Router Backend
## Setup
1. Install dependencies:
\`\`\`bash
npm install
\`\`\`
2. Configure environment variables:
\`\`\`bash
cp .env.example .env
# Edit .env with your configuration
\`\`\`
3. Start development server:
\`\`\`bash
npm run dev
\`\`\`
## Scripts
- \`npm start\`: Start production server
- \`npm run dev\`: Start development server
- \`npm run build\`: Build the project
- \`npm test\`: Run tests
- \`npm run lint\`: Lint code
- \`npm run format\`: Format code
## Project Structure
\`\`\`
src/
config/ # Configuration files
controllers/ # Request handlers
middleware/ # Express middleware
repositories/ # Data access layer
routes/ # API routes
services/ # Business logic
types/ # TypeScript types
utils/ # Utility functions
\`\`\`
"@
$readme | Out-File -FilePath "README.md" -Encoding UTF8
# Initialize git repository
Write-Host "$blue Initializing git repository... $nc"
git init
git add .
git commit -m "Initial commit"
# Install dependencies
Write-Host "$blue Installing dependencies... $nc"
npm install
Write-Host "$green Project setup complete! $nc"
Write-Host "$green To get started: $nc"
Write-Host "1. cd $projectName"
Write-Host "2. Edit .env with your configuration"
Write-Host "3. npm run dev"