forked from knockout/knockout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-linux
executable file
·45 lines (36 loc) · 1.96 KB
/
build-linux
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
#!/bin/sh
handle_fail() {
echo; echo "Build failed"
exit 1
}
tools/check-trailing-space-linux || handle_fail
OutDebugFile='output/knockout-latest.debug.js'
OutMinFile='output/knockout-latest.js'
# Combine the source files
SourceFiles=`grep js < fragments/source-references.js | # Find JS references
sed "s/[ \',]//g" | # Strip off JSON fluff (whitespace, commas, quotes)
sed -e 's/.*/..\/&/' | # Fix the paths by prefixing with ../
tr '\n' ' '` # Combine into single line
cat fragments/extern-pre.js > $OutDebugFile.temp
cat fragments/amd-pre.js >> $OutDebugFile.temp
cat $SourceFiles >> $OutDebugFile.temp || handle_fail
cat fragments/amd-post.js >> $OutDebugFile.temp
cat fragments/extern-post.js >> $OutDebugFile.temp
# Now call Google Closure Compiler to produce a minified version
curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode output_wrapper="(function() {%output%})();" --data-urlencode "js_code=/**@const*/var DEBUG=false;" --data-urlencode js_code@$OutDebugFile.temp "http://closure-compiler.appspot.com/compile" > $OutMinFile.temp
# Finalise each file by prefixing with version header and surrounding in function closure
cp fragments/version-header.js $OutDebugFile
echo "(function(){" >> $OutDebugFile
echo "var DEBUG=true;" >> $OutDebugFile
cat $OutDebugFile.temp >> $OutDebugFile
echo "})();" >> $OutDebugFile
rm $OutDebugFile.temp
cp fragments/version-header.js $OutMinFile
cat $OutMinFile.temp >> $OutMinFile
rm $OutMinFile.temp
# Inject the version number string
Version=`cat fragments/version.txt`
sed -i~ -e "s/##VERSION##/$Version/g" $OutDebugFile $OutMinFile
# Delete the odd files left behind on Mac
rm -f output/*.js~
echo; echo "Build succeeded"