generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to auto-update the root readme
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
|
||
# Takes the generated readme files for each feature, adjusts the markdown headings, and updates the root readme with the new content. | ||
|
||
import os | ||
import re | ||
|
||
# Get the list of subdirs in src | ||
feature_names = [d for d in os.listdir("src")] | ||
|
||
print(f"Found {len(feature_names)} features: {', '.join(feature_names)}") | ||
|
||
# Read the root readme | ||
with open("README.md", "r") as f: | ||
root_readme = f.read() | ||
|
||
new_content = "" | ||
|
||
# Update the root readme with the new content | ||
for feature_name in feature_names: | ||
# Read the feature readme | ||
with open(f"src/{feature_name}/README.md", "r") as f: | ||
feature_readme = f.read() | ||
|
||
# Adjust the markdown headings | ||
feature_readme = re.sub(r"^#", "###", feature_readme, flags=re.MULTILINE) | ||
|
||
# Remove everything after the --- to the end of the file | ||
feature_readme = re.sub(r"\n---.*", "", feature_readme, flags=re.DOTALL) | ||
|
||
new_content += f"\n{feature_readme}" | ||
|
||
print(f"New readme content to add: {new_content}") | ||
|
||
# Replace the old content with the new content | ||
root_readme = re.sub( | ||
r"<!-- START_FEATURES -->.*<!-- END_FEATURES -->", | ||
f"<!-- START_FEATURES -->{new_content}<!-- END_FEATURES -->", | ||
root_readme, | ||
flags=re.DOTALL, | ||
) | ||
|
||
# Write the updated root readme | ||
with open("README.md", "w") as f: | ||
f.write(root_readme) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters