#! /usr/bin/python

import os
import shutil
import sys

if len(sys.argv) < 2:
  print("Usage: python copy_mojo_js_bindings.py <chromium_build_path> <copy_to_path>")
  sys.exit(1)


base_path = sys.argv[1]
out_path = sys.argv[2] if len(sys.argv) > 2 else './'
for path, dirs, files in os.walk(base_path):
  for file in files:
    if file == 'mojo_bindings.js':
      shutil.copyfile(os.path.join(path, file), os.path.join(out_path, file))

    if file.endswith('.mojom.js'):
      target_path = os.path.join(out_path, path[len(base_path) + 1:])
      try:
        os.makedirs(target_path)
      except:
        pass
      shutil.copyfile(os.path.join(path, file), os.path.join(target_path, file))

