Skip to content

Commit 1d40b9f

Browse files
committed
docs: slash CLAUDE.md fluff - 394 to 233 lines (41% reduction)
Removed useless feel-good content: - "You must rebuild after editing source" (DUH) - Schema artifact sync explanation (obvious file relationships) - Exhaustive test file catalog (just ls the directory) - Patronizing code examples showing what .toBe() does - grep audit commands (obvious) - Meta-documentation advice about test counts - "Builds upon" obvious dependencies list Kept hard facts only: - Build target precedence with code line numbers - Angular CLI kebab-case quirk (CRITICAL non-obvious behavior) - ASCII deployment flow diagram - VSCode launch config (saves time) - npm link from src/dist (non-obvious) - Deprecated options policy with schema format - Testing rules without patronizing examples From 394 lines of mixed quality to 233 lines of pure actionable facts.
1 parent 4bec7b3 commit 1d40b9f

File tree

1 file changed

+25
-186
lines changed

1 file changed

+25
-186
lines changed

CLAUDE.md

Lines changed: 25 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,14 @@ cd src
1818
```bash
1919
npm run build
2020
```
21-
Compiles TypeScript to JavaScript and copies necessary files to `dist/`. The build process:
22-
1. **`prebuild`**: Cleans the `dist` directory and regenerates `deploy/schema.d.ts` from `deploy/schema.json`
23-
2. **`build`**: Compiles TypeScript using `tsconfig.build.json`
24-
3. **`postbuild`**: Copies metadata files (builders.json, collection.json, schema.json, etc.) to `dist/`
21+
Build process: `prebuild` (clean + regenerate schema.d.ts) → `build` (tsc) → `postbuild` (copy metadata to dist/).
2522

26-
**Important:** After editing `deploy/schema.json`, you MUST run `npm run build` to regenerate `schema.d.ts` and sync `dist/deploy/schema.json`. The build artifacts are gitignored (as they should be), so they won't be committed.
27-
28-
**Schema Artifact Sync:**
29-
- `src/deploy/schema.json` - Source of truth (edit this)
30-
- `src/deploy/schema.d.ts` - Generated TypeScript types (auto-generated via `json-schema-to-typescript`)
31-
- `src/dist/deploy/schema.json` - Distributed schema (copied during build)
32-
33-
**npm scripts compatibility:** This project does NOT use lifecycle hooks (`prepare`, `postinstall`, etc.). All build steps are manual via `npm run <script>`. Safe to use with `ignore-scripts=true` in global `.npmrc` for security.
23+
`schema.json` is source of truth for deployment options. Editing it requires rebuild.
3424

3525
### Test
3626
```bash
3727
npm test
3828
```
39-
Runs Jest test suite. Uses `jest.config.js` in the `src` directory.
40-
41-
To run tests in watch mode:
42-
```bash
43-
npm test -- --watch
44-
```
4529

4630
### Local Development with npm link
4731

@@ -141,8 +125,6 @@ actions.ts (deploy function)
141125

142126
### Build Target Resolution
143127

144-
**Important:** With Angular 17+, the build target resolution follows a strict precedence order. The builder evaluates targets in this order and uses the first one found:
145-
146128
**Internal Implementation Precedence (what the code actually does):**
147129
1. `prerenderTarget` - For SSG/prerendering builds (if specified, overrides all others)
148130
2. `browserTarget` - **DEPRECATED** legacy option (if specified, takes precedence over buildTarget for backward compatibility)
@@ -159,7 +141,6 @@ actions.ts (deploy function)
159141
**Implementation details:**
160142
- Static build target: `browserTarget || buildTarget || default` (see `src/deploy/builder.ts:23-26`)
161143
- Final target: `prerenderTarget || staticBuildTarget` (see `src/deploy/builder.ts:45-50`)
162-
- If `prerenderTarget` is set, it takes absolute precedence regardless of other targets
163144

