OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 import itertools | 7 import itertools |
8 import os | 8 import os |
9 import platform | 9 import platform |
10 import re | 10 import re |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 node.RunNode([node_modules.PathToCrisper(), | 165 node.RunNode([node_modules.PathToCrisper(), |
166 '--source', tmp.name, | 166 '--source', tmp.name, |
167 '--script-in-head', 'false', | 167 '--script-in-head', 'false', |
168 '--html', html_out_path, | 168 '--html', html_out_path, |
169 '--js', js_out_path]) | 169 '--js', js_out_path]) |
170 | 170 |
171 # Create an empty JS file if crisper did not create one. | 171 # Create an empty JS file if crisper did not create one. |
172 if not os.path.isfile(js_out_path): | 172 if not os.path.isfile(js_out_path): |
173 open(js_out_path, 'w').close() | 173 open(js_out_path, 'w').close() |
174 | 174 |
175 node.RunNode([node_modules.PathToUglifyJs(), js_out_path, | 175 # Rewrite licenses such that Closure Compiler will preserve them. |
176 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', | 176 import rewrite_licenses |
177 '--output', js_out_path]) | 177 with open(js_out_path, 'r') as f: |
| 178 output_data = rewrite_licenses.rewrite(f.read()) |
| 179 |
| 180 # Open file again with 'w' such that the previous contents are overwritten. |
| 181 with open(js_out_path, 'w') as f: |
| 182 f.write(output_data) |
| 183 f.close() |
| 184 |
| 185 output = node.RunNode([node_modules.PathToClosureCompiler(), js_out_path]) |
| 186 with open(js_out_path, 'w') as output_file: |
| 187 output_file.write(output) |
| 188 |
178 finally: | 189 finally: |
179 os.remove(tmp.name) | 190 os.remove(tmp.name) |
180 | 191 |
181 | 192 |
182 def main(argv): | 193 def main(argv): |
183 parser = argparse.ArgumentParser() | 194 parser = argparse.ArgumentParser() |
184 parser.add_argument('--depfile', required=True) | 195 parser.add_argument('--depfile', required=True) |
185 parser.add_argument('--exclude', nargs='*') | 196 parser.add_argument('--exclude', nargs='*') |
186 parser.add_argument('--host', required=True) | 197 parser.add_argument('--host', required=True) |
187 parser.add_argument('--html_in_file', required=True) | 198 parser.add_argument('--html_in_file', required=True) |
(...skipping 10 matching lines...) Expand all Loading... |
198 args.depfile = os.path.normpath(args.depfile) | 209 args.depfile = os.path.normpath(args.depfile) |
199 args.input = os.path.normpath(args.input) | 210 args.input = os.path.normpath(args.input) |
200 args.out_folder = os.path.normpath(args.out_folder) | 211 args.out_folder = os.path.normpath(args.out_folder) |
201 | 212 |
202 _vulcanize(args.input, args) | 213 _vulcanize(args.input, args) |
203 _update_dep_file(args.input, args) | 214 _update_dep_file(args.input, args) |
204 | 215 |
205 | 216 |
206 if __name__ == '__main__': | 217 if __name__ == '__main__': |
207 main(sys.argv[1:]) | 218 main(sys.argv[1:]) |
OLD | NEW |