UNPKG

forge-deploy-cli

Version:

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

121 lines 5.05 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.signupCommand = signupCommand; const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); const api_1 = require("../services/api"); const config_1 = require("../services/config"); async function signupCommand(options) { try { console.log(chalk_1.default.blue('Sign up for Forge')); console.log(chalk_1.default.gray('Create a new account to deploy your applications')); console.log(); const configService = new config_1.ConfigService(); // Get API URL from options or config let apiUrl = options.apiUrl; if (!apiUrl) { const globalConfig = await configService.loadGlobalConfig(); apiUrl = globalConfig?.apiUrl || 'https://api.forgecli.tech'; } const apiService = new api_1.ForgeApiService(apiUrl); // Get user input const answers = await inquirer_1.default.prompt([ { type: 'input', name: 'email', message: 'Email:', default: options.email, validate: (input) => { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(input)) { return 'Please enter a valid email address'; } return true; }, when: !options.email }, { type: 'input', name: 'username', message: 'Username (optional):', default: options.username, when: !options.username }, { type: 'password', name: 'password', message: 'Password:', validate: (input) => { if (input.length < 8) { return 'Password must be at least 8 characters long'; } return true; } }, { type: 'password', name: 'confirmPassword', message: 'Confirm password:', validate: (input, answers) => { if (input !== answers.password) { return 'Passwords do not match'; } return true; } } ]); const email = options.email || answers.email; const username = options.username || answers.username; const password = answers.password; console.log(); console.log(chalk_1.default.gray('Creating account...')); // Attempt signup const response = await apiService.signup(email, password, username); if (response.success) { console.log(chalk_1.default.green('Account created successfully!')); if (response.data?.apiKey) { // Save API key if provided const globalConfig = { apiKey: response.data.apiKey, apiUrl, email }; await configService.saveGlobalConfig(globalConfig); console.log(chalk_1.default.green('API key saved to configuration')); } console.log(); console.log(chalk_1.default.blue('Welcome to Forge!')); console.log(chalk_1.default.gray('You can now deploy your applications using "forge deploy"')); if (!response.data?.apiKey) { console.log(chalk_1.default.yellow('Please check your email for verification instructions')); console.log(chalk_1.default.gray('After verification, run "forge login" to get your API key')); } } else { throw new Error(response.error?.message || 'Signup failed'); } } catch (error) { if (error.response?.status === 409) { console.log(chalk_1.default.red('Error: Email already exists')); console.log(chalk_1.default.gray('Try logging in instead: forge login')); } else if (error.response?.status === 400) { console.log(chalk_1.default.red('Error: Invalid input')); console.log(chalk_1.default.gray('Please check your email and password requirements')); } else if (error.response?.data?.error?.message) { console.log(chalk_1.default.red(`Error: ${error.response.data.error.message}`)); } else { console.log(chalk_1.default.red(`Signup failed: ${error.message || error}`)); } console.log(); console.log(chalk_1.default.gray('If you already have an account, use "forge login"')); process.exit(1); } } //# sourceMappingURL=signup.js.map