-
Notifications
You must be signed in to change notification settings - Fork 1
/
scaffold
executable file
·73 lines (59 loc) · 1.94 KB
/
scaffold
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
#! /usr/bin/env bash
# This will generete Elm code in src/ directory.
#
# NOTE: It will first remove whatever is currently there. If you have some
# uncommited changes - commit them first, so you can later merge.
source "scripts/common.sh"
function write_module {
local name=$1 # Elm comaptible module name
local type=$2 # elements | attributes | events
local prefix=$3 # prefix to drop from each element function name
local component=$4 # Component name, e.g. paper-button
local analysis="$5" # JSON string
local path=$(echo ${name} | module_to_path )
echo "Generating ${name} module (${type})"
echo "Writing Elm code to ${path}"
mkdir -p "$(dirname ${path})"
echo ${analysis} \
| scripts/generate-${type}.sh ${name} ${prefix} ${component} \
> ${path}
elm-format-0.18 --yes ${path} \
|| echo "
Failed to format ${path}. Please fix it manually.
" 1>&2
}
api="https://www.webcomponents.org/api"
# Begin:
rm -rf src/Polymer/*
# Write common attribute helpers
envsubst \
< "templates/attributes-helpers.elm" \
> "src/Polymer/Attributes.elm"
collections=$(
js-yaml \
web-components.yml \
| jq \
--raw-output \
' .collections | keys | .[] '
)
for collection in ${collections}
do
components=$(
js-yaml \
web-components.yml \
| jq \
--raw-output \
".collections[\"${collection}\"].components[]"
)
for component in ${components}
do
module=$( echo ${component} | component_to_module_name )
url="${api}/docs/PolymerElements/${component}?use_analyzer_data"
echo "Fetching analysis data from ${url}"
analysis=$(http ${url} | jq ' .analysis ')
# Generate elements and attributes module
write_module ${module} elements ${collection} ${component} "${analysis}"
write_module ${module}.Attributes attributes ${collection} ${component} "${analysis}"
# write_module ${module}.Events events ${collection} "${analysis}"
done
done