UNPKG

@stellar/stellar-sdk

Version:

A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.

138 lines (136 loc) 3.33 kB
class ConfigGenerator { /** * Generate the complete TypeScript project */ generate(options) { const { contractName } = options; return { packageJson: this.generatePackageJson(contractName), tsConfig: this.generateTsConfig(), gitignore: this.generateGitignore(), readme: this.generateReadme(contractName) }; } /** * Generate package.json */ generatePackageJson(contractName) { const generatedPackageJson = { name: contractName.toLowerCase().replace(/[^a-z0-9-]/g, "-"), version: "0.0.1", description: `Generated TypeScript bindings for ${contractName} Stellar contract`, type: "module", main: "dist/index.js", types: "dist/index.d.ts", scripts: { build: "tsc" }, dependencies: { "@stellar/stellar-sdk": `^${"16.2.0"}`, buffer: "6.0.3" }, devDependencies: { typescript: "^5.6.3" } }; return JSON.stringify(generatedPackageJson, null, 2); } /** * Generate tsconfig.json */ generateTsConfig() { const tsConfig = { compilerOptions: { target: "ESNext", module: "NodeNext", moduleResolution: "nodenext", declaration: true, outDir: "./dist", strictNullChecks: true, skipLibCheck: true }, include: ["src/*"] }; return JSON.stringify(tsConfig, null, 2); } /** * Generate .gitignore */ generateGitignore() { const gitignore = [ "# Dependencies", "node_modules/", "", "# Build outputs", "dist/", "*.tgz", "", "# IDE", ".vscode/", ".idea/", "", "# OS", ".DS_Store", "Thumbs.db", "", "# Logs", "*.log", "npm-debug.log*", "", "# Runtime data", "*.pid", "*.seed" ].join("\n"); return gitignore; } /** * Generate README.md */ generateReadme(contractName) { const readme = [ `# ${contractName} Contract Bindings`, "", `TypeScript bindings for the ${contractName} Stellar smart contract.`, "", "## Installation", "", "```bash", "npm install", "```", "", "## Build", "", "```bash", "npm run build", "```", "", "## Usage", "", "```typescript", 'import { Client } from "./src";', "", "const client = new Client({", ' contractId: "YOUR_CONTRACT_ID",', ' rpcUrl: "https://soroban-testnet.stellar.org:443",', ' networkPassphrase: "Test SDF Network ; September 2015",', "});", "", "// Call contract methods", "// const result = await client.methodName();", "```", "", "## Generated Files", "", "- `src/index.ts` - Entry point exporting the Client", "- `src/types.ts` - Type definitions for contract structs, enums, and unions", "- `src/contract.ts` - Client implementation", "- `tsconfig.json` - TypeScript configuration", "- `package.json` - NPM package configuration", "", "This package was generated using the Js-Stellar-SDK contract binding generator." ].join("\n"); return readme; } } export { ConfigGenerator }; //# sourceMappingURL=config.js.map