gmail-to-exchange365
Version:
Complete Gmail to Exchange 365 migration tool with UI - Migrate emails, attachments, and folders seamlessly
95 lines (80 loc) • 3.1 kB
text/typescript
import dotenv from "dotenv";
import { existsSync, writeFileSync } from "fs";
import { join } from "path";
import app from "./server/app";
// Load environment variables
dotenv.config();
const PORT = process.env.PORT || 3000;
// Check if .env exists, if not, create a template
const envPath = join(process.cwd(), ".env");
if (!existsSync(envPath)) {
console.log("📝 Creating .env file template...");
const envTemplate = `# Google OAuth Credentials
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
GOOGLE_REDIRECT=http://localhost:${PORT}/google/callback
# Microsoft OAuth Credentials
MS_CLIENT_ID=your_ms_client_id_here
MS_CLIENT_SECRET=your_ms_client_secret_here
MS_TENANT_ID=common
MS_REDIRECT=http://localhost:${PORT}/ms/callback
# Session Configuration
SESSION_SECRET=${generateRandomSecret()}
# Server Configuration
PORT=${PORT}
`;
writeFileSync(envPath, envTemplate);
console.log("✅ Created .env file. Please fill in your OAuth credentials.");
console.log("📖 See SETUP.md or README.md for instructions on getting OAuth credentials.");
console.log("");
}
// Validate required environment variables
const requiredEnvVars = [
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET",
"MS_CLIENT_ID",
"MS_CLIENT_SECRET"
];
const env = dotenv.config().parsed || {};
const missingVars = requiredEnvVars.filter(varName => {
const value = env[varName] || process.env[varName];
return !value || value.includes("your_") || value.includes("_here");
});
if (missingVars.length > 0) {
console.log("⚠️ Missing or incomplete OAuth credentials in .env file:");
missingVars.forEach(varName => console.log(` - ${varName}`));
console.log("");
console.log("📖 Please:");
console.log(" 1. Edit the .env file with your OAuth credentials");
console.log(" 2. See SETUP.md or README.md for detailed setup instructions");
console.log("");
console.log("🔗 Quick links:");
console.log(" - Google: https://console.cloud.google.com/");
console.log(" - Microsoft: https://portal.azure.com/");
console.log("");
process.exit(1);
}
// Start server
console.log("🚀 Starting Gmail → Exchange 365 Migrator...");
console.log(`📧 Server running on http://localhost:${PORT}`);
console.log(`🌐 Open your browser and navigate to: http://localhost:${PORT}`);
console.log("");
app.listen(PORT, () => {
console.log("✅ Ready to migrate emails!");
console.log("");
console.log("📋 Next steps:");
console.log(" 1. Connect your Google account");
console.log(" 2. Connect your Microsoft account");
console.log(" 3. Start the migration");
console.log("");
console.log("Press Ctrl+C to stop the server");
});
function generateRandomSecret(): string {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
for (let i = 0; i < 32; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}