import json
import os
import utils

def process_file(filename):
    handle = open(filename, "r")
    lines = handle.read().replace("\r", "").split("\n")
    handle.close()
    real_lines = []
    for line in lines:
        line = line.replace(" default ", " ")
        raw_line = line.strip()
        if raw_line.startswith("@") or raw_line.startswith("import ") or raw_line == "":
            continue
        if raw_line.startswith("export ") and raw_line.endswith(";"):
            continue
        real_lines.append(line)
    return real_lines

def process_dir(dirname):
    real_files = []
    contents = []
    for root, _, files in os.walk(dirname):
        for filename in files: # Ensure that "I..." classes are put first
            if filename.startswith("I"):
                real_files.insert(0, root + "/" + filename)
            else:
                real_files.append(root + "/" + filename)
    for filename in real_files:
        if os.path.basename(filename) == "index.ts" or not filename.endswith(".ts"):
            continue
        contents += process_file(filename)
    return contents

def main():
    content_dir = utils.get_server_dir() + "content/"
    handle = open(content_dir + "config.json", "r")
    content_config = json.loads(handle.read())
    handle.close()
    lines = ['import * as linq from "linq";']
    model_dirs = content_config["modelDirs"]
    model_dirs.insert(0, "enums")
    for model_dir in model_dirs:
        lines += process_dir(content_dir + model_dir + "/")
    comment = "// This file is automatically generated by /scripts/export_models.py\n"
    raw = comment + "\n".join(lines)
    out_file = content_dir + "static/js/lib/Models.ts"
    handle = open(out_file, "w")
    handle.write(raw)
    handle.close()
    print("Wrote output to {}. Compiling client-side Typescript...".format(out_file))
    os.chdir(content_dir + "static/js")
    utils.compile_ts()
    os.chdir(utils.get_server_dir())

if __name__ == "__main__":
    main()

import json
import os
import utils

def process_file(filename):
    handle = open(filename, "r")
    lines = handle.read().replace("\r", "").split("\n")
    handle.close()
    real_lines = []
    for line in lines:
        line = line.replace(" default ", " ")
        raw_line = line.strip()
        if raw_line.startswith("@") or raw_line.startswith("import ") or raw_line == "":
            continue
        if raw_line.startswith("export ") and raw_line.endswith(";"):
            continue
        if raw_line == "// stop-generate":
            print("stop-generate encountered in " + filename)
            real_lines.append("}")
            break
        real_lines.append(line)
    return real_lines

def process_dir(dirname):
    real_files = []
    contents = []
    for root, _, files in os.walk(dirname):
        for filename in files: # Ensure that "I..." classes are put first
            if filename.startswith("I"):
                real_files.insert(0, root + "/" + filename)
            else:
                real_files.append(root + "/" + filename)
    for filename in real_files:
        if os.path.basename(filename) == "index.ts" or not filename.endswith(".ts"):
            continue
        contents += process_file(filename)
    return contents

def main():
    content_dir = utils.get_server_dir() + "content/"
    handle = open(content_dir + "config.json", "r")
    content_config = json.loads(handle.read())
    handle.close()
    lines = []
    model_dirs = content_config["modelDirs"]
    model_dirs.insert(0, "enums")
    for model_dir in model_dirs:
        lines += process_dir(content_dir + model_dir + "/")
    comment = "// This file is automatically generated by /scripts/export_models.py\n"
    raw = comment + "\n".join(lines)
    out_file = content_dir + "static/js/lib/Models.ts"
    handle = open(out_file, "w")
    handle.write(raw)
    handle.close()
    print("Wrote output to {}. Compiling client-side Typescript...".format(out_file))
    os.chdir(content_dir + "static/js")
    utils.compile_ts()
    os.chdir(utils.get_server_dir())

if __name__ == "__main__":
    main()

Add stop-generate to scripts/export_models.py