diff --git a/.gitignore b/.gitignore index c8312c40ff..fa697a4139 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,7 @@ tsconfig.tsbuildinfo .amazonq .kiro .github/instructions -aidlc-docs \ No newline at end of file +aidlc-docs +# Generated by docs/generate_api_readme.py - do not commit +API_README.md +packages/*/API_README.md diff --git a/docs/generate_api_readme.py b/docs/generate_api_readme.py new file mode 100644 index 0000000000..597b20fb21 --- /dev/null +++ b/docs/generate_api_readme.py @@ -0,0 +1,44 @@ +""" +Generate API_README.md files for TypeDoc by stripping the customer reference section +from each package's README.md and the root README.md. + +Registered as an mkdocs on_pre_build hook so it runs automatically during `mkdocs build`. +Can also be run standalone: python3 docs/generate_api_readme.py +""" + +import re +from pathlib import Path + + +# Removes the full section body (heading through the last sub-section before ## License) +SECTION_PATTERN = re.compile( + r"\n## How to support Powertools for AWS Lambda \(TypeScript\)\?.*?(?=\n## )", + re.DOTALL, +) + +# Removes the TOC entry and its indented children +TOC_ENTRY_PATTERN = re.compile( + r"\n- \[How to support Powertools for AWS Lambda \(TypeScript\)\?[^\n]*" + r"(?:\n - \[[^\n]*)*", +) + + +def generate(root: Path = Path(".")) -> None: + targets = [root] + sorted((root / "packages").iterdir()) + for pkg in targets: + readme = pkg / "README.md" + if not readme.exists(): + continue + content = readme.read_text(encoding="utf-8") + clean = SECTION_PATTERN.sub("", content) + clean = TOC_ENTRY_PATTERN.sub("", clean) + (pkg / "API_README.md").write_text(clean, encoding="utf-8") + + +# mkdocs hook entry point +def on_pre_build(config) -> None: # noqa: ANN001 + generate() + + +if __name__ == "__main__": + generate() diff --git a/mkdocs.yml b/mkdocs.yml index 79ccff71b1..bfa88bd045 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,3 +1,6 @@ +hooks: + - docs/generate_api_readme.py + site_name: Powertools for AWS Lambda (TypeScript) site_description: Powertools for AWS Lambda (TypeScript) site_author: Amazon Web Services diff --git a/package.json b/package.json index 862e30481d..dc5df8dd87 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "docs:docker:run": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs powertools-typescript/docs", "docs:local:setup": "python3 -m venv .venv && .venv/bin/pip install -r docs/requirements.txt", "docs:local:run": ".venv/bin/mkdocs serve", - "docs:local:api": "typedoc .", + "docs:local:api": "python3 docs/generate_api_readme.py && typedoc .", "postpublish": "git restore .", "lint:markdown": "markdownlint-cli2 '**/*.md' '#node_modules' '#**/*/node_modules' '#docs/changelog.md' '#LICENSE.md' '#.github' '#CHANGELOG.md' '#**/*/CHANGELOG.md' '#examples/app/README.md' '#.venv' '#site'" }, diff --git a/packages/batch/typedoc.json b/packages/batch/typedoc.json index 5873dab1cd..eb41ee0204 100644 --- a/packages/batch/typedoc.json +++ b/packages/batch/typedoc.json @@ -1,5 +1,5 @@ { "extends": ["../../typedoc.base.json"], "entryPoints": ["./src/index.ts", "./src/parser.ts", "./src/types.ts"], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/commons/typedoc.json b/packages/commons/typedoc.json index e85c329a9d..521f5facd8 100644 --- a/packages/commons/typedoc.json +++ b/packages/commons/typedoc.json @@ -9,5 +9,5 @@ "./src/fromBase64.ts", "./src/LRUCache.ts" ], - "readme": "./README.md" + "readme": "./API_README.md" } diff --git a/packages/event-handler/typedoc.json b/packages/event-handler/typedoc.json index 4a6e4113b0..c8a382be3c 100644 --- a/packages/event-handler/typedoc.json +++ b/packages/event-handler/typedoc.json @@ -7,5 +7,5 @@ "./src/http/index.ts", "./src/types/index.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/idempotency/typedoc.json b/packages/idempotency/typedoc.json index a429c1b85f..0e8b32d3cd 100644 --- a/packages/idempotency/typedoc.json +++ b/packages/idempotency/typedoc.json @@ -9,5 +9,5 @@ "./src/persistence/CachePersistenceLayer.ts", "./src/types/CachePersistence.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/jmespath/typedoc.json b/packages/jmespath/typedoc.json index 480beba0f8..f53835eaab 100644 --- a/packages/jmespath/typedoc.json +++ b/packages/jmespath/typedoc.json @@ -7,5 +7,5 @@ "./src/Functions.ts", "./src/PowertoolsFunctions.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/kafka/typedoc.json b/packages/kafka/typedoc.json index dafd6a578c..389b92f2d2 100644 --- a/packages/kafka/typedoc.json +++ b/packages/kafka/typedoc.json @@ -1,5 +1,5 @@ { "extends": ["../../typedoc.base.json"], "entryPoints": ["./src/index.ts", "./src/types/types.ts", "./src/errors.ts"], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/logger/typedoc.json b/packages/logger/typedoc.json index 7df20e3456..1fa87ebc91 100644 --- a/packages/logger/typedoc.json +++ b/packages/logger/typedoc.json @@ -5,5 +5,5 @@ "./src/types/index.ts", "./src/middleware/middy.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/metrics/typedoc.json b/packages/metrics/typedoc.json index 7df20e3456..1fa87ebc91 100644 --- a/packages/metrics/typedoc.json +++ b/packages/metrics/typedoc.json @@ -5,5 +5,5 @@ "./src/types/index.ts", "./src/middleware/middy.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/parameters/typedoc.json b/packages/parameters/typedoc.json index 6f77a07a12..3c36f17ba3 100644 --- a/packages/parameters/typedoc.json +++ b/packages/parameters/typedoc.json @@ -13,7 +13,7 @@ "./src/errors.ts", "./src/constants.ts" ], - "readme": "README.md", + "readme": "./API_README.md", "externalSymbolLinkMappings": { "@aws-sdk/client-secrets-manager": { "GetSecretValueCommandInput": "https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-secrets-manager/Interface/GetSecretValueCommandInput/" diff --git a/packages/parser/typedoc.json b/packages/parser/typedoc.json index cc06598557..2a4df3b89c 100644 --- a/packages/parser/typedoc.json +++ b/packages/parser/typedoc.json @@ -9,5 +9,5 @@ "./src/helpers/index.ts", "./src/helpers/dynamodb.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/tracer/typedoc.json b/packages/tracer/typedoc.json index c1513a9208..9a7cd9dc47 100644 --- a/packages/tracer/typedoc.json +++ b/packages/tracer/typedoc.json @@ -6,5 +6,5 @@ "./src/middleware/middy.ts", "./src/provider/ProviderService.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/packages/validation/typedoc.json b/packages/validation/typedoc.json index 0ce66a9f21..a2f821fcaf 100644 --- a/packages/validation/typedoc.json +++ b/packages/validation/typedoc.json @@ -7,5 +7,5 @@ "./src/decorator.ts", "./src/errors.ts" ], - "readme": "README.md" + "readme": "./API_README.md" } diff --git a/typedoc.json b/typedoc.json index 57017cc3fb..8ed13d1bb8 100644 --- a/typedoc.json +++ b/typedoc.json @@ -2,7 +2,7 @@ "entryPoints": ["packages/*"], "entryPointStrategy": "packages", "name": "Powertools for AWS Lambda (Typescript) API Reference", - "readme": "README.md", + "readme": "./API_README.md", "out": "api", "exclude": [ "**/node_modules/**",