| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 set -e | 7 set -e |
| 8 | 8 |
| 9 if [ "$#" -ne 2 ] | 9 if [ "$#" -ne 2 ] |
| 10 then | 10 then |
| 11 echo "Usage: $0 <src_dir> <dst_dir>" | 11 echo "Usage: $0 <src_dir> <dst_dir>" |
| 12 echo | 12 echo |
| 13 echo "Extracts inlined scripts from <src_dir> to <dst_dir>" \ | 13 echo "Extracts inlined scripts from <src_dir> to <dst_dir>" \ |
| 14 "Polymer HTML files found in the destination directory to separate JS" \ | 14 "Polymer HTML files found in the destination directory to separate JS" \ |
| 15 "files. A JS file extracted from the file with name 'foo.html' will" \ | 15 "files. A JS file extracted from the file with name 'foo.html' will" \ |
| 16 "have a name 'foo-extracted.js'. Inclusion of the script file will be" \ | 16 "have a name 'foo-extracted.js'. Inclusion of the script file will be" \ |
| 17 "added to 'foo.html': '<script src=\"foo-extracted.js\"></script>'." | 17 "added to 'foo.html': '<script src=\"foo-extracted.js\"></script>'." |
| 18 exit 1 | 18 exit 1 |
| 19 fi | 19 fi |
| 20 | 20 |
| 21 src="${1%/}" | 21 src="${1%/}" |
| 22 dst="${2%/}" | 22 dst="${2%/}" |
| 23 | 23 |
| 24 rsync -c -r -v --exclude="compiled_resources*.gyp" "$src/" "$dst/" | 24 rsync -c --delete -r -v --exclude="compiled_resources*.gyp" "$src/" "$dst/" |
| 25 | 25 |
| 26 find "$dst" -name "*.html" \ | 26 find "$dst" -name "*.html" \ |
| 27 -not -path "*/demos/*" \ | 27 -not -path "*/demos/*" \ |
| 28 -not -path "*/test/*" \ | 28 -not -path "*/test/*" \ |
| 29 -not -path "*/tests/*" \ | 29 -not -path "*/tests/*" \ |
| 30 -not -name "demo*.html" \ | 30 -not -name "demo*.html" \ |
| 31 -not -name "index.html" \ | 31 -not -name "index.html" \ |
| 32 -not -name "metadata.html" | \ | 32 -not -name "metadata.html" | \ |
| 33 xargs grep -l "<script>" | \ | 33 xargs grep -l "<script>" | \ |
| 34 while read original_html_name | 34 while read original_html_name |
| 35 do | 35 do |
| 36 dir=$(dirname "$original_html_name") | 36 dir=$(dirname "$original_html_name") |
| 37 name=$(basename "$original_html_name" .html) | 37 name=$(basename "$original_html_name" .html) |
| 38 | 38 |
| 39 html_without_js="$dir/$name-extracted.html" | 39 html_without_js="$dir/$name-extracted.html" |
| 40 extracted_js="$dir/$name-extracted.js" | 40 extracted_js="$dir/$name-extracted.js" |
| 41 echo "Crisping $original_html_name" | 41 echo "Crisping $original_html_name" |
| 42 crisper --script-in-head=false --source "$original_html_name" \ | 42 crisper --script-in-head=false --source "$original_html_name" \ |
| 43 --html "$html_without_js" --js "$extracted_js" | 43 --html "$html_without_js" --js "$extracted_js" |
| 44 mv "$html_without_js" "$original_html_name" | 44 mv "$html_without_js" "$original_html_name" |
| 45 done | 45 done |
| OLD | NEW |