-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-docs.sh
executable file
·56 lines (41 loc) · 1.7 KB
/
generate-docs.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
56
#!/bin/bash
SCHEMA_DIR="src/schemas"
OUTPUT_DIR="docusaurus/docs"
OVERVIEW="$OUTPUT_DIR/overview.md"
mkdir -p $OUTPUT_DIR
# init overview.md
echo "# ATT&CK Schemas" > $OVERVIEW
echo "" >> $OVERVIEW
# attack spec version
specVersion=$(cat "ATTACK_SPEC_VERSION")
echo "Current ATT&CK Spec Version: [$specVersion](https://github.com/mitre-attack/attack-stix-data/blob/master/CHANGELOG.md)" >> $OVERVIEW
echo "" >> $OVERVIEW
# schema table
echo "| ATT&CK Concept | STIX Object Type | Link |" >> $OVERVIEW
echo "|----------------|------------------|------|" >> $OVERVIEW
find $SCHEMA_DIR -name "*.schema.ts" | while read schemaFile; do
fileName="$(basename "$schemaFile")"
# skip software (covered by malware/tool)
if [[ "${fileName}" == "software.schema.ts" ]]; then
continue
fi
# skip stix-bundle (manually generated) and add to overview page
if [[ "${fileName}" == "stix-bundle.schema.ts" ]]; then
echo "| STIX Bundle | SDO | [Schema](/docs/sdo/stix-bundle.schema) |" >> $OVERVIEW
continue
fi
# get relative file path
relativePath="${schemaFile#$SCHEMA_DIR/}"
# get schema title
title=$(sed -e 's/-/ /g' <<< "${fileName%%.*}")
title=$(echo "$title" | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1')
# title="$(tr '[:lower:]' '[:upper:]' <<< "${title:0:1}")${title:1}"
# set output file path
outputFile="$OUTPUT_DIR/${relativePath/.ts/.md}"
# convert zod schemas to md
npx zod2md --entry $schemaFile --title "$title Schema" --output "$outputFile"
# add schema to overview table
schemaLink="${relativePath/.ts/.md}"
stixType=$(dirname "$relativePath" | cut -d '/' -f 1 | tr '[:lower:]' '[:upper:]')
echo "| $title | $stixType | [Schema](/docs/$schemaLink) |" >> $OVERVIEW
done