forked from selectize/selectize.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·53 lines (40 loc) · 1.65 KB
/
build.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
#!/bin/bash
# read version info
config=$(cat bower.json)
version_regex="\"version\": \"([^\"]*)\""
[[ "$config" =~ $version_regex ]]
version="${BASH_REMATCH[1]}"
# setup
IFS='%'
out=selectize.js
out_min=selectize.min.js
banner="/*! selectize.js - v${version} | https://github.com/brianreavis/selectize.js | Apache License (v2) */"
append_file () {
src=$(cat $2 | sed 's/^ *//g' | sed 's/ *$//g' | sed 's.\\.\\\\\\\\\\.g')
echo -eE "$1\n\n// --- $2 ---\n\n$src"
}
# bundle files...
printf "Generating \033[1;39mselectize.js\033[0;39m..."
src=""
for file in src/contrib/*.js; do src=`append_file "$src" $file`; done
for file in src/*.js; do
if [ "$file" != "src/selectize.js" ]; then src=`append_file "$src" $file`; fi
done
src=`append_file "$src" src/selectize.js`
# format and wrap...
src=`echo -e "$src" | while read -r line; do echo -e "\t$line"; done`
src="$banner\n\n(function (factory) {\n\tif (typeof exports === 'object') {\n\t\tfactory(require('jquery'));\n\t} else if (typeof define === 'function' && define.amd) {\n\t\tdefine(['jquery'], factory);\n\t} else {\n\t\tfactory(jQuery);\n\t}\n}(function ($) {\n\t\"use strict\";$src\n\n\treturn Selectize;\n\n}));"
echo -e "$src" > $out
printf " done.\n"
# generate minified version...
printf "Generating \033[1;39mselectize.min.js\033[0;39m..."
curl -s -d compilation_level=SIMPLE_OPTIMIZATIONS \
-d output_format=text \
-d output_info=compiled_code \
--data-urlencode "js_code@$out" \
http://closure-compiler.appspot.com/compile \
> $out_min
echo "$banner" | cat - $out_min > temp && mv temp $out_min
printf " done.\n"
printf "\033[32mv${version} compiled\033[0;39m\n"
unset IFS