|
| 1 | +--- |
| 2 | +title: "@macalinao/create-coda" |
| 3 | +description: Project scaffolding tool for Coda client projects |
| 4 | +--- |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +`@macalinao/create-coda` is a project scaffolding tool that helps you bootstrap new TypeScript clients for Solana programs. It sets up a complete project structure with TypeScript, ESLint, and Coda pre-configured, allowing you to start generating clients immediately. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +The package is designed to be used with create commands from any package manager: |
| 13 | + |
| 14 | +```bash |
| 15 | +# Using npm |
| 16 | +npm create @macalinao/create-coda@latest my-project |
| 17 | + |
| 18 | +# Using bun |
| 19 | +bun create @macalinao/create-coda my-project |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +### Basic Usage |
| 25 | + |
| 26 | +Create a new Coda client project: |
| 27 | + |
| 28 | +```bash |
| 29 | +# Using npm |
| 30 | +npm create @macalinao/create-coda@latest my-client |
| 31 | + |
| 32 | +# Using bun |
| 33 | +bun create @macalinao/create-coda my-client |
| 34 | +``` |
| 35 | + |
| 36 | +This will create a new directory called `my-client` with a complete project setup. |
| 37 | + |
| 38 | +### Custom Directory Name |
| 39 | + |
| 40 | +You can specify any name for your project: |
| 41 | + |
| 42 | +```bash |
| 43 | +# Using npm |
| 44 | +npm create @macalinao/create-coda@latest my-awesome-dex |
| 45 | +npm create @macalinao/create-coda@latest lending-protocol |
| 46 | +npm create @macalinao/create-coda@latest nft-marketplace |
| 47 | + |
| 48 | +# Using bun |
| 49 | +bun create @macalinao/create-coda my-awesome-dex |
| 50 | +bun create @macalinao/create-coda lending-protocol |
| 51 | +bun create @macalinao/create-coda nft-marketplace |
| 52 | +``` |
| 53 | + |
| 54 | +## What's Included |
| 55 | + |
| 56 | +The scaffolded project includes: |
| 57 | + |
| 58 | +### Project Structure |
| 59 | + |
| 60 | +``` |
| 61 | +my-client/ |
| 62 | +├── idls/ # Anchor IDL files |
| 63 | +│ └── example.json # Example IDL to demonstrate usage |
| 64 | +├── src/ |
| 65 | +│ ├── generated/ # Generated client code (after codegen) |
| 66 | +│ └── index.ts # Main entry point |
| 67 | +├── coda.config.mjs # Coda configuration |
| 68 | +├── tsconfig.json # TypeScript configuration |
| 69 | +├── eslint.config.js # ESLint configuration |
| 70 | +├── package.json # Dependencies and scripts |
| 71 | +├── README.md # Project documentation |
| 72 | +└── .gitignore # Git ignore patterns |
| 73 | +``` |
| 74 | + |
| 75 | +### Pre-configured Dependencies |
| 76 | + |
| 77 | +- **@macalinao/coda** - The Coda CLI for generating clients |
| 78 | +- **@macalinao/eslint-config** - Consistent ESLint configuration |
| 79 | +- **@macalinao/tsconfig** - Shared TypeScript configuration |
| 80 | +- **@solana/kit** - Solana development kit |
| 81 | +- **TypeScript** - For type-safe development |
| 82 | +- **ESLint** - For code quality |
| 83 | + |
| 84 | +### NPM Scripts |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + "scripts": { |
| 89 | + "build": "tsc", |
| 90 | + "clean": "rm -fr dist/ tsconfig.tsbuildinfo", |
| 91 | + "codegen": "rm -fr src/generated/ && coda generate", |
| 92 | + "lint": "eslint . --cache" |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### TypeScript Configuration |
| 98 | + |
| 99 | +Extends `@macalinao/tsconfig` with: |
| 100 | + |
| 101 | +- ES modules with `.js` extensions |
| 102 | +- Strict type checking |
| 103 | +- Modern ES2024 target |
| 104 | +- Source maps and declarations |
| 105 | +- Incremental compilation |
| 106 | + |
| 107 | +### ESLint Configuration |
| 108 | + |
| 109 | +Extends `@macalinao/eslint-config` with: |
| 110 | + |
| 111 | +- TypeScript-specific rules |
| 112 | +- Import organization |
| 113 | +- Special handling for generated code |
| 114 | +- Automatic formatting fixes |
| 115 | + |
| 116 | +### Coda Configuration |
| 117 | + |
| 118 | +Pre-configured `coda.config.mjs` with: |
| 119 | + |
| 120 | +- Automatic IDL discovery from `./idls/*.json` |
| 121 | +- Output to `./src/generated` |
| 122 | +- Ready for custom visitors and PDAs |
| 123 | + |
| 124 | +## Template Customization |
| 125 | + |
| 126 | +The template is designed to be flexible: |
| 127 | + |
| 128 | +### Single IDL Projects |
| 129 | + |
| 130 | +Default configuration works out of the box: |
| 131 | + |
| 132 | +```javascript |
| 133 | +// coda.config.mjs |
| 134 | +export default defineConfig({ |
| 135 | + // Automatically finds IDLs in ./idls/*.json |
| 136 | + outputDir: "./src/generated", |
| 137 | +}); |
| 138 | +``` |
| 139 | + |
| 140 | +### Multiple IDL Projects |
| 141 | + |
| 142 | +Configure for multiple programs: |
| 143 | + |
| 144 | +```javascript |
| 145 | +// coda.config.mjs |
| 146 | +export default defineConfig({ |
| 147 | + idlPath: "./idls/*.json", // Process all IDLs |
| 148 | + outputDir: "./src/generated", |
| 149 | +}); |
| 150 | +``` |
| 151 | + |
| 152 | +### Custom Visitors |
| 153 | + |
| 154 | +Add Codama visitors for enhanced functionality: |
| 155 | + |
| 156 | +```javascript |
| 157 | +// coda.config.mjs |
| 158 | +import { addPdasVisitor } from "codama"; |
| 159 | + |
| 160 | +export default defineConfig({ |
| 161 | + outputDir: "./src/generated", |
| 162 | + visitors: [ |
| 163 | + addPdasVisitor({ |
| 164 | + // Custom PDA definitions |
| 165 | + }), |
| 166 | + ], |
| 167 | +}); |
| 168 | +``` |
| 169 | + |
| 170 | +## Development Workflow |
| 171 | + |
| 172 | +After creating a project with create-coda: |
| 173 | + |
| 174 | +### 1. Install Dependencies |
| 175 | + |
| 176 | +```bash |
| 177 | +cd my-client |
| 178 | +bun install |
| 179 | +``` |
| 180 | + |
| 181 | +### 2. Add Your IDL |
| 182 | + |
| 183 | +Replace the example IDL with your program's IDL: |
| 184 | + |
| 185 | +```bash |
| 186 | +rm idls/example.json |
| 187 | +cp path/to/your/target/idl/program.json idls/ |
| 188 | +``` |
| 189 | + |
| 190 | +### 3. Generate Client |
| 191 | + |
| 192 | +```bash |
| 193 | +bun run codegen |
| 194 | +``` |
| 195 | + |
| 196 | +### 4. Build Project |
| 197 | + |
| 198 | +```bash |
| 199 | +bun run build |
| 200 | +``` |
| 201 | + |
| 202 | +### 5. Use the Client |
| 203 | + |
| 204 | +```typescript |
| 205 | +import { createInitializeInstruction } from "./dist/index.js"; |
| 206 | + |
| 207 | +const ix = createInitializeInstruction({ |
| 208 | + // ... parameters |
| 209 | +}); |
| 210 | +``` |
| 211 | + |
| 212 | +## Package Development |
| 213 | + |
| 214 | +To work on the create-coda package itself: |
| 215 | + |
| 216 | +### Building |
| 217 | + |
| 218 | +```bash |
| 219 | +cd packages/create-coda |
| 220 | +bun run build |
| 221 | +``` |
| 222 | + |
| 223 | +### Testing Locally |
| 224 | + |
| 225 | +```bash |
| 226 | +node ./dist/bin.js test-project |
| 227 | +``` |
| 228 | + |
| 229 | +### Template Files |
| 230 | + |
| 231 | +The template files are located in `packages/create-coda/template/` and are copied when creating new projects. |
| 232 | + |
| 233 | +## Source Code |
| 234 | + |
| 235 | +The create-coda package is part of the Coda monorepo: |
| 236 | + |
| 237 | +- [GitHub Repository](https://github.com/macalinao/coda/tree/master/packages/create-coda) |
| 238 | +- [NPM Package](https://www.npmjs.com/package/@macalinao/create-coda) |
| 239 | + |
| 240 | +## Related Packages |
| 241 | + |
| 242 | +- [**@macalinao/coda**](/docs/packages/coda) - The main Coda CLI |
| 243 | +- [**@macalinao/codama-renderers-js-esm**](/docs/packages/codama-renderers-js-esm) - ESM renderer for Codama |
| 244 | +- [**@macalinao/codama-instruction-accounts-dedupe-visitor**](/docs/packages/codama-instruction-accounts-dedupe-visitor) - Account deduplication visitor |
0 commit comments