OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Wraps the standalone JavaScript inside a templated outer JavaScript. |
| 6 |
| 7 Chrome needs to wrap the standalone JavaScript so it does not access the real |
| 8 window object, which is done in the wrapper JS. The output of this script is |
| 9 the file which is included in the Chrome builds. |
| 10 """ |
| 11 |
| 12 import optparse |
| 13 import sys |
| 14 |
| 15 def main(argv): |
| 16 parser = optparse.OptionParser() |
| 17 parser.add_option('-t', '--templatefile', |
| 18 help='The path to the output JavaScript template.') |
| 19 parser.add_option('-i', '--infile', |
| 20 help='The path to the standalone JavaScript to inject into the template.') |
| 21 parser.add_option('-o', '--outfile', |
| 22 help='The path to the output JavaScript.') |
| 23 options, _ = parser.parse_args(argv) |
| 24 |
| 25 templatepath = options.templatefile |
| 26 inpath = options.infile |
| 27 outpath = options.outfile |
| 28 |
| 29 if templatepath: |
| 30 templatefile = open(templatepath, 'r') |
| 31 else: |
| 32 print 'Please provide path to the template file' |
| 33 return 1 |
| 34 |
| 35 if inpath: |
| 36 infile = open(inpath, 'r') |
| 37 else: |
| 38 print 'Reading input from stdin' |
| 39 infile = sys.stdin |
| 40 |
| 41 if outpath: |
| 42 outfile = open(outpath, 'w') |
| 43 else: |
| 44 outfile = sys.stdout |
| 45 |
| 46 standalone_js = infile.read() |
| 47 template_js = templatefile.read() |
| 48 output_js = template_js.replace('$$DISTILLER_JAVASCRIPT', standalone_js) |
| 49 outfile.write(output_js) |
| 50 return 0 |
| 51 |
| 52 if __name__ == '__main__': |
| 53 sys.exit(main(sys.argv)) |
OLD | NEW |