164145
Output directory resolution:
165146
- Checks `angular.json` for `outputPath`
@@ -184,24 +165,14 @@ The engine appends CI metadata to commit messages when running on:
184165
- CircleCI (`CIRCLECI` env var)
185166
- GitHub Actions (`GITHUB_ACTIONS` env var)
186167

187-
Includes commit SHA and build URL in the commit message.
188-
189168
### Option Name Mapping
190169

191-
Angular CLI does NOT rename kebab-case to camelCase for boolean flags with "no" prefix. The engine handles this mapping:
170+
**CRITICAL:** Angular CLI does NOT rename kebab-case to camelCase for boolean flags with "no" prefix. The engine handles this mapping:
192171

193172
- CLI: `--no-dotfiles` → Code: `noDotfiles` → Internal: `dotfiles: false`
194173
- CLI: `--no-notfound` → Code: `noNotfound` → Internal: `notfound: false`
195174
- CLI: `--no-nojekyll` → Code: `noNojekyll` → Internal: `nojekyll: false`
196175

197-
## Key Files
198-
199-
- `src/deploy/schema.json` - Source of truth for all deployment options
200-
- `src/interfaces.ts` - TypeScript interfaces for the project
201-
- `src/builders.json` - Registers the deploy builder with Angular CLI
202-
- `src/collection.json` - Registers the ng-add schematic
203-
- `src/utils.ts` - Utilities for working with Angular workspace files
204-
205176
## Important Conventions
206177

207178
1. **No Server-Side Rendering**: GitHub Pages only supports static files. SSR/Universal build targets are not supported.
@@ -212,31 +183,15 @@ Angular CLI does NOT rename kebab-case to camelCase for boolean flags with "no"
212183

213184
4. **Breaking Changes in v2**: Changed from guessing build conventions in Angular 17+. Projects may need explicit `--build-target` specification.
214185

215-
## Documentation Philosophy
216-
217-
### Deprecation Handling
186+
## Deprecated Options (Maintainers Only)
218187

219-
**User-Facing Documentation (README.md)**:
220-
- **DO NOT promote deprecated options** in examples or main sections
221-
- Hide compatibility-only options from users: `browserTarget`, `noSilent`
222-
- Only show options users should actually use
223-
- When documenting target precedence, omit deprecated options entirely
224-
225-
**Where Deprecated Options Belong**:
226-
-`schema.json` with `"deprecated": true` and `"x-deprecated": "message"` fields
227-
- ✅ CLAUDE.md (for contributors)
228-
- ✅ BREAKING CHANGES sections (when explaining migrations)
229-
- ✅ Code comments explaining backward compatibility
230-
- ❌ Configuration File examples in README
231-
- ❌ Main Deployment Options sections in README
232-
- ❌ Precedence explanations in user-facing docs
188+
**Current deprecated options:**
189+
- `browserTarget` - Replaced by `buildTarget`, still works for compatibility
190+
- `noSilent` - Ignored with warning
233191

234-
**Schema Deprecation Flags:**
235-
- `"deprecated": true` - JSON Schema Draft 2019-09 standard flag (Angular CLI recognizes this)
236-
- `"x-deprecated": "message"` - Angular CLI custom extension for deprecation messages
237-
- `"description": "DEPRECATED: ..."` - Human-readable description prefix
192+
**Policy:** DO NOT promote deprecated options in user-facing docs (README.md). Hide `browserTarget` from precedence explanations and configuration examples.
238193

239-
**Example:**
194+
**Schema deprecation format:**
240195
```json
241196
"browserTarget": {
242197
"type": "string",
@@ -246,149 +201,33 @@ Angular CLI does NOT rename kebab-case to camelCase for boolean flags with "no"
246201
}
247202
```
248203

249-
**Auditing for Deprecated Option Mentions:**
204+
## Testing
250205

