Skip to content

Commit 6332def

Browse files
authored
Tong/add vault route (#258)
* chore(build): create routes folder * chore(build): add vault route * chore(build): add lint for route vault * chore(build): update doc * chore(build): add FF
1 parent 8c1a639 commit 6332def

File tree

16 files changed

+316
-35
lines changed

16 files changed

+316
-35
lines changed
File renamed without changes.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
This repository is a monorepo for Babylon Labs TypeScript applications and libraries. It uses [Nx](https://nx.dev/) to manage multiple packages, allowing for efficient development and deployment of TypeScript-based projects.
1616

17-
# Contributing
18-
Please follow the guidelines outlined in the [CONTRIBUTING.md](CONTRIBUTING.md) file.
17+
# Development
18+
Please follow the guidelines outlined in the [DEVELOPMENT.md](DEVELOPMENT.md) file.
1919

2020
# Working with simple-staking
2121

package-lock.json

Lines changed: 55 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"workspaces": [
4141
"packages/*",
4242
"tools/*",
43-
"services/*"
43+
"services/*",
44+
"routes/*"
4445
],
4546
"overrides": {
4647
"axios": "^1.12.2",

packages/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Packages
2+
3+
This folder contains reusable library packages that are **built as distributable artifacts** and published to npm. These packages provide shared functionality across the Babylon ecosystem.
4+
5+
## Package Architecture
6+
7+
```
8+
packages/
9+
├── README.md # This file
10+
├── babylon-core-ui/ # Shared UI components
11+
│ ├── package.json # Build artifacts exports
12+
│ ├── tsconfig.json # Library build config for your IDE
13+
│ ├── tsconfig.lib.json # Library build config for the build process and type checking
14+
│ ├── vite.config.ts # Bundle configuration
15+
│ ├── src/ # Source code
16+
│ └── dist/ # Built artifacts (generated)
17+
├── babylon-wallet-connector/ # Wallet integration
18+
├── babylon-proto-ts/ # Protocol definitions
19+
├── babylon-campaigns/ # Campaign functionality
20+
└── babylon-bsn-registry/ # BSN registry utilities
21+
```
22+
23+
## Usage
24+
25+
### Consuming Packages
26+
27+
```typescript
28+
// In services or other packages
29+
import { Card, Button } from "@babylonlabs-io/core-ui";
30+
import { useWalletConnect } from "@babylonlabs-io/wallet-connector";
31+
import type { StakingParams } from "@babylonlabs-io/babylon-proto-ts";
32+
```
33+
34+
### Adding Dependencies
35+
36+
```json
37+
// services/simple-staking/package.json
38+
{
39+
"dependencies": {
40+
"@babylonlabs-io/core-ui": "*",
41+
"@babylonlabs-io/wallet-connector": "*"
42+
}
43+
}
44+
```
45+
46+
### Development Workflow
47+
48+
1. **Make changes** to package source code
49+
2. **Build package**: `npm run build` (generates dist/)
50+
3. **Test locally**: Changes will need to be rebuilt to be reflected in consuming packages
51+
4. **Release**: Semantic release handles versioning and npm publishing
52+
53+
### Creating a New Package
54+
55+
1. **Create package structure:**
56+
```bash
57+
mkdir packages/my-package
58+
cd packages/my-package
59+
```
60+
61+
2. **Setup package.json with build exports:**
62+
```json
63+
{
64+
"name": "@babylonlabs-io/my-package",
65+
"main": "dist/index.cjs.js",
66+
"types": "dist/index.d.ts",
67+
"exports": {
68+
".": {
69+
"types": "./dist/index.d.ts",
70+
"require": "./dist/index.cjs.js",
71+
"import": "./dist/index.es.js"
72+
}
73+
}
74+
}
75+
```
76+
77+
3. **Configure build process** (Vite, TypeScript, etc.)
78+
79+
4. **Add to nx release configuration** for publishing
80+
81+
### Important Notes
82+
83+
- Packages export **built artifacts** from `dist/` directory
84+
- Follow semantic versioning for breaking changes
85+
- Each package should have its own build and test configuration
86+
- Packages can depend on other packages in the monorepo

routes/.gitkeep

Whitespace-only changes.

routes/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Routes
2+
3+
This folder contains route packages that define React components for different application routes. Unlike other packages in the monorepo, route packages are consumed as **source code** rather than built artifacts.
4+
5+
## Key Differences compared to `packages/`
6+
7+
| Aspect | `packages/` | `routes/` |
8+
|--------|-------------|-----------|
9+
| **Purpose** | Reusable libraries published to npm | Route-specific React components |
10+
| **Consumption** | Built artifacts (dist/) | Source code (src/) |
11+
| **Build Process** | Individual build step required | No build - bundled by consuming service |
12+
| **Hot Reloading** | Requires rebuild for changes | Instant hot reload in development |
13+
| **Distribution** | Published to npm registry | Internal workspace only |
14+
15+
## Architecture
16+
17+
```
18+
routes/
19+
├── README.md # This file
20+
├── vault/ # Vault route package
21+
│ ├── package.json # Source code exports
22+
│ ├── tsconfig.json # TypeScript config (no path mapping)
23+
│ ├── eslint.config.mjs # Shared ESLint config
24+
│ └── src/
25+
│ ├── index.ts # Main exports
26+
│ └── VaultLayout.tsx # Route components
27+
└── [future-route]/ # Additional routes...
28+
```
29+
30+
## Usage
31+
32+
### Adding a New Route
33+
34+
1. **Create route package structure:**
35+
```bash
36+
mkdir routes/my-route
37+
cd routes/my-route
38+
```
39+
40+
2. **Setup package.json with source exports:**
41+
```json
42+
{
43+
"name": "@routes/my-route",
44+
"main": "src/index.ts",
45+
"types": "src/index.ts",
46+
"exports": {
47+
".": {
48+
"types": "./src/index.ts",
49+
"default": "./src/index.ts"
50+
}
51+
}
52+
}
53+
```
54+
55+
3. **Add to service dependencies:**
56+
```json
57+
// services/simple-staking/package.json
58+
{
59+
"dependencies": {
60+
"@routes/my-route": "*"
61+
}
62+
}
63+
```
64+
65+
4. **Import and use:**
66+
```typescript
67+
// services/simple-staking/src/ui/router.tsx
68+
import { MyRouteLayout } from "@routes/my-route";
69+
70+
<Route path="my-route" element={<MyRouteLayout />} />
71+
```
72+
73+
### Important Notes
74+
75+
- Route packages should use **relative imports** (no path mapping like `@/*`)
76+
- No build step is needed - services bundle the source code directly

routes/vault/eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "eslint/config";
2+
import { reactConfig } from "@internal/eslint-config/react";
3+
4+
export default defineConfig([
5+
...reactConfig,
6+
{
7+
rules: {
8+
"tailwindcss/no-custom-classname": 0,
9+
},
10+
}
11+
]);

routes/vault/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@routes/vault",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"main": "src/index.ts",
7+
"types": "src/index.ts",
8+
"exports": {
9+
".": {
10+
"types": "./src/index.ts",
11+
"default": "./src/index.ts"
12+
}
13+
},
14+
"scripts": {
15+
"build": "echo 'Skipping build for route package. Bundling happens from the service package.'",
16+
"lint": "eslint",
17+
"lint:fix": "eslint --fix",
18+
"typecheck": "tsc --noEmit"
19+
},
20+
"peerDependencies": {
21+
"react": "18.3.1",
22+
"react-dom": "18.3.1",
23+
"tailwind-merge": "2.5.4"
24+
},
25+
"dependencies": {
26+
"@babylonlabs-io/core-ui": "*",
27+
"@babylonlabs-io/wallet-connector": "*",
28+
"react-router": "7.6.3"
29+
},
30+
"devDependencies": {
31+
"@internal/eslint-config": "*",
32+
"@types/react": "^18.3.12",
33+
"@types/react-dom": "^18.3.1",
34+
"typescript": "^5.8.3"
35+
}
36+
}

routes/vault/src/VaultLayout.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Card } from "@babylonlabs-io/core-ui";
2+
3+
export default function VaultLayout() {
4+
return (
5+
<div className="container mx-auto flex max-w-[760px] flex-1 flex-col gap-12 px-4">
6+
<Card className="bg-surface flex flex-col gap-6 p-6">
7+
<h1 className="text-primary text-2xl font-bold">hello vault</h1>
8+
</Card>
9+
</div>
10+
);
11+
}

0 commit comments

Comments
 (0)