This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdist.sh
executable file
·107 lines (92 loc) · 3.2 KB
/
dist.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
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
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
DATE="$( date '+%Y%m%d%H%S' )"
DIST_DIR=$SCRIPTPATH/dist
DIST_SCHEMA_DIR=$DIST_DIR/schema
DIST_SCHEMA_ACTIONS_DIR=$DIST_SCHEMA_DIR/actions
DIST_SCHEMA_NOTIFICATIONS_DIR=$DIST_SCHEMA_DIR/notifications
ACTIONS_DIR=$SCRIPTPATH/schema/actions
NOTIFICATIONS_DIR=$SCRIPTPATH/schema/notifications
GH_PAGES_INDEX_FILE=$DIST_DIR/index.md
#
# Function that is invoked when the script fails.
#
# $1 - The message to display prior to exiting.
#
function fail() {
echo $1
echo "Exiting."
exit 1
}
#
# Function that processes a schema file
# (validates, resolves references, generates HTML)
#
# $1 - The schema file
# $2 - The output directory
#
function process_schema() {
schema=$1
outdir=$2
echo "Processing '$schema' schema..."
schema_dir=$(dirname "$schema")
schema_basename=$(basename "$schema")
schema_no_ext="${schema_basename%.*}"
schema_ref_deref="$outdir/$schema_no_ext-deref.json"
# Change to schema directory
cd $schema_dir || { fail "Unable to change to schema dir: $schema_dir"; }
# Copy original schema to outdir
cp "$schema" "$outdir" || { fail "Error copying: $schema"; }
# Dereference the json $ref values
echo "Dereferencing schema file..."
node /root/deref.js "$schema" > "$schema_ref_deref" \
|| { fail "Error dereferencing: $schema"; }
# Validate the dereferenced schema
echo "Validating dereferenced schema file..."
jsonschema -i "$schema_ref_deref" /root/dxlschema/v0.1/schema.json \
|| { fail "Error validating schema: $schema"; }
# Generate html
echo "Generating HTML for schema..."
schema_html_dir="$outdir/$schema_no_ext"
bootprint opendxl "$schema_ref_deref" "$schema_html_dir" \
|| { fail "Error generating html for schema: $schema"; }
}
#
# Walks the specified schema directory
# (validates, resolves references, generates HTML)
#
# $1 - The schema directory
# $2 - The output directory
#
function walk_schema_dir() {
schemadir=$1
outdir=$2
for f in "$schemadir"/*.json
do
if [ -f $f ]; then
process_schema "$f" "$outdir"
fi
done
}
# Clear dist directory
if [ -d $DIST_DIR ]; then
echo "Clearing dist directory..."
rm -rf $DIST_DIR || { fail 'Error clearing dist directory.'; }
fi
# Create dist directories
echo "Creating dist directory..."
mkdir $DIST_DIR || { fail 'Error creating dist directory.'; }
echo "Creating schema directory..."
mkdir $DIST_SCHEMA_DIR || { fail 'Error creating schema directory.'; }
echo "Creating schema actions directory..."
mkdir $DIST_SCHEMA_ACTIONS_DIR || { fail 'Error creating schema actions directory.'; }
echo "Creating schema notifications directory..."
mkdir $DIST_SCHEMA_NOTIFICATIONS_DIR || { fail 'Error creating schema notifications directory.'; }
# Walk actions
walk_schema_dir "$ACTIONS_DIR" "$DIST_SCHEMA_ACTIONS_DIR"
# Walk notifications
walk_schema_dir "$NOTIFICATIONS_DIR" "$DIST_SCHEMA_NOTIFICATIONS_DIR"
# Generate index file for GitHub pages
python $SCRIPTPATH/site/generatepagesindex.py "$GH_PAGES_INDEX_FILE" \
"$DIST_SCHEMA_ACTIONS_DIR" "$DIST_SCHEMA_NOTIFICATIONS_DIR" \
|| { fail 'Error generating GitHub pages index file.'; }