diff options
author | Frédéric Menou <frederic.menou@fretlink.com> | 2016-12-08 10:19:15 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@fretlink.com> | 2022-05-17 18:01:51 +0200 |
commit | a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7 (patch) | |
tree | adf3186fdccaeef19151026cdfbd38a530cf9ecb /scripts | |
download | edi-parser-a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7.tar.gz edi-parser-a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7.tar.zst edi-parser-a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7.zip |
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/documentation-versioning.sh | 125 | ||||
-rwxr-xr-x | scripts/scaffolder.sh | 29 |
2 files changed, 154 insertions, 0 deletions
diff --git a/scripts/documentation-versioning.sh b/scripts/documentation-versioning.sh new file mode 100755 index 0000000..a5ffd2a --- /dev/null +++ b/scripts/documentation-versioning.sh | |||
@@ -0,0 +1,125 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # This is the initial commit of this project. | ||
4 | # This is useful to list content of the first tagged version. | ||
5 | rootCommit="c468e930cf7f15c709bf8890f197135a62858f16" | ||
6 | |||
7 | function parentTag { | ||
8 | local tag=$1 | ||
9 | git describe --abbrev=0 --tags "${tag}^" 2>/dev/null || echo "${rootCommit}" | ||
10 | } | ||
11 | |||
12 | function prettyLogUndocumentedTag { | ||
13 | local tag=$1; | ||
14 | cat <<-HTML | ||
15 | <dt> | ||
16 | <h2> | ||
17 | (${tag}) Not generated | ||
18 | </h2> | ||
19 | </dt> | ||
20 | HTML | ||
21 | } | ||
22 | |||
23 | function gitAuthor { | ||
24 | local tag="$1" | ||
25 | git log -n1 --pretty="%an" "${tag}" | ||
26 | } | ||
27 | |||
28 | function linkToTaggedDocumentation { | ||
29 | local tag="$1" | ||
30 | cat <<-HTML | ||
31 | <a href="${tag}/index.html"> | ||
32 | <button> | ||
33 | <small>Go to </small> | ||
34 | <strong>${tag}</strong> | ||
35 | <small> released by </small> | ||
36 | <strong>$(gitAuthor "${tag}")</strong> | ||
37 | </button> | ||
38 | </a> | ||
39 | HTML | ||
40 | } | ||
41 | |||
42 | function contentOfTaggedDocumentation { | ||
43 | local tag=$1; | ||
44 | local content | ||
45 | content=$(git log --pretty="%ad | %h | %s" --date=short "$(parentTag "${tag}")..${tag}") | ||
46 | echo "<pre>${content}</pre>" | ||
47 | } | ||
48 | |||
49 | function prettyLogTag { | ||
50 | local tag=$1 | ||
51 | cat <<-HTML | ||
52 | <dt>$(linkToTaggedDocumentation "${tag}")</dt> | ||
53 | <dd>$(contentOfTaggedDocumentation "${tag}")</dd> | ||
54 | HTML | ||
55 | } | ||
56 | |||
57 | function formatTags { | ||
58 | local webRoot="$1" | ||
59 | while read -r tag | ||
60 | do | ||
61 | if [ -d "${webRoot}/${tag}" ] | ||
62 | then | ||
63 | prettyLogTag "$tag" | ||
64 | else | ||
65 | prettyLogUndocumentedTag "$tag" | ||
66 | fi | ||
67 | done | ||
68 | } | ||
69 | |||
70 | function listTags { | ||
71 | git tag --list "v20??-??-??" --sort="-refname" | ||
72 | } | ||
73 | |||
74 | function generateIndex { | ||
75 | local webRoot="$1" | ||
76 | cat <<-HTML | ||
77 | <!DOCTYPE html> | ||
78 | <html> | ||
79 | <meta charset="UTF-8"> | ||
80 | <head> | ||
81 | <link rel="stylesheet" href="https://cdn.rawgit.com/yegor256/tacit/gh-pages/tacit-css-1.3.4.min.css"/> | ||
82 | </head> | ||
83 | <body> | ||
84 | <section> | ||
85 | <article> | ||
86 | <h1>Available documentations</h1> | ||
87 | <hr> | ||
88 | <dl> | ||
89 | $(listTags | formatTags "${webRoot}") | ||
90 | </dl> | ||
91 | </section> | ||
92 | </article> | ||
93 | </section> | ||
94 | </body> | ||
95 | </html> | ||
96 | HTML | ||
97 | } | ||
98 | |||
99 | function generateDoc { | ||
100 | local webRoot="$1" | ||
101 | local currentTag="$2" | ||
102 | local docRoot="$3" | ||
103 | local tagWebRoot="${webRoot}/${currentTag}" | ||
104 | if [[ -z "$webRoot" ]] | ||
105 | then | ||
106 | echo "Undefined webRoot directory" | ||
107 | exit 1 | ||
108 | fi | ||
109 | if [[ -z "$currentTag" ]] | ||
110 | then | ||
111 | echo "Undefined current tag" | ||
112 | exit 1 | ||
113 | fi | ||
114 | if [[ -z "$docRoot" ]] | ||
115 | then | ||
116 | echo "Undefined documentation root" | ||
117 | exit 1 | ||
118 | fi | ||
119 | echo "Documentation root: ${docRoot}" | ||
120 | mkdir -p "${webRoot}"; | ||
121 | cp -r "${docRoot}" "${tagWebRoot}" | ||
122 | generateIndex "${webRoot}" > "${webRoot}/index.html" | ||
123 | } | ||
124 | |||
125 | generateDoc "$1" "$2" "$3" | ||
diff --git a/scripts/scaffolder.sh b/scripts/scaffolder.sh new file mode 100755 index 0000000..a7121f7 --- /dev/null +++ b/scripts/scaffolder.sh | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | HERE="$(dirname "$0")" | ||
4 | |||
5 | REVISION="D96A" | ||
6 | if [ -n "$1" ] | ||
7 | then | ||
8 | REVISION=$1 | ||
9 | shift 1 | ||
10 | fi | ||
11 | |||
12 | function specification { | ||
13 | stack exec edi-parser-scaffolder -- \ | ||
14 | scaffold --revision "$REVISION" \ | ||
15 | --src "$HERE/../src" \ | ||
16 | --specification "$HERE/../specification" | ||
17 | } | ||
18 | |||
19 | function missing { | ||
20 | echo "$1 is missing. Aborting." | ||
21 | exit 1 | ||
22 | } | ||
23 | |||
24 | function checkRequirements { | ||
25 | command -v stylish-haskell > /dev/null || missing "stylish-haskell" | ||
26 | } | ||
27 | |||
28 | checkRequirements | ||
29 | specification | ||