Advertisement
kosx

Google compile_js.sh

Dec 30th, 2020
1,964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.61 KB | None | 0 0
  1. #!/usr/bin/env -S bash -e
  2. # Copyright 2019 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. # Use the Google Closure Compiler to minimize and concatenate
  6. # our JavasScript.
  7. # With -check, it checks that the source files are not newer
  8. # than the compiled ones instead.
  9. source devtools/lib.sh || { echo "Are you at repo root?"; exit 1; }
  10. JSDIR=content/static/js
  11. # compile OUTFILE INFILE1 INFILE2 ...
  12. compile() {
  13.   local outfile=$1
  14.   shift
  15.   rm -f $outfile
  16.   local args
  17.   if [[ $1 = '-advanced' ]]; then
  18.     shift
  19.     args='--compilation_level=ADVANCED_OPTIMIZATIONS'
  20.   fi
  21.   docker run --rm -i femtopixel/google-closure-compiler-app:closure-compiler-parent-v20200719 $args < <(cat $@) > $outfile
  22.   echo "wrote $outfile"
  23. }
  24. check() {
  25.   local outfile=$1
  26.   shift
  27.   for infile in $@; do
  28.     if [[ $infile -nt $outfile ]]; then
  29.       echo "$infile is newer than $outfile; run devtools/compile_js.sh"
  30.       exit 1
  31.     fi
  32.   done
  33.   echo "checked $outfile"
  34. }
  35. main() {
  36.   local cmd=compile
  37.   if [[ $1 = "-check" ]]; then
  38.     cmd=check
  39.   fi
  40.   $cmd $JSDIR/base.min.js               $JSDIR/{site,analytics}.js
  41.   $cmd $JSDIR/fetch.min.js              $JSDIR/fetch.js
  42.   $cmd $JSDIR/playground.min.js         $JSDIR/playground.js
  43.   $cmd $JSDIR/badge.min.js              $JSDIR/badge.js
  44.   $cmd $JSDIR/jump.min.js               third_party/dialog-polyfill/dialog-polyfill.js $JSDIR/jump.js
  45.   # TODO: once this is not an experiment, add it to the relevant line above.
  46.   $cmd $JSDIR/completion.min.js         $JSDIR/completion.js
  47. }
  48. main $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement