-
Notifications
You must be signed in to change notification settings - Fork 18
/
mkmanifest.sh
executable file
·63 lines (49 loc) · 1.66 KB
/
mkmanifest.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
#!/bin/bash
# Initializes the dagger browser given the build directory of project of where to search for component graph files.
# If the build directory is not provided, the sample will be compiled and used an example.
# Usage: ./init.sh build_dir [out_file]
set -eu
MANIFEST_FILENAME=ComponentsManifest.json
main() {
local build_dir=${1:-}
local out_file=${2:-}
local pattern=${3:-}
# if component manifest is not provided, then we build the sample
if [ -z ${build_dir:-} ]; then
echo "Usage: $0 build_dir"
exit 1
fi
if [ -d "$out_file" ]; then
out_file="${out_file}/${MANIFEST_FILENAME}"
elif [ -z ${out_file:-} ]; then
out_file="$MANIFEST_FILENAME"
fi
echo "Looking for component graph files in $build_dir"
local components_manifest_file=$out_file
mkdir -p build
local tmp="${components_manifest_file}.tmp"
if [ -d "$pattern" ]; then
pattern="${pattern}"
elif [ -z ${pattern:-} ]; then
pattern="*/build/*_graph.json"
fi
find $build_dir -path "$pattern" >"$tmp"
echo '{"components": [' >|"$components_manifest_file"
for f in $(awk "NR != $(wc -l <$tmp)" $tmp); do
cat "$f" >>"$components_manifest_file"
echo ',' >>"$components_manifest_file"
done
f=$(tail -n 1 "$tmp")
if [ -z "$f" ]; then
echo "Failed to find any component graph files in $build_dir. Did you add the SPI plugin to your modules?"
exit 1
fi
cat "$f" >>"$components_manifest_file"
echo ']}' >>"$components_manifest_file"
# clean up the tmp file
rm -f -- "$tmp"
echo ""
echo "Generated $out_file"
echo ""
}
main $@