-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
55 lines (40 loc) · 1.95 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Ensure the 'tree' command is installed
if ! command -v tree &> /dev/null; then
echo "'tree' command not found. Please install it to use this script."
exit 1
fi
# Define the output file (README.md in the root directory)
readme_file="README.md"
license_file="LICENSE"
script="test.sh"
# Define the default content you want to keep at the top of the README.md
default_content=$(cat << EOF
# Project Title
This repository contains Terraform modules designed to help manage and automate the provisioning of Azure cloud resources. Each module is crafted to follow best practices and make it easier to create, configure, and manage specific Azure services in a reusable manner.
## Report an Issue
If you encounter any issues, please report them on the [Issues page](https://github.com/devwithkrishna/azure-terraform-modules/issues/new).
EOF
)
# Remove the old directory structure, if it exists
# It assumes the old structure starts from '# Available Modules' until the end of the file
sed -i '/# Available Modules/,$d' "$readme_file"
# Write the default content back to the README.md
echo "$default_content" > "$readme_file"
# List module names based on subdirectories
MODULES_SECTION="## Available Modules\n\n"
for dir in */; do
module_name=$(basename "$dir")
MODULES_SECTION+="* **${module_name}**: Located in \`${dir}\`\n"
done
# Append the modules section to the README.md
echo -e "$MODULES_SECTION" >> "$readme_file"
# Start a Markdown code block for the directory structure
echo '## Project Directory Structure' >> "$readme_file"
echo '```' >> "$readme_file"
# Generate the directory structure and append to README.md, ignoring certain files
tree -I 'README.md|README123.md|LICENSE|test.sh|node_modules|.git' --charset utf-8 >> "$readme_file"
# End the Markdown code block
echo '```' >> "$readme_file"
# Print success message
echo "README.md has been successfully updated with the directory structure, module listings, and issue reporting section."