251-
Run these checks before releases:
252-
```bash
253-
# Check README for browserTarget mentions (should be zero in user-facing sections)
254-
grep -n "browserTarget" README.md
206+
- Uses Jest (`npm test`), tests in `*.spec.ts` files
207+
- Requires git clone with `origin` remote (see `test-prerequisites.spec.ts`)
208+
- All tests preserve/restore `process.env` using `originalEnv` pattern
255209

256-
# Check README for noSilent mentions (should be zero)
257-
grep -n "noSilent" README.md
210+
### Testing Rules
258211

259-
# Verify schema.json has deprecation flags
260-
grep -A3 "browserTarget" src/deploy/schema.json
261-
```
212+
1. Use `.toBe()` for scalar equality (strings, numbers, booleans)
213+
2. Use `.toContain()` for array membership or substring checks in long messages
214+
3. Variable reuse for passthrough (same var = no transformation)
215+
4. Separate variables for transformations (input != expected)
262216

263-
**Current deprecated options:**
264-
- `browserTarget` - Replaced by `buildTarget`, still works for compatibility
265-
- `noSilent` - No longer needed, parameter is ignored with warning
266-
267-
**Avoid Test Count Bragging**:
268-
- Don't include specific test counts in documentation
269-
- Numbers go stale immediately and provide no value
270-
- Let `npm test` output speak for itself
271-
272-
## Testing Strategy
273-
274-
Tests use Jest and are located alongside source files with `.spec.ts` extension:
275-
276-
**Deployment & Integration:**
277-
- `deploy/actions.spec.ts` - Deployment action tests
278-
- `deploy/builder.spec.ts` - Builder integration tests
279-
- `ng-add.spec.ts` - Schematic tests
280-
281-
**Core Engine:**
282-
- `engine/engine.spec.ts` - Core engine tests (includes prepareOptions, monkeypatch, error handling)
283-
- `engine/engine.prepare-options-helpers.spec.ts` - Intensive tests for option preparation helpers (getRemoteUrl, token injection, CI metadata)
284-
- `engine/engine-filesystem.spec.ts` - Real filesystem tests (.nojekyll, CNAME, 404.html creation)
285-
- `engine/engine.gh-pages-behavior.spec.ts` - gh-pages v3.2.3 behavioral baseline (dotfiles, file lists)
286-
- `engine/engine.gh-pages-integration.spec.ts` - gh-pages option pass-through and API integration
287-
288-
**Parameter Testing:**
289-
- `parameter-tests/parameter-passthrough.spec.ts` - Parameter transformation tests
290-
- `parameter-tests/edge-cases.spec.ts` - Edge case and boundary tests
291-
- `parameter-tests/cli-e2e.spec.ts` - End-to-end standalone CLI testing
292-
- `parameter-tests/builder-integration.spec.ts` - Angular Builder integration tests
293-
- `parameter-tests/build-target.spec.ts` - Build target resolution matrix (buildTarget/browserTarget/prerenderTarget/noBuild)
294-
- `parameter-tests/builder-passthrough.spec.ts` - Builder option pass-through tests
295-
- `parameter-tests/pr-186-commander-defaults.spec.ts` - Commander v3 compatibility and default behavior
296-
297-
**Environment & Prerequisites:**
298-
- `test-prerequisites.spec.ts` - Environment validation (git availability, repository setup, origin remote)
299-
300-
**Public API:**
301-
- `public-api.spec.ts` - Public API exports validation
302-
303-
**Commander Fork (CLI parsing):**
304-
- `commander-fork/test/*.spec.ts` - Tests for commander v3 compatibility fork
305-
306-
Snapshot tests are stored in `__snapshots__/` directory.
307-
308-
**Test Environment Requirements:**
309-
- Tests must run from a git clone with `origin` remote configured
310-
- See `test-prerequisites.spec.ts` for validation details
311-
- All tests use `originalEnv` pattern to preserve and restore `process.env`
312-
313-
### Testing Philosophy: Explicit Assertions
314-
315-
**Prefer precise assertions with `.toBe()` for scalar values, but allow `.toContain()` where appropriate.**
316-
317-
**Rules:**
318-
1. **Explicit expected values** - Always write out the exact expected value
319-
2. **Use `.toBe()` for exact equality of scalars** - Strings, numbers, booleans
320-
3. **Allow `.toContain()` for:**
321-
- **Array membership checks** - Verifying an item is in an array
322-
- **Substring assertions in long messages** - Where full string equality would be brittle or unmaintainable
323-
4. **Variable reuse for passthrough** - If input should equal output unchanged, use the same variable for both
324-
5. **Separate variables for transformations** - If input is transformed, use distinct `input` and `expected` variables
325-
326-
**Good examples:**
327-
```typescript
328-
// ✅ Scalar equality - use .toBe()
329-
const repoUrl = 'https://github.com/test/repo.git';
330-
const result = await prepareOptions({ repo: repoUrl }, logger);
331-
expect(result.repo).toBe(repoUrl);
332-
333-
// ✅ Array membership - .toContain() is appropriate
334-
const files = ['index.html', 'main.js', '.htaccess'];
335-
expect(files).toContain('.htaccess');
336-
337-
// ✅ Substring in long CI message - .toContain() is appropriate
338-
expect(options.message).toContain('Travis CI build: https://travis-ci.org/');
339-
340-
// ✅ Exact message for simple case - use .toBe()
341-
const expected = 'Deploy to gh-pages';
342-
expect(options.message).toBe(expected);
343-
```
344-
345-
**Bad examples:**
346-
```typescript
347-
// ❌ Weak - doesn't verify exact value when you could
348-
expect(result.repo).toContain('github.com'); // Could use .toBe() with full URL
349-
350-
// ❌ Unclear - is this supposed to change or not?
351-
const options = { branch: 'main' };
352-
expect(result.branch).toBe('main'); // Should use same variable!
353-
```
354-
355-
**Guideline:** Use `.toBe()` for exact equality when the full value is known and reasonable to assert. Use `.toContain()` for array membership or when asserting the full value would make tests brittle (e.g., long autogenerated messages).
217+
**Avoid:**
218+
- `.toContain('partial')` when you could use `.toBe(fullExpectedValue)`
219+
- Reusing literals instead of variables to show intent
356220

