def _css_build(out_folder, input_files, output_files): out_path = os.path.join(_CWD, out_folder) in_paths = map(lambda f: os.path.join(out_path, f), input_files) out_paths = map(lambda f: os.path.join(out_path, f), output_files) args = ['--no-inline-includes', '-f'] + in_paths + ['-o'] + out_paths node.RunNode([node_modules.PathToPolymerCssBuild()] + args)
def _optimize(in_folder, args): in_path = os.path.normpath(os.path.join(_CWD, in_folder)).replace('\\', '/') out_path = os.path.join(_CWD, args.out_folder).replace('\\', '/') manifest_out_path = _request_list_path(out_path, args.host_url) tmp_out_dir = tempfile.mkdtemp(dir=out_path).replace('\\', '/') excludes = _BASE_EXCLUDES + [ # This file is dynamically created by C++. Need to specify an exclusion # URL for both the relative URL and chrome:// URL syntax. 'strings.js', 'strings.m.js', '%s/strings.js' % args.host_url, '%s/strings.m.js' % args.host_url, ] excludes.extend(args.exclude or []) external_paths = args.external_paths or [] try: if args.js_module_in_files: pcb_out_paths = [ os.path.join(tmp_out_dir, f) for f in args.js_out_files ] bundled_paths = _bundle_v3(tmp_out_dir, in_path, out_path, manifest_out_path, args, excludes, external_paths) else: # Ensure Polymer 2 and Polymer 3 request lists don't collide. manifest_out_path = _request_list_path(out_path, args.host_url[:-1] + '-v2/') pcb_out_paths = [ os.path.join(out_path, f) for f in args.html_out_files ] bundled_paths = _bundle_v2(tmp_out_dir, in_path, out_path, manifest_out_path, args, excludes) # Run polymer-css-build. node.RunNode([node_modules.PathToPolymerCssBuild()] + ['--polymer-version', '2'] + ['--no-inline-includes', '-f'] + bundled_paths + ['-o'] + pcb_out_paths) # Pass the JS files through Uglify and write the output to its final # destination. for index, js_out_file in enumerate(args.js_out_files): node.RunNode([ node_modules.PathToTerser(), os.path.join(tmp_out_dir, js_out_file), '--comments', '/Copyright|license|LICENSE|\<\/?if/', '--output', os.path.join(out_path, js_out_file) ]) finally: shutil.rmtree(tmp_out_dir) return manifest_out_path
def _optimize(in_folder, args): in_path = os.path.normpath(os.path.join(_CWD, in_folder)).replace('\\', '/') out_path = os.path.join(_CWD, args.out_folder).replace('\\', '/') manifest_out_path = _request_list_path(out_path, args.target_name) tmp_out_dir = tempfile.mkdtemp(dir=out_path).replace('\\', '/') excludes = _BASE_EXCLUDES + [ # This file is dynamically created by C++. Should always be imported with a # relative path. 'strings.m.js', ] excludes.extend(args.exclude or []) external_paths = args.external_paths or [] try: pcb_out_paths = [ os.path.join(tmp_out_dir, f) for f in args.js_out_files ] bundled_paths = _bundle_v3(tmp_out_dir, in_path, out_path, manifest_out_path, args, excludes, external_paths) # Run polymer-css-build. node.RunNode([node_modules.PathToPolymerCssBuild()] + ['--polymer-version', '2'] + ['--no-inline-includes', '-f'] + bundled_paths + ['-o'] + pcb_out_paths) # Pass the JS files through Terser and write the output to its final # destination. for index, js_out_file in enumerate(args.js_out_files): node.RunNode([ node_modules.PathToTerser(), os.path.join(tmp_out_dir, js_out_file), '--comments', '/Copyright|license|LICENSE|\<\/?if/', '--output', os.path.join(out_path, js_out_file) ]) finally: shutil.rmtree(tmp_out_dir) return manifest_out_path
def _css_build(out_folder, files): out_path = os.path.join(_CWD, out_folder) paths = map(lambda f: os.path.join(out_path, f), files) _run_node([node_modules.PathToPolymerCssBuild()] + paths)
def _optimize(in_folder, args): in_path = os.path.normpath(os.path.join(_CWD, in_folder)).replace('\\', '/') out_path = os.path.join(_CWD, args.out_folder).replace('\\', '/') manifest_out_path = _request_list_path(out_path, args.host) exclude_args = [] for f in args.exclude or []: exclude_args.append('--exclude') exclude_args.append(f) in_html_args = [] for f in args.html_in_files: in_html_args.append(f) tmp_out_dir = os.path.join(out_path, 'bundled').replace('\\', '/') node.RunNode( [node_modules.PathToBundler()] + _VULCANIZE_BASE_ARGS + _VULCANIZE_REDIRECT_ARGS + exclude_args + [# This file is dynamically created by C++. Need to specify an exclusion # URL for both the relative URL and chrome:// URL syntax. '--exclude', 'strings.js', '--exclude', 'chrome://%s/strings.js' % args.host, '--manifest-out', manifest_out_path, '--root', in_path, '--redirect', '"chrome://%s/|%s"' % (args.host, in_path + '/'), '--out-dir', os.path.relpath(tmp_out_dir, _CWD).replace('\\', '/'), '--shell', args.html_in_files[0], ] + in_html_args) for index, html_file in enumerate(args.html_in_files): with open( os.path.join(os.path.relpath(tmp_out_dir, _CWD), html_file), 'r') as f: output = f.read() # Grit includes are not supported, use HTML imports instead. output = output.replace('<include src="', '<include src-disabled="') if args.insert_in_head: assert '<head>' in output # NOTE(dbeam): polymer-bundler eats <base> tags after processing. This # undoes that by adding a <base> tag to the (post-processed) generated # output. output = output.replace('<head>', '<head>' + args.insert_in_head) # Open file again with 'w' such that the previous contents are overwritten. with open( os.path.join(os.path.relpath(tmp_out_dir, _CWD), html_file), 'w') as f: f.write(output) f.close() try: crisper_html_out_paths = [] for index, html_in_file in enumerate(args.html_in_files): crisper_html_out_paths.append( os.path.join(tmp_out_dir, args.html_out_files[index])) js_out_file = args.js_out_files[index] # Run crisper to separate the JS from the HTML file. node.RunNode([node_modules.PathToCrisper(), '--source', os.path.join(tmp_out_dir, html_in_file), '--script-in-head', 'false', '--html', crisper_html_out_paths[index], '--js', os.path.join(tmp_out_dir, js_out_file)]) if args.replace_for_html_imports_polyfill == js_out_file: # Replace the output file with a loader script, to wait until HTML # imports are ready before loading. with open(crisper_html_out_paths[index], 'r') as f: output = f.read() output = output.replace(js_out_file + '"', 'chrome://resources/js/crisper_loader.js"' + \ ' data-script-name="' + js_out_file + '"') # Preload the final script, even though it will not be evaluated # until after crisper_loader.js executes. output = output.replace('<head>', '<head><link rel="preload" href="' + \ js_out_file + '" as="script">') f.close() # Open file again with 'w' such that the previous contents are # overwritten. with open(crisper_html_out_paths[index], 'w') as f: f.write(output) f.close() # Pass the JS file through Uglify and write the output to its final # destination. node.RunNode([node_modules.PathToUglify(), os.path.join(tmp_out_dir, js_out_file), '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', '--output', os.path.join(out_path, js_out_file)]) # Run polymer-css-build and write the output HTML files to their final # destination. html_out_paths = [ os.path.join(out_path, f) for f in args.html_out_files] node.RunNode([node_modules.PathToPolymerCssBuild()] + ['--polymer-version', '2'] + ['--no-inline-includes', '-f'] + crisper_html_out_paths + ['-o'] + html_out_paths) finally: shutil.rmtree(tmp_out_dir) return manifest_out_path
def _css_build(out_folder, files): out_path = os.path.join(_CWD, out_folder) paths = [os.path.join(out_path, f) for f in files] _run_node([node_modules.PathToPolymerCssBuild()] + paths)
def _css_build(directory, files): target_path = os.path.join(_HERE_PATH, directory) paths = map(lambda f: os.path.join(target_path, f), files) _run_node([node_modules.PathToPolymerCssBuild()] + paths)
def _polymer_css_build(out_path, html_in_paths, html_out_files, version): html_out_paths = [os.path.join(out_path, f) for f in html_out_files] node.RunNode([node_modules.PathToPolymerCssBuild()] + ['--polymer-version', str(version)] + ['--no-inline-includes', '-f'] + html_in_paths + ['-o'] + html_out_paths)