-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
126 lines (107 loc) · 3.02 KB
/
run.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
script_dir=`dirname $0`
if test $# -ne 2; then
echo "usage: $0 <data-files-dir-path> <yesod-project-path>"
exit 1
fi
parallel=1
checkError() {
if test $? -ne 0; then
exit 1
fi
}
for p in handlebars \
handlebars-helpers; do
if test ! -d node_modules/$p; then
echo "npm install $p"
npm install $p
checkError
fi
done
if test ! -d hs-yaml2json/.stack-work; then
cd hs-yaml2json
echo "stack build"
stack build
checkError
cd -
fi
data_files_dir=$1
yesod_project_dir=$2
yaml2json=`find hs-yaml2json/.stack-work/install -name hs-yaml2json | head -1`
which nodejs > /dev/null
if test $? -eq 0; then
handlebars="nodejs handlebars_process.js"
else
handlebars="node handlebars_process.js"
fi
tmp_dir=tmp
if test -d $tmp_dir; then
rm -rf $tmp_dir
fi
mkdir $tmp_dir
templates_dir=templates
if test ! -d $templates_dir; then
mkdir $templates_dir
fi
checkError() {
if test $? -ne 0; then
exit 1
fi
}
generateCode() {
data_filename=$1
template_filename=$2
code_file_ext=$3
echo " template: $template_filename"
template_file=$templates_dir/$template_filename
data_file_json=$tmp_dir/$data_filename.json
gen_code_file=$tmp_dir/${data_filename}__$template_filename.$code_file_ext
$yaml2json $data_files_dir/$data_filename > $data_file_json
$handlebars $template_file $data_file_json > $gen_code_file
template_file=${template_file}_cmds.hbs
shell_cmds_file=${gen_code_file}_cmds.sh
$handlebars $template_file $data_file_json > $shell_cmds_file
sed -e "s:__GEN_CODE_FILE__:`pwd`/$gen_code_file:g" \
-e "s:__YESOD_PROJECT_DIR__:$yesod_project_dir:g" \
-i'.tmp' \
$shell_cmds_file
}
processDataFile() {
data_file=$1
echo "generate code: $data_file ..."
data_filename=`basename $data_file`
if echo "$data_file" | grep -q "/modelWithView_"; then
echo " modelWithView"
generateCode $data_filename model_handler.hbs hs
checkError
generateCode $data_filename model_edit_form_hamlet.hbs html
checkError
generateCode $data_filename model_edit_form_fields_hamlet.hbs html
checkError
generateCode $data_filename model_add_form_hamlet.hbs html
checkError
generateCode $data_filename model_add_form_fields_hamlet.hbs html
checkError
generateCode $data_filename model_config.hbs txt
checkError
generateCode $data_filename model_list_hamlet.hbs html
checkError
generateCode $data_filename model_version_table_trigger.hbs sql
checkError
fi
}
# remove not needed files that may be replaced
rm $yesod_project_dir/templates/*_gen.hamlet
for data_file in $data_files_dir/*; do
if test $parallel -eq 1; then
processDataFile $data_file &
else
processDataFile $data_file
fi
done
# wait for all background processes to finish
wait
for cmd_file in $tmp_dir/*.sh; do
echo "update project: $cmd_file ..."
sh $cmd_file
done