Merge pull request #18140 from mattwire/removetimeoutpermlocation
[civicrm-core.git] / ext / afform / html / bin / setup.sh
1 #!/usr/bin/env bash
2 set -e
3
4 EXTROOT=$(cd `dirname $0`/..; pwd)
5 EXTKEY="org.civicrm.afform-html"
6
7 ##############################
8 function do_help() {
9 echo "usage: $0 [options]"
10 echo "example: $0"
11 echo " -h (Help) Show this help screen"
12 echo " -D (Download) Download dependencies"
13 echo " -z (Zip) Build installable ZIP file"
14 }
15
16 ##############################
17 function use_civiroot() {
18 if [ -z "$CIVIROOT" ]; then
19 CIVIROOT=$(cv ev 'echo $GLOBALS["civicrm_root"];')
20 if [ -z "$CIVIROOT" -o ! -d "$CIVIROOT" ]; then
21 do_help
22 echo ""
23 echo "ERROR: invalid civicrm-dir: [$CIVIROOT]"
24 exit
25 fi
26 fi
27 }
28
29 ##############################
30 function cleanup() {
31 use_civiroot
32 ## No DAOs or XML build to cleanup
33 }
34
35 ##############################
36 function do_download() {
37 pushd "$EXTROOT" >> /dev/null
38 npm install
39 popd >> /dev/null
40 }
41
42 ##############################
43 ## Build installable ZIP file
44 function do_zipfile() {
45 local canary="$EXTROOT/node_modules/monaco-editor/package.json"
46 if [ ! -f "$canary" ]; then
47 echo "Error: File $canary missing. Are you sure the build is ready?"
48 exit 1
49 fi
50
51 local zipfile="$EXTROOT/build/$EXTKEY.zip"
52 [ -f "$zipfile" ] && rm -f "$zipfile"
53 [ ! -d "$EXTROOT/build" ] && mkdir "$EXTROOT/build"
54 pushd "$EXTROOT" >> /dev/null
55 ## Build a list of files to include.
56 ## Put the files into the *.zip, using a $EXTKEY as a prefix.
57 {
58 ## Get any files in the project root, except for dotfiles.
59 find . -mindepth 1 -maxdepth 1 -type f -o -type d | grep -v '^\./\.'
60 ## Get any files in the main subfolders.
61 #find CRM/ ang/ api/ bin/ css/ js/ sql/ sass/ settings/ templates/ tests/ xml/ -type f -o -type d
62 find bin/ xml/ -type f -o -type d
63 ## Get the distributable files for Monaco.
64 find node_modules/monaco-editor/LICENSE node_modules/monaco-editor/min -type f -o -type d
65 } \
66 | grep -v '~$' \
67 | php bin/add-zip-regex.php "$zipfile" ":^:" "$EXTKEY/"
68 popd >> /dev/null
69 echo "Created: $zipfile"
70 }
71
72 ##############################
73 ## Main
74 HAS_ACTION=
75
76 while getopts "aDghz" opt; do
77 case $opt in
78 h)
79 do_help
80 HAS_ACTION=1
81 ;;
82 D)
83 do_download
84 HAS_ACTION=1
85 ;;
86 z)
87 do_zipfile
88 HAS_ACTION=1
89 ;;
90 \?)
91 do_help
92 echo "Invalid option: -$OPTARG" >&2
93 exit 1
94 ;;
95 :)
96 echo "Option -$OPTARG requires an argument." >&2
97 exit 1
98 ;;
99 esac
100 done
101
102 if [ -z "$HAS_ACTION" ]; then
103 do_help
104 exit 2
105 fi