#!/usr/bin/env python3
"""Patch a tsconfig.json to exclude test directories for Debian packaging."""
import json
import shutil
import sys

tsconfig_path = sys.argv[1]

# Save original
shutil.copy(tsconfig_path, tsconfig_path + '.debian-orig')

with open(tsconfig_path) as f:
    config = json.load(f)

exclude = config.setdefault('exclude', [])
for pattern in ['src/test', 'src/test/**']:
    if pattern not in exclude:
        exclude.append(pattern)

with open(tsconfig_path, 'w') as f:
    json.dump(config, f, indent=2)

print(f'Patched {tsconfig_path}: exclude += src/test')
