UNPKG

forge-deploy-cli

Version:

Professional CLI for local deployments with automatic subdomain routing, SSL certificates, and infrastructure management

62 lines 2.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loginCommand = loginCommand; const inquirer_1 = __importDefault(require("inquirer")); const chalk_1 = __importDefault(require("chalk")); const config_1 = require("../services/config"); const api_1 = require("../services/api"); async function loginCommand(options) { console.log(chalk_1.default.blue.bold('Login to Forge')); const configService = new config_1.ConfigService(); const config = await configService.getConfig(); const apiService = new api_1.ForgeApiService(config.apiUrl); try { let email; let password; if (options.email && options.password) { email = options.email; password = options.password; } else { const answers = await inquirer_1.default.prompt([ { type: 'input', name: 'email', message: 'Email:', validate: (input) => { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return emailRegex.test(input) || 'Please enter a valid email address'; } }, { type: 'password', name: 'password', message: 'Password:', validate: (input) => input.length > 0 || 'Password is required' } ]); email = answers.email; password = answers.password; } console.log(chalk_1.default.gray('Authenticating...')); const response = await apiService.login(email, password); if (response.success && response.data?.user?.apiKey) { await configService.saveGlobalConfig({ apiKey: response.data.user.apiKey }); console.log(chalk_1.default.green('Login successful!')); console.log(chalk_1.default.gray(`Welcome back, ${response.data.user.username || email}`)); } else { throw new Error(response.error?.message || 'Login failed'); } } catch (error) { console.error(chalk_1.default.red('Login failed:'), error instanceof Error ? error.message : error); process.exit(1); } } //# sourceMappingURL=login.js.map