render.sh
1.33 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
#!/usr/bin/env bash
# render.sh — init 渲染单个 _module.md 或 REQ-*.md
#
# 用法:
# bash render.sh module <out_path> <module_code> <module_name> <module_brief>
# bash render.sh req <out_path> <req_id> <title> <goal> <rules> <constraints> <acceptance>
#
# 模板路径自定位:脚本同级父目录下 templates/{_module-template.md, req-card-template.md}
set -euo pipefail
TYPE=${1:?missing type (module|req)}
shift
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
TPL_DIR="$SCRIPT_DIR/../templates"
case "$TYPE" in
module)
out=${1:?missing out_path}; code=${2:?}; name=${3:?}; brief=${4:?}
c=$(cat "$TPL_DIR/_module-template.md")
c="${c//\{\{module_code\}\}/$code}"
c="${c//\{\{module_name\}\}/$name}"
c="${c//\{\{module_brief\}\}/$brief}"
;;
req)
out=${1:?missing out_path}; req_id=${2:?}; title=${3:?}; goal=${4:?}; rules=${5:?}; constraints=${6:?}; acceptance=${7:?}
c=$(sed '/^<!--$/,/^-->$/d' "$TPL_DIR/req-card-template.md")
c="${c//\{\{req_id\}\}/$req_id}"
c="${c//\{\{title\}\}/$title}"
c="${c//\{\{goal\}\}/$goal}"
c="${c//\{\{rules\}\}/$rules}"
c="${c//\{\{constraints\}\}/$constraints}"
c="${c//\{\{acceptance\}\}/$acceptance}"
;;
*)
echo "render.sh: unknown type '$TYPE' (expect module|req)" >&2
exit 1
;;
esac
printf '%s\n' "$c" > "$out"