Skip to content

Commit 66c0bbd

Browse files
authored
Merge pull request #13 from macalinao/igm/coda-create
Add Coda create template package
2 parents 55299df + 74221c5 commit 66c0bbd

File tree

110 files changed

+22381
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+22381
-26
lines changed

.changeset/eager-planets-jam.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@macalinao/clients-orca-whirlpools": minor
3+
"@macalinao/create-coda": minor
4+
---
5+
6+
Add create-coda package

.changeset/eight-animals-win.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@macalinao/clients-orca-whirlpools": patch
3+
"@macalinao/clients-kamino-lending": patch
4+
"@macalinao/create-coda": patch
5+
"coda-docs": patch
6+
---
7+
8+
Docs

apps/docs/content/docs/meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"title": "Documentation",
2+
"title": "Coda Documentation",
33
"pages": [
4-
"---Introduction---",
54
"index",
65
"why-coda",
76
"installation",
87
"quick-start",
98
"---Using Coda---",
9+
"create-coda",
1010
"configuration",
1111
"generating-clients",
1212
"generating-docs",
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
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

apps/docs/content/docs/packages/index.mdx

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,40 @@ description: Core packages that power Coda's client generation capabilities
55

66
Coda is built as a modular system of packages that work together to generate high-quality TypeScript clients from Solana IDLs. Each package serves a specific purpose in the generation pipeline.
77

8-
## Core Package
8+
## Core Packages
99

1010
### [@macalinao/coda](/docs/packages/coda)
11+
1112
The main CLI tool for generating TypeScript clients from Anchor IDLs. Works out of the box with sensible defaults and extensible configuration.
1213

14+
### [@macalinao/create-coda](/docs/packages/create-coda)
15+
16+
Project scaffolding tool that bootstraps new Coda client projects with TypeScript, ESLint, and all configurations pre-set.
17+
1318
## Parsers
1419

1520
### [@macalinao/codama-nodes-from-anchor-x](/docs/packages/codama-nodes-from-anchor-x)
21+
1622
Creates Codama root nodes from multiple Anchor IDLs with enhanced support for various IDL versions.
1723

1824
## Visitors
1925

2026
### [@macalinao/codama-instruction-accounts-dedupe-visitor](/docs/packages/codama-instruction-accounts-dedupe-visitor)
27+
2128
Flattens nested account structures from Anchor IDLs while preserving relationships through naming conventions.
2229

2330
### [@macalinao/codama-rename-visitor](/docs/packages/codama-rename-visitor)
31+
2432
Renames accounts, instructions, and defined types in the Codama AST to avoid conflicts and customize naming.
2533

2634
## Renderers
2735

2836
### [@macalinao/codama-renderers-js-esm](/docs/packages/codama-renderers-js-esm)
37+
2938
ESM-native TypeScript renderer that generates modern JavaScript modules with proper `.js` extensions.
3039

3140
### [@macalinao/codama-renderers-markdown](/docs/packages/codama-renderers-markdown)
41+
3242
Generates comprehensive Markdown documentation from Codama AST nodes, perfect for API documentation.
3343

3444
## Package Architecture
@@ -44,18 +54,56 @@ Each package in the Coda ecosystem follows a consistent structure:
4454

4555
Each package can be installed individually based on your needs:
4656

57+
### Create a New Project (Recommended)
58+
59+
```bash
60+
# Using npm
61+
npm create @macalinao/create-coda@latest my-client
62+
63+
# Using bun
64+
bun create @macalinao/create-coda my-client
65+
```
66+
67+
### Install the Main CLI
68+
4769
```bash
48-
# Install the main CLI
70+
# Using npm
71+
npm install -D @macalinao/coda
72+
73+
# Using bun
4974
bun add -D @macalinao/coda
75+
```
5076

51-
# Install parsers
77+
### Install Parsers
78+
79+
```bash
80+
# Using npm
81+
npm install @macalinao/codama-nodes-from-anchor-x
82+
83+
# Using bun
5284
bun add @macalinao/codama-nodes-from-anchor-x
85+
```
86+
87+
### Install Visitors
5388

54-
# Install visitors
89+
```bash
90+
# Using npm
91+
npm install @macalinao/codama-instruction-accounts-dedupe-visitor
92+
npm install @macalinao/codama-rename-visitor
93+
94+
# Using bun
5595
bun add @macalinao/codama-instruction-accounts-dedupe-visitor
5696
bun add @macalinao/codama-rename-visitor
97+
```
98+
99+
### Install Renderers
57100

58-
# Install renderers
101+
```bash
102+
# Using npm
103+
npm install @macalinao/codama-renderers-js-esm
104+
npm install @macalinao/codama-renderers-markdown
105+
106+
# Using bun
59107
bun add @macalinao/codama-renderers-js-esm
60108
bun add @macalinao/codama-renderers-markdown
61109
```
@@ -73,4 +121,4 @@ bun test
73121

74122
# Fix linting issues
75123
bun run lint:fix
76-
```
124+
```

apps/docs/content/docs/packages/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"title": "Packages",
33
"pages": [
44
"index",
5-
"---Core Package---",
5+
"---Core Packages---",
66
"coda",
7+
"create-coda",
78
"---Parsers---",
89
"codama-nodes-from-anchor-x",
910
"---Visitors---",

0 commit comments

Comments
 (0)