UNPKG

google-oauth-cli-generator

Version:

CLI tool to quickly set up Google OAuth authentication for hackathons and projects

207 lines (180 loc) • 6.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateProject = generateProject; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const react_template_1 = require("./templates/react-template"); const next_template_1 = require("./templates/next-template"); const vanilla_template_1 = require("./templates/vanilla-template"); const express_template_1 = require("./templates/express-template"); const fastify_template_1 = require("./templates/fastify-template"); const mongo_template_1 = require("./templates/mongo-template"); const postgres_template_1 = require("./templates/postgres-template"); const validation_1 = require("../utils/validation"); async function generateProject(config) { const sanitizedName = (0, validation_1.sanitizeProjectName)(config.projectName); const projectPath = path_1.default.resolve(process.cwd(), sanitizedName); // Check if directory already exists if (await fs_extra_1.default.pathExists(projectPath)) { throw new Error(`Directory "${sanitizedName}" already exists`); } // Create project directory await fs_extra_1.default.ensureDir(projectPath); const templateData = { config, projectPath }; try { // Generate frontend templates await generateFrontendTemplate(templateData); // Generate backend templates await generateBackendTemplate(templateData); // Generate database templates if (config.database !== 'none') { await generateDatabaseTemplate(templateData); } // Generate common files await generateCommonFiles(templateData); } catch (error) { // Cleanup on error await fs_extra_1.default.remove(projectPath); throw error; } } async function generateFrontendTemplate(data) { switch (data.config.frontend) { case 'react': await (0, react_template_1.generateReactTemplate)(data); break; case 'next': await (0, next_template_1.generateNextTemplate)(data); break; case 'vanilla': await (0, vanilla_template_1.generateVanillaTemplate)(data); break; default: throw new Error(`Unsupported frontend: ${data.config.frontend}`); } } async function generateBackendTemplate(data) { switch (data.config.backend) { case 'express': await (0, express_template_1.generateExpressTemplate)(data); break; case 'fastify': await (0, fastify_template_1.generateFastifyTemplate)(data); break; default: throw new Error(`Unsupported backend: ${data.config.backend}`); } } async function generateDatabaseTemplate(data) { switch (data.config.database) { case 'mongodb': await (0, mongo_template_1.generateMongoTemplate)(data); break; case 'postgresql': await (0, postgres_template_1.generatePostgresTemplate)(data); break; } } async function generateCommonFiles(data) { const { projectPath, config } = data; // Generate .env template const envContent = `# Google OAuth Configuration GOOGLE_CLIENT_ID=${config.clientId} GOOGLE_CLIENT_SECRET=${config.clientSecret} REDIRECT_URI=${config.redirectUri} # Session Configuration SESSION_SECRET=your-session-secret-here-change-this-in-production # Database Configuration ${config.database === 'mongodb' ? 'MONGODB_URI=mongodb://localhost:27017/auth-app' : ''} ${config.database === 'postgresql' ? 'DATABASE_URL=postgresql://username:password@localhost:5432/auth_app' : ''} # Application Configuration PORT=3000 NODE_ENV=development `; await fs_extra_1.default.writeFile(path_1.default.join(projectPath, '.env.example'), envContent); // Generate .gitignore const gitignoreContent = `node_modules/ .env dist/ build/ *.log .DS_Store coverage/ .nyc_output/ `; await fs_extra_1.default.writeFile(path_1.default.join(projectPath, '.gitignore'), gitignoreContent); // Generate README.md const readmeContent = `# ${config.projectName} Google OAuth authentication setup generated by CipherAI Auth CLI. ## šŸš€ Quick Start 1. Install dependencies: \`\`\`bash npm install \`\`\` 2. Copy environment variables: \`\`\`bash cp .env.example .env \`\`\` 3. Update your \`.env\` file with your actual values 4. Start the development server: \`\`\`bash npm run dev \`\`\` ## šŸ“‹ Configuration ### Google OAuth Setup 1. Go to [Google Cloud Console](https://console.cloud.google.com/) 2. Create a new project or select existing one 3. Go to "APIs & Services" > "Credentials" 4. Create OAuth 2.0 Client ID 5. Add your redirect URI: \`${config.redirectUri}\` ### Environment Variables - \`GOOGLE_CLIENT_ID\`: Your Google OAuth Client ID - \`GOOGLE_CLIENT_SECRET\`: Your Google OAuth Client Secret - \`REDIRECT_URI\`: OAuth redirect URI - \`SESSION_SECRET\`: Secret for session encryption ## šŸ›  Tech Stack - **Frontend**: ${config.frontend} - **Backend**: ${config.backend} - **Database**: ${config.database === 'none' ? 'None (in-memory)' : config.database} ## šŸ“ Project Structure \`\`\` ${config.projectName}/ ā”œā”€ā”€ frontend/ # ${config.frontend} frontend code ā”œā”€ā”€ backend/ # ${config.backend} backend code ${config.database !== 'none' ? 'ā”œā”€ā”€ database/ # Database schemas and config' : ''} ā”œā”€ā”€ .env.example # Environment variables template └── README.md # This file \`\`\` ## šŸ”§ Development ### Frontend Development \`\`\`bash cd frontend npm run dev \`\`\` ### Backend Development \`\`\`bash cd backend npm run dev \`\`\` ## šŸš€ Deployment This setup is ready for deployment to: - Vercel (for Next.js) - Netlify (for React/Vanilla) - Heroku (for backend) - Railway (full-stack) ## šŸ“š Learn More - [Google OAuth 2.0 Documentation](https://developers.google.com/identity/protocols/oauth2) - [Passport.js Google Strategy](http://www.passportjs.org/packages/passport-google-oauth20/) --- Generated with ā¤ļø by [CipherAI Auth CLI](https://github.com/cipherai/auth-setup) `; await fs_extra_1.default.writeFile(path_1.default.join(projectPath, 'README.md'), readmeContent); } //# sourceMappingURL=project-generator.js.map