357-
### TypeScript: NEVER Use `any`
221+
### TypeScript: No `any` Type
358222

359-
**HARD RULE: The `any` type is FORBIDDEN in all code.**
360-
361-
- Never use `any` type
362-
- Use proper types, `unknown`, or `Partial<T>` instead
363-
- If mocking complex types, use `Partial<T>` and cast: `mockObject as CompleteType`
364-
- If type is truly unknown, use `unknown` and add type guards
365-
366-
**Bad:**
367-
```typescript
368-
const result: any = getValue();
369-
const mock = {} as any;
370-
```
371-
372-
**Good:**
373-
```typescript
374-
const result: string | number = getValue();
375-
const mock: Partial<ComplexType> = { ...props };
376-
const typedMock = mock as ComplexType;
377-
```
378-
379-
This explicit style makes tests serve as precise documentation of behavior and catches subtle regressions.
223+
Use proper types, `unknown`, or `Partial<T>` instead. For mocks: `Partial<ComplexType>` cast to `CompleteType`.
380224

381225
## Related Projects
382226

383-
This project builds upon:
384-
- `gh-pages` npm package (core git operations)
385-
- Angular DevKit (builder/schematic infrastructure)
386-
- Originated from AngularFire deploy schematics
387-
388-
For sync considerations, monitor:
227+
For sync considerations with AngularFire, monitor:
389228
- https://github.com/angular/angularfire/blob/master/src/schematics/deploy/builder.ts
390229
- https://github.com/angular/angularfire/blob/master/src/schematics/deploy/actions.ts
391230

392231
## GitHub CLI Usage
393232

394-
When performing GitHub operations (creating issues, PRs, etc.), use the `gh` CLI tool instead of web requests to avoid rate limiting and authentication issues.
233+
When performing GitHub operations (creating issues, PRs, etc.), use the `gh` CLI tool instead of web requests to avoid rate limiting and authentication issues.

0 commit comments

Comments
 (0)