Creates the webui vulcanized directory to deploy to Appengine. Args: out_dir: directory name of the output directory. Must not have slashes, dots, etc.
(out_dir)
| 87 | |
| 88 | |
| 89 | def CreateWebuiAppengineDist(out_dir): |
| 90 | """Creates the webui vulcanized directory to deploy to Appengine. |
| 91 | |
| 92 | Args: |
| 93 | out_dir: directory name of the output directory. Must not have slashes, |
| 94 | dots, etc. |
| 95 | """ |
| 96 | logging.info('entering ...') |
| 97 | try: |
| 98 | tempdir = tempfile.mkdtemp() |
| 99 | # Merge the contents of webui with the installed node_modules into a |
| 100 | # common root (a temp directory). This lets us use the vulcanize tool. |
| 101 | for entry in os.listdir('.'): |
| 102 | if entry != 'node_modules': |
| 103 | if os.path.isfile(entry): |
| 104 | shutil.copyfile(entry, os.path.join(tempdir, entry)) |
| 105 | else: |
| 106 | shutil.copytree(entry, os.path.join(tempdir, entry)) |
| 107 | for entry in os.listdir('node_modules'): |
| 108 | if not os.path.isdir('node_modules/' + entry): |
| 109 | continue |
| 110 | elif entry == 'web-animations-js': |
| 111 | shutil.copytree(os.path.join('node_modules', entry), |
| 112 | os.path.join(tempdir, '@polymer', entry)) |
| 113 | elif entry != '@polymer': |
| 114 | shutil.copytree(os.path.join('node_modules', entry), |
| 115 | os.path.join(tempdir, entry)) |
| 116 | for entry in os.listdir('node_modules/@polymer'): |
| 117 | shutil.copytree(os.path.join('node_modules/@polymer', entry), |
| 118 | os.path.join(tempdir, '@polymer', entry)) |
| 119 | vulcanized_index_html = subprocess.check_output([ |
| 120 | 'node_modules/vulcanize/bin/vulcanize', |
| 121 | '--inline-scripts', '--inline-css', |
| 122 | '-p', tempdir, 'index.html']) |
| 123 | finally: |
| 124 | shutil.rmtree(tempdir) |
| 125 | webui_out = os.path.join(out_dir, 'webui_appengine') |
| 126 | shutil.copytree('.', webui_out, ignore=shutil.ignore_patterns('dist')) |
| 127 | f = open(os.path.join(webui_out, 'index.html'), 'wb') |
| 128 | f.write(vulcanized_index_html) |
| 129 | f.close() |
| 130 | f = open(os.path.join(webui_out, 'legacy.html'), 'wb') |
| 131 | f.write(vulcanized_index_html.replace(b'https://cdn.ampproject.org/v0/validator_wasm.js', b'https://cdn.ampproject.org/v0/validator.js', 1)) |
| 132 | f.close() |
| 133 | logging.info('... success') |
| 134 | |
| 135 | |
| 136 | def Main(): |