@macalinao/create-coda 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
package/dist/bin.js ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { cp, mkdir, readdir } from "node:fs/promises";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ async function main() {
8
+ const projectName = process.argv[2] ?? "my-coda-client";
9
+ const targetDir = resolve(process.cwd(), projectName);
10
+ // Check if directory already exists
11
+ if (existsSync(targetDir)) {
12
+ const files = await readdir(targetDir);
13
+ if (files.length > 0) {
14
+ console.error(`Error: Directory ${projectName} already exists and is not empty.`);
15
+ process.exit(1);
16
+ }
17
+ }
18
+ // Create target directory
19
+ await mkdir(targetDir, { recursive: true });
20
+ // Copy template files (template is at the package root, not in dist)
21
+ const templateDir = join(__dirname, "..", "template");
22
+ await cp(templateDir, targetDir, { recursive: true });
23
+ console.log(`✨ Created Coda client project at ${projectName}`);
24
+ console.log("");
25
+ console.log("Next steps:");
26
+ console.log(` cd ${projectName}`);
27
+ console.log(" bun install");
28
+ console.log(" # Add your IDL file to idls/ directory");
29
+ console.log(" bun run codegen");
30
+ console.log(" bun run build");
31
+ console.log("");
32
+ console.log("Happy coding! 🚀");
33
+ }
34
+ main().catch((error) => {
35
+ console.error("Error creating project:", error);
36
+ process.exit(1);
37
+ });
38
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";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;IAChB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,QAAQ,WAAW,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC/B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { existsSync } from \"node:fs\";\nimport { cp, mkdir, readdir } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nasync function main(): Promise<void> {\n const projectName = process.argv[2] ?? \"my-coda-client\";\n const targetDir = resolve(process.cwd(), projectName);\n\n // Check if directory already exists\n if (existsSync(targetDir)) {\n const files = await readdir(targetDir);\n if (files.length > 0) {\n console.error(\n `Error: Directory ${projectName} already exists and is not empty.`,\n );\n process.exit(1);\n }\n }\n\n // Create target directory\n await mkdir(targetDir, { recursive: true });\n\n // Copy template files (template is at the package root, not in dist)\n const templateDir = join(__dirname, \"..\", \"template\");\n await cp(templateDir, targetDir, { recursive: true });\n\n console.log(`✨ Created Coda client project at ${projectName}`);\n console.log(\"\");\n console.log(\"Next steps:\");\n console.log(` cd ${projectName}`);\n console.log(\" bun install\");\n console.log(\" # Add your IDL file to idls/ directory\");\n console.log(\" bun run codegen\");\n console.log(\" bun run build\");\n console.log(\"\");\n console.log(\"Happy coding! 🚀\");\n}\n\nmain().catch((error: unknown) => {\n console.error(\"Error creating project:\", error);\n process.exit(1);\n});\n"]}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@macalinao/create-coda",
3
+ "version": "0.1.0",
4
+ "description": "Create a new Coda client project",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-coda": "./dist/bin.js"
8
+ },
9
+ "main": "./dist/bin.js",
10
+ "files": [
11
+ "dist/",
12
+ "template/"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "clean": "rm -rf dist/ template/node_modules template/dist template/src/generated",
17
+ "lint": "eslint . --cache"
18
+ },
19
+ "keywords": [
20
+ "coda",
21
+ "solana",
22
+ "codama",
23
+ "client",
24
+ "generator",
25
+ "create",
26
+ "template"
27
+ ],
28
+ "license": "MIT",
29
+ "homepage": "https://github.com/macalinao/coda",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/macalinao/coda.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/macalinao/coda/issues"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "devDependencies": {
41
+ "@macalinao/eslint-config": "^5",
42
+ "@macalinao/tsconfig": "^3.2.3",
43
+ "@types/node": "^22.0.0",
44
+ "eslint": "^9.33.0",
45
+ "typescript": "^5.9.2"
46
+ }
47
+ }
@@ -0,0 +1,63 @@
1
+ # My Coda Client
2
+
3
+ TypeScript client for Solana program generated with [Coda](https://github.com/macalinao/coda).
4
+
5
+ ## Getting Started
6
+
7
+ 1. **Add your IDL file(s)**
8
+ - Place your Anchor IDL JSON file(s) in the `idls/` directory
9
+ - Remove the example.json file
10
+
11
+ 2. **Generate the client code**
12
+ ```bash
13
+ bun run codegen
14
+ ```
15
+
16
+ 3. **Build the project**
17
+ ```bash
18
+ bun run build
19
+ ```
20
+
21
+ ## Project Structure
22
+
23
+ ```
24
+ .
25
+ ├── idls/ # Anchor IDL files
26
+ ├── src/
27
+ │ ├── generated/ # Generated client code (do not edit)
28
+ │ └── index.ts # Main entry point
29
+ ├── coda.config.mjs # Coda configuration
30
+ └── package.json
31
+ ```
32
+
33
+ ## Available Scripts
34
+
35
+ - `bun run codegen` - Generate TypeScript client from IDL
36
+ - `bun run build` - Build the TypeScript project
37
+ - `bun run clean` - Clean build artifacts
38
+ - `bun run lint` - Run ESLint
39
+ - `bun test` - Run tests
40
+
41
+ ## Configuration
42
+
43
+ Edit `coda.config.mjs` to customize:
44
+ - IDL discovery patterns
45
+ - Output directory
46
+ - Custom PDAs and visitors
47
+
48
+ ## Usage
49
+
50
+ ```typescript
51
+ import { createInitializeInstruction } from "./dist/index.js";
52
+
53
+ // Use the generated client
54
+ const instruction = createInitializeInstruction({
55
+ // ... instruction parameters
56
+ });
57
+ ```
58
+
59
+ ## Learn More
60
+
61
+ - [Coda Documentation](https://github.com/macalinao/coda)
62
+ - [Codama Documentation](https://github.com/codama-idl/codama)
63
+ - [Anchor Framework](https://www.anchor-lang.com/)
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from "@macalinao/coda";
2
+
3
+ export default defineConfig({
4
+ // Coda will automatically discover IDLs from ./idls/*.json
5
+ // You can override this by specifying a custom path:
6
+ // idlPath: "./idls/my_program.json",
7
+
8
+ // For multiple IDLs, use a glob pattern or array:
9
+ // idlPath: "./idls/*.json",
10
+ // idlPath: ["./idls/program1.json", "./idls/program2.json"],
11
+
12
+ // Output directory for generated code (default: "./src/generated")
13
+ outputDir: "./src/generated",
14
+
15
+ // Optional: Add custom Codama visitors for advanced customization
16
+ // visitors: [
17
+ // addPdasVisitor({
18
+ // // Define custom PDAs here
19
+ // })
20
+ // ]
21
+ });
@@ -0,0 +1,31 @@
1
+ import { configs } from "@macalinao/eslint-config";
2
+
3
+ export default [
4
+ ...configs.fast,
5
+ {
6
+ languageOptions: {
7
+ parserOptions: {
8
+ tsconfigRootDir: import.meta.dirname,
9
+ },
10
+ },
11
+ },
12
+ {
13
+ files: ["src/generated/**/*.ts"],
14
+ rules: {
15
+ "@typescript-eslint/no-non-null-assertion": "off",
16
+ "@typescript-eslint/prefer-nullish-coalescing": "off",
17
+ },
18
+ },
19
+ {
20
+ files: [
21
+ "src/generated/instructions/*.ts",
22
+ "src/generated/types/*.ts",
23
+ "src/generated/errors/*.ts",
24
+ ],
25
+ rules: {
26
+ "@typescript-eslint/no-unnecessary-condition": "off",
27
+ "no-constant-condition": "off",
28
+ "@typescript-eslint/no-empty-object-type": "off",
29
+ },
30
+ },
31
+ ];
@@ -0,0 +1,79 @@
1
+ {
2
+ "version": "0.1.0",
3
+ "name": "example",
4
+ "instructions": [
5
+ {
6
+ "name": "Initialize",
7
+ "accounts": [
8
+ {
9
+ "name": "payer",
10
+ "isMut": true,
11
+ "isSigner": true
12
+ },
13
+ {
14
+ "name": "state",
15
+ "isMut": true,
16
+ "isSigner": false
17
+ },
18
+ {
19
+ "name": "systemProgram",
20
+ "isMut": false,
21
+ "isSigner": false
22
+ }
23
+ ],
24
+ "args": [
25
+ {
26
+ "name": "data",
27
+ "type": "u64"
28
+ }
29
+ ]
30
+ },
31
+ {
32
+ "name": "Update",
33
+ "accounts": [
34
+ {
35
+ "name": "authority",
36
+ "isMut": false,
37
+ "isSigner": true
38
+ },
39
+ {
40
+ "name": "state",
41
+ "isMut": true,
42
+ "isSigner": false
43
+ }
44
+ ],
45
+ "args": [
46
+ {
47
+ "name": "newData",
48
+ "type": "u64"
49
+ }
50
+ ]
51
+ }
52
+ ],
53
+ "accounts": [
54
+ {
55
+ "name": "State",
56
+ "type": {
57
+ "kind": "struct",
58
+ "fields": [
59
+ {
60
+ "name": "authority",
61
+ "type": "publicKey"
62
+ },
63
+ {
64
+ "name": "data",
65
+ "type": "u64"
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ],
71
+ "types": [],
72
+ "errors": [
73
+ {
74
+ "code": 6000,
75
+ "name": "Unauthorized",
76
+ "msg": "Unauthorized access"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "my-coda-client",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript client for Solana program",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "license": "Apache-2.0",
8
+ "keywords": [
9
+ "coda",
10
+ "solana",
11
+ "client",
12
+ "typescript"
13
+ ],
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/",
24
+ "src/"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "clean": "rm -fr dist/ tsconfig.tsbuildinfo",
29
+ "codegen": "rm -fr src/generated/ && coda generate",
30
+ "lint": "eslint . --cache"
31
+ },
32
+ "peerDependencies": {
33
+ "@solana/kit": "*"
34
+ },
35
+ "devDependencies": {
36
+ "@macalinao/coda": "^0.2.3",
37
+ "@macalinao/eslint-config": "^5",
38
+ "@macalinao/tsconfig": "^3.2.3",
39
+ "@solana/kit": "*",
40
+ "@types/bun": "latest",
41
+ "eslint": "^9.0.0",
42
+ "typescript": "^5.0.0"
43
+ }
44
+ }
@@ -0,0 +1,2 @@
1
+ // Re-export all generated code
2
+ export * from "./generated/index.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@macalinao/tsconfig/tsconfig.base.json"
3
+ }