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
| sh
#!/bin/bash
# allows to find a comment in each file for a project and auto generate the documentation
# for the moment the format is \\ @, before the function, on one line
# example a
# 1 // @ this function make something great (great:string)
# 2 async function(great: string) {
# 3 ... some code
# example b
# 1 // @ this function make something great (great:string)
# 2 // @ other line of comment
# 3 async function(great: string) {
# 4 ... some code
# remove content
: > generated_documentation.md
# search comment and stock it
grep -ri -A1 "// @ " * > tmp.md
# set style
old_IFS=$IFS
IFS=$'\n'
for line in $(cat tmp.md)
do
# suppress last { on line function (the line after the last // @) (in example a is line 2, in example b is line 3)
if [ "${line: -1}" = "{" ] ; then
newLine="\`\`\` ${IFS}${line::-1}${IFS} \`\`\`"
else
newLine="${line}"
fi
# suppress bad log line
if [ "${newLine}" = "--" ] ; then
newLine=''
fi
# remove command log and replace by nothing
newLine=${newLine//[a-z0-9]*.[a-z0-9]*.ts[:||-][' '][' '][' '][' ']/}
# remove comment
newLine=${newLine//'// @ '/}
echo "${newLine}${IFS}" >> generated_documentation.md
done
IFS=$old_IFS
# remove temporary file and exit
rm tmp.md
exit |
Partager