UNPKG

onramp-docs-cli

Version:

CLI tool to set up Onramp documentation and integration in your project

183 lines (181 loc) • 7.55 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OnrampDocs = void 0; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const chalk_1 = __importDefault(require("chalk")); class OnrampDocs { constructor() { this.templatePath = path.join(__dirname, '..', 'src', 'templates'); } /** * Setup Onramp documentation in the target project */ async setupDocs(options = {}) { const projectRoot = options.projectRoot || process.cwd(); const docsPath = options.docsPath || path.join(projectRoot, 'doc', 'onramp'); console.log(chalk_1.default.blue('šŸš€ Setting up Onramp documentation...')); try { // Create the docs directory structure await this.createDirectoryStructure(docsPath, options.force); // Copy documentation files await this.copyDocumentationFiles(docsPath); console.log(chalk_1.default.green('āœ… Onramp documentation setup complete!')); console.log(chalk_1.default.yellow(`šŸ“ Documentation created at: ${docsPath}`)); console.log(chalk_1.default.cyan('\nšŸ“š Available commands:')); console.log(chalk_1.default.white(' - npx onramp-setup # Run interactive setup')); console.log(chalk_1.default.white(' - npx onramp-docs # Show available documentation')); } catch (error) { console.error(chalk_1.default.red('āŒ Error setting up Onramp documentation:'), error); throw error; } } /** * Create the directory structure for Onramp docs */ async createDirectoryStructure(docsPath, force = false) { const dirsToCreate = [ docsPath, path.join(docsPath, 'onramp'), path.join(docsPath, 'examples') ]; for (const dir of dirsToCreate) { if (await fs.pathExists(dir) && !force) { console.log(chalk_1.default.yellow(`āš ļø Directory already exists: ${dir}`)); } else { await fs.ensureDir(dir); console.log(chalk_1.default.green(`šŸ“ Created directory: ${dir}`)); } } } /** * Copy documentation files from templates */ async copyDocumentationFiles(docsPath) { const docsSourcePath = path.join(this.templatePath, 'docs'); const docsTargetPath = path.join(docsPath, 'onramp'); if (await fs.pathExists(docsSourcePath)) { await fs.copy(docsSourcePath, docsTargetPath, { overwrite: true }); console.log(chalk_1.default.green('šŸ“– Copied onramp documentation files')); } else { console.log(chalk_1.default.yellow('āš ļø Onramp docs template not found')); } } /** * Install Onramp dependencies */ async installDependencies(projectRoot = process.cwd()) { console.log(chalk_1.default.blue('šŸ“¦ Installing Onramp dependencies...')); const packageJsonPath = path.join(projectRoot, 'package.json'); if (!await fs.pathExists(packageJsonPath)) { throw new Error('package.json not found. Please run this command in a Node.js project directory.'); } const dependencies = [ 'axios', 'dotenv' ]; const devDependencies = [ '@types/node' ]; try { const { execSync } = require('child_process'); console.log(chalk_1.default.blue('Installing runtime dependencies...')); execSync(`npm install ${dependencies.join(' ')}`, { stdio: 'inherit', cwd: projectRoot }); console.log(chalk_1.default.blue('Installing dev dependencies...')); execSync(`npm install -D ${devDependencies.join(' ')}`, { stdio: 'inherit', cwd: projectRoot }); console.log(chalk_1.default.green('āœ… Dependencies installed successfully!')); } catch (error) { console.error(chalk_1.default.red('āŒ Error installing dependencies:'), error); throw error; } } /** * Create environment file template */ async createEnvTemplate(projectRoot = process.cwd()) { const envPath = path.join(projectRoot, '.env.local.example'); const envContent = `# Onramp Configuration # Get these values from https://portal.cdp.coinbase.com/ # Your CDP API credentials CDP_API_KEY_ID=your_actual_key_id_here CDP_API_KEY_SECRET=your_actual_key_secret_here # Onramp configuration ONRAMP_PROJECT_ID=your_project_id_here `; await fs.writeFile(envPath, envContent); console.log(chalk_1.default.green(`šŸ” Created environment template: ${envPath}`)); console.log(chalk_1.default.yellow('šŸ“ Copy this to .env.local and add your actual CDP credentials')); } /** * List available documentation */ async listDocs(projectRoot = process.cwd()) { const docsPath = path.join(projectRoot, 'doc', 'onramp'); if (!await fs.pathExists(docsPath)) { console.log(chalk_1.default.yellow('šŸ“š Onramp documentation not found.')); console.log(chalk_1.default.cyan('Run: npx onramp-docs setup')); return; } console.log(chalk_1.default.blue('šŸ“š Available Onramp Documentation:')); console.log(''); const onrampPath = path.join(docsPath, 'onramp'); if (await fs.pathExists(onrampPath)) { console.log(chalk_1.default.green('šŸ”— Onramp Documentation:')); const onrampFiles = await fs.readdir(onrampPath); onrampFiles.forEach((file) => { if (file.endsWith('.md')) { console.log(chalk_1.default.white(` - ${file}`)); } }); console.log(''); } } } exports.OnrampDocs = OnrampDocs; //# sourceMappingURL=index.js.map