pame-core-cli
Version:
PAME.AI Core Operating System CLI - Open Source AI Platform for Agentic Commerce
93 lines • 4.31 kB
JavaScript
import { GoogleCalendarService } from '../services/google-calendar.service.js';
import chalk from 'chalk';
import inquirer from 'inquirer';
export async function handleCalendarIntegration(options, platform) {
console.log(chalk.cyan('🗓️ Calendar Integration Active'));
const calendarService = new GoogleCalendarService();
try {
await calendarService.initialize();
}
catch (error) {
console.log(chalk.yellow('⚠️ Calendar integration not available. Run: pame-core auth google-calendar'));
console.log(chalk.yellow('Proceeding with deployment without calendar integration...'));
return;
}
const teamEmails = process.env.PAME_TEAM_EMAILS?.split(',') || [];
if (options.checkTeam) {
console.log(chalk.cyan('🔍 Checking team availability...'));
const now = new Date();
const oneHour = new Date(now.getTime() + 60 * 60 * 1000);
const availability = await calendarService.checkTeamAvailability(now.toISOString(), oneHour.toISOString(), teamEmails);
if (!availability.available) {
console.log(chalk.yellow('⚠️ Team has conflicts in the next hour:'));
availability.conflictingEvents.forEach(event => {
console.log(chalk.red(` • ${event.summary}`));
});
const { proceed } = await inquirer.prompt([
{
type: 'confirm',
name: 'proceed',
message: 'Team has conflicts. Proceed with deployment anyway?',
default: false
}
]);
if (!proceed) {
console.log(chalk.yellow('🛑 Deployment cancelled due to team conflicts.'));
process.exit(0);
}
}
else {
console.log(chalk.green('✅ Team is available for deployment!'));
}
}
if (options.schedule) {
console.log(chalk.cyan('📅 Finding optimal deployment time...'));
try {
const optimalTime = await calendarService.findOptimalDeploymentTime(teamEmails, 90, // 90 minutes for deployment
7 // Search next 7 days
);
const startTime = new Date(optimalTime.start).toLocaleString();
console.log(chalk.green(`🎯 Optimal deployment time found: ${startTime}`));
const { shouldSchedule } = await inquirer.prompt([
{
type: 'confirm',
name: 'shouldSchedule',
message: 'Schedule deployment for this time?',
default: true
}
]);
if (shouldSchedule) {
const eventId = await calendarService.scheduleDeployment(`PAME.AI ${platform} Deployment`, `Production deployment of ${platform} platform via pame-core-cli`, optimalTime.start, 90, teamEmails);
console.log(chalk.green(`📅 Deployment scheduled! Calendar event: ${eventId}`));
console.log(chalk.yellow('🛑 Deployment will wait for scheduled time.'));
process.exit(0);
}
}
catch (error) {
console.log(chalk.yellow('⚠️ Could not find optimal time. Proceeding with immediate deployment...'));
}
}
// Create deployment event for immediate deployments
if (options.production) {
try {
const eventId = await calendarService.createEvent({
summary: `PAME.AI ${platform} Deployment - In Progress`,
description: `Production deployment started at ${new Date().toLocaleString()}`,
start: {
dateTime: new Date().toISOString(),
timeZone: 'UTC'
},
end: {
dateTime: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
timeZone: 'UTC'
},
attendees: teamEmails.map(email => ({ email }))
});
console.log(chalk.green(`📅 Deployment event created: ${eventId}`));
}
catch (error) {
console.log(chalk.yellow('⚠️ Could not create deployment event, but continuing...'));
}
}
}
//# sourceMappingURL=deploy-calendar.js.map