Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ tsconfig.tsbuildinfo
.amazonq
.kiro
.github/instructions
aidlc-docs
aidlc-docs
# Generated by docs/generate_api_readme.py - do not commit
API_README.md
packages/*/API_README.md
44 changes: 44 additions & 0 deletions docs/generate_api_readme.py
Original file line number Diff line number Diff line change
@@ -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## )",

Check warning on line 15 in docs/generate_api_readme.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Fix this reluctant quantifier that will only ever match 0 repetitions.

See more on https://sonarcloud.io/project/issues?id=aws-powertools_powertools-lambda-typescript&issues=AZ1uE1Az39oYaSTaQ3SC&open=AZ1uE1Az39oYaSTaQ3SC&pullRequest=5166
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

Check warning on line 39 in docs/generate_api_readme.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused function parameter "config".

See more on https://sonarcloud.io/project/issues?id=aws-powertools_powertools-lambda-typescript&issues=AZ1uE1Az39oYaSTaQ3SD&open=AZ1uE1Az39oYaSTaQ3SD&pullRequest=5166
generate()


if __name__ == "__main__":
generate()
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/batch/typedoc.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion packages/commons/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"./src/fromBase64.ts",
"./src/LRUCache.ts"
],
"readme": "./README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/event-handler/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"./src/http/index.ts",
"./src/types/index.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/idempotency/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"./src/persistence/CachePersistenceLayer.ts",
"./src/types/CachePersistence.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/jmespath/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"./src/Functions.ts",
"./src/PowertoolsFunctions.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/kafka/typedoc.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion packages/logger/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"./src/types/index.ts",
"./src/middleware/middy.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/metrics/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"./src/types/index.ts",
"./src/middleware/middy.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/parameters/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"./src/helpers/index.ts",
"./src/helpers/dynamodb.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/tracer/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"./src/middleware/middy.ts",
"./src/provider/ProviderService.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion packages/validation/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"./src/decorator.ts",
"./src/errors.ts"
],
"readme": "README.md"
"readme": "./API_README.md"
}
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**",
Expand Down