-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandardize_readmes.sh
More file actions
executable file
·132 lines (103 loc) · 4.1 KB
/
Copy pathstandardize_readmes.sh
File metadata and controls
executable file
·132 lines (103 loc) · 4.1 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
#
# standardize_readmes.sh — converts every repo's README.md to README.adoc
# (canonical format) using pandoc, with snapshots saved before each change.
set -uo pipefail
__SD="$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
. "${__SD}/lib/common.sh"
GS_SCRIPT_NAME="standardize_readmes"
gs::strict
gs::install_trap
gs::install_trap_summary
gs::need pandoc
REPOS_DIR="${REPOS_DIR:-${GS_REPOS_DIR}}"
LOG_FILE="${GS_REPORT_DIR}/$(date -u +'%Y%m%dT%H%M%SZ')-readme-standardization.log"
BACKUP_DIR="${GS_BACKUP_DIR}/readmes-$(date -u +'%Y%m%dT%H%M%SZ')"
gs::info "log: ${LOG_FILE}"
gs::info "backups: ${BACKUP_DIR}"
echo "Starting README standardization process..."
echo "$(date) - Starting README standardization" > "$LOG_FILE"
# Create backup directory
mkdir -p "$BACKUP_DIR"
echo "Creating backups of existing README files..."
find "$REPOS_DIR" -maxdepth 2 -name "README*" -type f | while read readme_file; do
repo_name=$(basename $(dirname "$readme_file"))
file_name=$(basename "$readme_file")
# Backup original file
cp "$readme_file" "$BACKUP_DIR/${repo_name}_${file_name}"
echo "Backed up: $file_name from $repo_name" >> "$LOG_FILE"
done
echo "" >> "$LOG_FILE"
echo "Processing repositories..." >> "$LOG_FILE"
# Process each repository
find "$REPOS_DIR"/*/ -maxdepth 0 -type d | while read repo; do
if [[ ! -d "$repo/.git" ]]; then
continue
fi
repo_name=$(basename "$repo")
echo "Processing: $repo_name" >> "$LOG_FILE"
# Check what README files exist
md_file="$repo/README.md"
adoc_file="$repo/README.adoc"
if [[ -f "$md_file" && -f "$adoc_file" ]]; then
# Both exist - need to merge/decide
echo " ✗ Both README.md and README.adoc exist" >> "$LOG_FILE"
# Compare sizes - keep the more substantial one
md_lines=$(wc -l < "$md_file")
adoc_lines=$(wc -l < "$adoc_file")
if [[ $md_lines -gt $adoc_lines ]]; then
echo " Converting README.md to README.adoc (more content)" >> "$LOG_FILE"
# Convert markdown to asciidoc
pandoc "$md_file" -o "$adoc_file" -f markdown -t asciidoc
rm "$md_file"
else
echo " Keeping README.adoc (more content), removing README.md" >> "$LOG_FILE"
rm "$md_file"
fi
elif [[ -f "$md_file" ]]; then
# Only README.md exists - convert to adoc
echo " Converting README.md to README.adoc" >> "$LOG_FILE"
pandoc "$md_file" -o "$adoc_file" -f markdown -t asciidoc
rm "$md_file"
elif [[ -f "$adoc_file" ]]; then
# Only README.adoc exists - good
echo " ✓ README.adoc already exists" >> "$LOG_FILE"
else
# No README exists - create basic one
echo " Creating new README.adoc" >> "$LOG_FILE"
# Analyze repository to create appropriate README
language="Unknown"
if [[ -f "$repo/mix.exs" ]]; then language="Elixir"
elif [[ -f "$repo/Cargo.toml" ]]; then language="Rust"
elif [[ -f "$repo/package.json" ]]; then language="JavaScript"
elif [[ -f "$repo/stack.yaml" || -f "$repo/*.cabal" ]]; then language="Haskell"
elif [[ -f "$repo/Project.toml" ]]; then language="Julia"
fi
cat > "$adoc_file" << EOF
= $repo_name
:toc: preamble
:icons: font
== Overview
**$language implementation of [purpose based on repo name].**
[Brief description to be completed]
== Features
* [Feature 1]
* [Feature 2]
* [Feature 3]
== Quick Start
[Installation and basic usage]
== License
SPDX-License-Identifier: MPL-2.0
Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath)
EOF
fi
done
echo "" >> "$LOG_FILE"
echo "$(date) - Standardization process completed" >> "$LOG_FILE"
echo "All README files have been standardized to README.adoc format" >> "$LOG_FILE"
echo "Backups are available in: $BACKUP_DIR"
echo "README standardization completed!"
echo "Backups saved to: $BACKUP_DIR"
echo "Log saved to: $LOG_FILE"