Skip to content

Commit 6d35e88

Browse files
readme instructions
1 parent ecb9920 commit 6d35e88

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
compile-js
22
==========
33

4-
Bash script wrapper for google closure compiler. Allows for JS files listed in manifest or wildcard directory to be combined and compiled.
4+
Bash script wrapper for google closure compiler. Allows for JS files listed in manifest or wildcard directory to be combined and compiled.
5+
Support file modified time checking and only compiles if the source files are newer then the build files.
6+
7+
8+
Installation
9+
==========
10+
1. Download google closure compiler jar. https://developers.google.com/closure/compiler/
11+
2. Edit the path to compiler.jar within compile-js.
12+
3. Edit .profile within terminal and add an alias to compile-js.sh e.g. alias compile-js="~/Sites/libs/closure/compile-js.sh"
13+
14+
Usage
15+
==========
16+
17+
compile-js [command] [output file] [input file(s)]
18+
19+
Wildcard compile all js files within a directory.
20+
cd my_js_src; compile-js build ../my_src_build/myapp.min.js
21+
or
22+
compile-js build /path/my_src_build/myapp.min.js /path/to/my_src/
23+
24+
Create a manifest list of js files
25+
cd my_js_src; compile-js list manifest.txt
26+
or
27+
compile-js list manifest.txt /path/to/my_src/
28+
29+
Compile js using a manifest file
30+
cd my_js_src; compile-js build ../my_src_build/myapp.min.js manifest.txt
31+
or
32+
compile-js build /path/my_src_build/myapp.min.js /path/to/my_src/manifest.txt
33+
34+
Force re-compile js and ignore modified time
35+
cd my_js_src; compile-js rebuild ../my_src_build/myapp.min.js manifest.txt
36+
or
37+
compile-js rebuild /path/my_src_build/myapp.min.js /path/to/my_src/manifest.txt
38+
39+
40+

compile-js.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
4+
#@usage
5+
#compile-js $command $output $input
6+
#compile-js build ../html/assets/js/build/xylo.app.min.js *
7+
#compile-js list manifest.txt
8+
#compile-js build ../html/assets/js/build/xylo.app.min.js manifest.txt
9+
#compile-js rebuild ../html/assets/js/build/xylo.app.min.js manifest.txt
10+
#compile-js build ../html/assets/js/build/xylo.app.min.js booter.js xylo.js service.js
11+
12+
command=$1
13+
output=$2
14+
files=''
15+
list=''
16+
stale=false
17+
compiler=~/Sites/libs/closure/compiler.jar
18+
19+
if test -z "$command"
20+
then
21+
echo "Please specify a command."
22+
fi
23+
24+
25+
if [ "$command" == "list" ]
26+
then
27+
for f in $3*.js
28+
do
29+
list=$list$f'\n'
30+
echo -e "$f"
31+
done
32+
echo -e $list > $output
33+
fi
34+
35+
if [ "$command" == "rebuild" ]
36+
then
37+
command="build"
38+
stale=true
39+
fi
40+
41+
if [ "$command" == "build" ]
42+
then
43+
for f in "$@"
44+
do
45+
if [ "$f" != "$1" ] && [ "$f" != "$2" ] && [[ $f == *.js ]]
46+
then
47+
files=$files$f' '
48+
fi
49+
done
50+
51+
if test -z "$files"
52+
then
53+
files=`cat $3`
54+
fi
55+
56+
57+
for f in $files ; do
58+
list=$list'--js '$f' '
59+
if test $f -nt $output
60+
then
61+
echo $f' is newer then '$output
62+
stale=true
63+
fi
64+
done
65+
66+
#echo -e $files
67+
68+
# closure help
69+
# java -jar compiler.jar -h
70+
# --compilation_level WHITESPACE_ONLY SIMPLE_OPTIMIZATIONS ADVANCED_OPTIMIZATIONS
71+
# --externs ../src/js/angular/angular.min.js ../src/js/angular/angular-resource.min.js
72+
if $stale ; then
73+
echo "Compiling $output: "
74+
java -jar $compiler $list --compilation_level SIMPLE_OPTIMIZATIONS --js_output_file $output --warning_level QUIET --summary_detail_level 3
75+
echo "completed $output."
76+
else
77+
echo "No new files to compile."
78+
fi
79+
80+
fi
81+

0 commit comments

Comments
 (0)