#!/usr/bin/env python3
"""Ajoute ou retire basePath: "/app" dans un next.config.ts."""
import sys

path, mode = sys.argv[1], sys.argv[2]
src = open(path).read()
line = '  basePath: "/app",\n'
if mode == "on":
    if "basePath" not in src:
        src = src.replace("const nextConfig: NextConfig = {\n",
                          "const nextConfig: NextConfig = {\n" + line, 1)
else:
    src = src.replace(line, "")
open(path, "w").write(src)
