import os
import shutil

BUILD_DIR = 'Release/gen'

OUTPUT_DIR = 'mojomjs'

def copy_mojom_js_files(build_dir, output_dir):

    for root, _, files in os.walk(build_dir):
        for file in files:
            if file.endswith('.mojom.js') or file.endswith('mojom.m.js') or file == 'mojo_bindings.js':

                file_path = os.path.join(root, file)

                relative_path = os.path.relpath(file_path, build_dir)

                target_path = os.path.join(output_dir, relative_path)

                os.makedirs(os.path.dirname(target_path), exist_ok=True)

                shutil.copy2(file_path, target_path)

                print(f"Copied: {file_path} -> {target_path}")

copy_mojom_js_files(BUILD_DIR, OUTPUT_DIR)

print(f"All .mojom.js files have been copied to {OUTPUT_DIR}")
