cdp-docs-cli
Version:
CLI tool to set up CDP (Coinbase Developer Platform) documentation and integration in your project
212 lines (210 loc) ⢠8.94 kB
JavaScript
;
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.CdpDocsCli = void 0;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const chalk_1 = __importDefault(require("chalk"));
class CdpDocsCli {
constructor() {
this.templatePath = path.join(__dirname, '..', 'src', 'templates');
}
/**
* Setup CDP documentation in the target project
*/
async setupDocs(options = {}) {
const projectRoot = options.projectRoot || process.cwd();
const docsPath = options.docsPath || path.join(projectRoot, 'doc', 'cdp');
console.log(chalk_1.default.blue('š Setting up CDP documentation...'));
try {
// Create the docs directory structure
await this.createDirectoryStructure(docsPath, options.force);
// Copy documentation files
await this.copyDocumentationFiles(docsPath);
// Copy prompt/integration files
await this.copyIntegrationFiles(docsPath);
console.log(chalk_1.default.green('ā
CDP 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 cdp-setup # Run interactive CDP integration setup'));
console.log(chalk_1.default.white(' - npx cdp-docs # Show available documentation'));
}
catch (error) {
console.error(chalk_1.default.red('ā Error setting up CDP documentation:'), error);
throw error;
}
}
/**
* Create the directory structure for CDP docs
*/
async createDirectoryStructure(docsPath, force = false) {
const dirsToCreate = [
docsPath,
path.join(docsPath, 'wallet'),
path.join(docsPath, 'integration'),
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, 'wallet');
if (await fs.pathExists(docsSourcePath)) {
await fs.copy(docsSourcePath, docsTargetPath, { overwrite: true });
console.log(chalk_1.default.green('š Copied wallet documentation files'));
}
else {
console.log(chalk_1.default.yellow('ā ļø Wallet docs template not found'));
}
}
/**
* Copy integration files from templates
*/
async copyIntegrationFiles(docsPath) {
const promptSourcePath = path.join(this.templatePath, 'prompt');
const promptTargetPath = path.join(docsPath, 'integration');
if (await fs.pathExists(promptSourcePath)) {
await fs.copy(promptSourcePath, promptTargetPath, { overwrite: true });
console.log(chalk_1.default.green('š§ Copied integration documentation files'));
}
else {
console.log(chalk_1.default.yellow('ā ļø Integration docs template not found'));
}
}
/**
* Install CDP dependencies
*/
async installDependencies(projectRoot = process.cwd()) {
console.log(chalk_1.default.blue('š¦ Installing CDP 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 = [
'@coinbase/cdp-sdk',
'dotenv',
'viem'
];
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 = `# CDP (Coinbase Developer Platform) 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
CDP_WALLET_SECRET=your_actual_wallet_secret_here
# Network configuration (optional)
# CDP_NETWORK_ID=base-sepolia # Use base-sepolia for testing, base-mainnet for production
`;
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', 'cdp');
if (!await fs.pathExists(docsPath)) {
console.log(chalk_1.default.yellow('š CDP documentation not found.'));
console.log(chalk_1.default.cyan('Run: npx cdp-docs setup'));
return;
}
console.log(chalk_1.default.blue('š Available CDP Documentation:'));
console.log('');
const walletPath = path.join(docsPath, 'wallet');
const integrationPath = path.join(docsPath, 'integration');
if (await fs.pathExists(walletPath)) {
console.log(chalk_1.default.green('š Wallet API Documentation:'));
const walletFiles = await fs.readdir(walletPath);
walletFiles.forEach((file) => {
if (file.endsWith('.md')) {
console.log(chalk_1.default.white(` - ${file}`));
}
});
console.log('');
}
if (await fs.pathExists(integrationPath)) {
console.log(chalk_1.default.green('āļø Integration Guides:'));
const integrationFiles = await fs.readdir(integrationPath);
integrationFiles.forEach((file) => {
if (file.endsWith('.md')) {
console.log(chalk_1.default.white(` - ${file}`));
}
});
}
}
}
exports.CdpDocsCli = CdpDocsCli;
//# sourceMappingURL=index.js.map