UNPKG

@kya-os/cli

Version:

CLI for KYA-OS MCP-I setup and management

133 lines 4.89 kB
import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; export function detectPlatform(projectRoot = process.cwd()) { const info = { platform: 'unknown', hasVercel: false, hasDocker: false, packageManager: 'npm' }; // Check package.json const packageJsonPath = join(projectRoot, 'package.json'); if (existsSync(packageJsonPath)) { try { const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); // Detect Next.js if (packageJson.dependencies?.next || packageJson.devDependencies?.next) { info.platform = 'nextjs'; info.framework = 'nextjs'; info.version = packageJson.dependencies?.next || packageJson.devDependencies?.next; } // Check for other frameworks if (packageJson.dependencies?.express) { info.framework = 'express'; if (info.platform === 'unknown') info.platform = 'node'; } if (packageJson.dependencies?.fastify) { info.framework = 'fastify'; if (info.platform === 'unknown') info.platform = 'node'; } } catch (error) { console.error('Error reading package.json:', error); } } // Check for Vercel if (existsSync(join(projectRoot, 'vercel.json')) || existsSync(join(projectRoot, '.vercel'))) { info.hasVercel = true; if (info.platform === 'nextjs') { info.platform = 'vercel'; // Next.js on Vercel } } // Check for Docker if (existsSync(join(projectRoot, 'Dockerfile')) || existsSync(join(projectRoot, 'docker-compose.yml'))) { info.hasDocker = true; if (info.platform === 'unknown') info.platform = 'docker'; } // Check for Lambda if (existsSync(join(projectRoot, 'serverless.yml')) || existsSync(join(projectRoot, 'template.yaml')) || existsSync(join(projectRoot, 'sam-template.yaml'))) { info.platform = 'lambda'; } // Detect package manager if (existsSync(join(projectRoot, 'pnpm-lock.yaml'))) { info.packageManager = 'pnpm'; } else if (existsSync(join(projectRoot, 'yarn.lock'))) { info.packageManager = 'yarn'; } // Default to Node.js if we found a package.json but nothing else if (info.platform === 'unknown' && existsSync(packageJsonPath)) { info.platform = 'node'; } return info; } export function getPlatformSpecificConfig(platform) { const configs = { nextjs: { storage: 'memory', transport: 'fetch', envFile: '.env.local', instructions: [ 'Add environment variables to .env.local for local development', 'For production, add variables to Vercel Dashboard', 'Import with: import "@kya-os/mcp-i/auto"' ] }, vercel: { storage: 'memory', transport: 'fetch', envFile: '.env.local', instructions: [ 'Add environment variables to .env.local for local development', 'Add the same variables to Vercel Dashboard → Settings → Environment Variables', 'Import with: import "@kya-os/mcp-i/auto"' ] }, lambda: { storage: 'memory', transport: 'fetch', envFile: '.env', instructions: [ 'Add environment variables to your Lambda function configuration', 'Or use AWS Systems Manager Parameter Store', 'Import with: import "@kya-os/mcp-i/auto"' ] }, docker: { storage: 'file', transport: 'fetch', envFile: '.env', instructions: [ 'Add environment variables to docker-compose.yml or Dockerfile', 'Mount a volume for persistent identity storage', 'Import with: import "@kya-os/mcp-i/auto"' ] }, node: { storage: 'file', transport: 'fetch', envFile: '.env', instructions: [ 'Add environment variables to .env file', 'Make sure to add .env to .gitignore', 'Import with: import "@kya-os/mcp-i/auto"' ] }, unknown: { storage: 'auto', transport: 'fetch', envFile: '.env', instructions: [ 'Add environment variables based on your deployment platform', 'Import with: import "@kya-os/mcp-i/auto"' ] } }; return configs[platform]; } //# sourceMappingURL=platform-detector.js.map