Skip to content

Commit a31e599

Browse files
Added top-level CLAUDE.md file (#581)
no issue - basic file created with `/init` - checked for accuracy and made minor corrections
1 parent c56862c commit a31e599

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

CLAUDE.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Repository Overview
6+
7+
The Ghost SDK is a monorepo containing a collection of JavaScript/TypeScript packages for interacting with Ghost's APIs. It uses Lerna for monorepo management and Yarn workspaces.
8+
9+
## Common Development Commands
10+
11+
### Setup & Installation
12+
- **Initial setup**: `yarn setup` (mapped to `lerna bootstrap`)
13+
- Installs all external dependencies
14+
- Links all internal dependencies
15+
- **Install dependencies**: `yarn`
16+
17+
### Testing
18+
- **Run all tests**: `yarn test` (runs `lerna run test`)
19+
- This runs tests in all packages
20+
- **Run tests in specific package**: `cd packages/<package-name> && yarn test`
21+
- **Run tests with coverage**: Most packages use `NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'`
22+
- **Run specific test file**: `NODE_ENV=testing mocha './test/specific.test.js'`
23+
- **Run tests matching pattern**: `NODE_ENV=testing mocha './test/**/*.test.js' --grep "pattern"`
24+
25+
### Linting
26+
- **Run all linters**: `yarn lint` (runs `lerna run lint`)
27+
- **Run linter in specific package**: `cd packages/<package-name> && yarn lint`
28+
- **Fix linting issues**: `yarn lint -- --fix`
29+
30+
### Building
31+
- **Build packages with build scripts**: Individual packages have their own build commands
32+
- For packages with Rollup: `yarn build`
33+
- TypeScript packages: Check for `tsconfig.json` and build scripts
34+
35+
### Publishing
36+
- **Publish packages**: `yarn ship` (alias for `lerna publish`)
37+
- Publishes all packages which have changed
38+
- Updates any packages which depend on changed packages
39+
- Use `yarn ship --git-remote upstream` when `origin` points to a fork and `upstream` points to the original TryGhost/SDK repo
40+
41+
## Package Structure
42+
43+
All packages are located in the `/packages` directory:
44+
45+
### API Packages
46+
- **@tryghost/admin-api**: Admin API client for Ghost
47+
- **@tryghost/content-api**: Content API client for Ghost
48+
- **@tryghost/admin-api-schema**: JSON schemas for Admin API
49+
50+
### Utility Packages
51+
- **@tryghost/helpers**: Template helpers (reading time, tags, etc.)
52+
- **@tryghost/helpers-gatsby**: Gatsby-specific helpers
53+
- **@tryghost/url-utils**: URL manipulation utilities
54+
- **@tryghost/string**: String manipulation (slugify, escapeHtml, etc.)
55+
- **@tryghost/color-utils**: Color manipulation utilities
56+
- **@tryghost/config-url-helpers**: URL configuration helpers
57+
- **@tryghost/social-urls**: Social media URL generation
58+
- **@tryghost/schema-org**: Schema.org structured data generation
59+
- **@tryghost/timezone-data**: Timezone data utilities
60+
61+
### Content Processing
62+
- **@tryghost/html-to-plaintext**: HTML to plaintext conversion
63+
- **@tryghost/html-to-mobiledoc**: HTML to Mobiledoc conversion
64+
- **@tryghost/image-transform**: Image transformation utilities
65+
66+
### Infrastructure
67+
- **@tryghost/limit-service**: Centralized limit enforcement
68+
- **@tryghost/adapter-base-cache**: Base cache adapter
69+
- **@tryghost/members-csv**: CSV parsing for members import/export
70+
- **@tryghost/referrer-parser**: Referrer parsing utilities
71+
72+
### Frontend Packages
73+
- **@tryghost/custom-fonts**: Custom font utilities
74+
75+
## Testing Approach
76+
77+
- Testing framework: **Mocha** with **Should.js** for assertions
78+
- Mocking: **Sinon** for stubs and mocks
79+
- Coverage: **c8** for code coverage
80+
- Environment: Set `NODE_ENV=testing` when running tests
81+
82+
### Test Structure
83+
```
84+
packages/<package-name>/
85+
├── test/
86+
│ ├── unit/ # Unit tests (if separated)
87+
│ ├── integration/ # Integration tests (if separated)
88+
│ ├── fixtures/ # Test fixtures and mock data
89+
│ └── utils/ # Test utilities
90+
│ ├── assertions.js
91+
│ ├── index.js
92+
│ └── overrides.js
93+
```
94+
95+
## Adding New Packages
96+
97+
To add a new package to the repo:
98+
1. Install [slimer](https://github.com/TryGhost/slimer)
99+
2. Run `slimer new <package name>`
100+
101+
## Build Systems
102+
103+
Different packages use different build systems:
104+
105+
### Rollup-based packages
106+
- **content-api**, **timezone-data**, **helpers**, **color-utils**
107+
- Build command: `yarn build`
108+
- Configuration: `rollup.config.js`
109+
- Outputs: `cjs/`, `es/`, `umd/` directories
110+
111+
### TypeScript packages
112+
- **color-utils**, **timezone-data**, **custom-fonts**, **referrer-parser**
113+
- Configuration: `tsconfig.json`
114+
- Some use Vite for building
115+
116+
### Plain JavaScript packages
117+
- Most other packages don't require building
118+
- Source in `lib/` directory
119+
120+
## Important Notes
121+
122+
- This is a Yarn workspaces monorepo - always use `yarn`, not `npm`
123+
- The main branch is `master` (not `main`) for pull requests
124+
- All packages are published under the `@tryghost` scope
125+
- Packages have independent versioning
126+
- ESLint configuration uses `eslint-plugin-ghost`
127+
- Most packages follow similar patterns for structure and testing
128+
129+
## Environment Variables
130+
131+
- `NODE_ENV=testing` - Required for running tests
132+
- `GHOST_UPSTREAM` - Set remote for publishing (defaults to `origin`)
133+
134+
## Git Configuration
135+
136+
- Default branch for PRs: `main`
137+
- Publishing allowed from: `main` branch
138+
- Commit message for version updates: "Published new versions"
139+
140+
## Common Patterns
141+
142+
### Error Handling
143+
- Most packages use `@tryghost/errors` for consistent error formatting
144+
145+
### Database Integration
146+
- Packages expecting database access use Knex instances
147+
- Support for transactions via `options.transacting`
148+
149+
### API Versioning
150+
- API packages support multiple versions (v2, v3, v4, v5, v6, canary)
151+
- Version-specific tests in `test/<package>-test/v*.test.js`
152+
153+
## Development Tips
154+
155+
1. Run tests before committing
156+
2. Use `yarn lint` to check code style
157+
3. Follow existing patterns in the codebase
158+
4. Add tests for new functionality
159+
5. Update README.md in package directory for significant changes
160+
6. Use semantic versioning for package updates

0 commit comments

Comments
 (0)