1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import re
17import sys
18
19
20def main(input_path, output_path):
21    with open(output_path, "w", encoding="utf-8") as ohos:
22        export_content = "export default { "
23        with open(input_path, "r", encoding="utf-8") as f:
24            line = f.readline()
25            isFirstClass = True
26            class_num = 0
27            while (line):
28                ohos.write(line)
29                if (line.startswith("class ")):
30                    class_num += 1
31                    if class_num % 5 == 0:
32                        class_num = 0
33                        isFirstClass = True
34                        export_content += ",\n\t"
35
36                    class_name = re.match(r"class\s+(\w+)", line).group(1)
37                    if isFirstClass:
38                        isFirstClass = False
39                    else:
40                        export_content += ", "
41                    export_content += class_name
42                line = f.readline()
43            ohos.write("\n")
44        export_content += " };\n"
45        export_content += "globalThis.__getUIContext__ = __getUIContext__;\n"
46        export_content += "globalThis.__getFrameNodeByNodeId__ = __getFrameNodeByNodeId__;\n"
47        export_content += "globalThis.__checkRegexValid__ = __checkRegexValid__;"
48        ohos.write("\n" + export_content)
49
50
51if __name__ == "__main__":
52    main(sys.argv[1], sys.argv[2])
53