123b3eb3cSopenharmony_ci#!/usr/bin/env python
223b3eb3cSopenharmony_ci# -*- coding: utf-8 -*-
323b3eb3cSopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
423b3eb3cSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
523b3eb3cSopenharmony_ci# you may not use this file except in compliance with the License.
623b3eb3cSopenharmony_ci# You may obtain a copy of the License at
723b3eb3cSopenharmony_ci#
823b3eb3cSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
923b3eb3cSopenharmony_ci#
1023b3eb3cSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
1123b3eb3cSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
1223b3eb3cSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1323b3eb3cSopenharmony_ci# See the License for the specific language governing permissions and
1423b3eb3cSopenharmony_ci# limitations under the License.
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ciimport re
1723b3eb3cSopenharmony_ciimport sys
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci
2023b3eb3cSopenharmony_cidef main(input_path, output_path):
2123b3eb3cSopenharmony_ci    with open(output_path, "w", encoding="utf-8") as ohos:
2223b3eb3cSopenharmony_ci        export_content = "export default { "
2323b3eb3cSopenharmony_ci        with open(input_path, "r", encoding="utf-8") as f:
2423b3eb3cSopenharmony_ci            line = f.readline()
2523b3eb3cSopenharmony_ci            isFirstClass = True
2623b3eb3cSopenharmony_ci            class_num = 0
2723b3eb3cSopenharmony_ci            while (line):
2823b3eb3cSopenharmony_ci                ohos.write(line)
2923b3eb3cSopenharmony_ci                if (line.startswith("class ")):
3023b3eb3cSopenharmony_ci                    class_num += 1
3123b3eb3cSopenharmony_ci                    if class_num % 5 == 0:
3223b3eb3cSopenharmony_ci                        class_num = 0
3323b3eb3cSopenharmony_ci                        isFirstClass = True
3423b3eb3cSopenharmony_ci                        export_content += ",\n\t"
3523b3eb3cSopenharmony_ci
3623b3eb3cSopenharmony_ci                    class_name = re.match(r"class\s+(\w+)", line).group(1)
3723b3eb3cSopenharmony_ci                    if isFirstClass:
3823b3eb3cSopenharmony_ci                        isFirstClass = False
3923b3eb3cSopenharmony_ci                    else:
4023b3eb3cSopenharmony_ci                        export_content += ", "
4123b3eb3cSopenharmony_ci                    export_content += class_name
4223b3eb3cSopenharmony_ci                line = f.readline()
4323b3eb3cSopenharmony_ci            ohos.write("\n")
4423b3eb3cSopenharmony_ci        export_content += " };\n"
4523b3eb3cSopenharmony_ci        export_content += "globalThis.__getUIContext__ = __getUIContext__;\n"
4623b3eb3cSopenharmony_ci        export_content += "globalThis.__getFrameNodeByNodeId__ = __getFrameNodeByNodeId__;\n"
4723b3eb3cSopenharmony_ci        export_content += "globalThis.__checkRegexValid__ = __checkRegexValid__;"
4823b3eb3cSopenharmony_ci        ohos.write("\n" + export_content)
4923b3eb3cSopenharmony_ci
5023b3eb3cSopenharmony_ci
5123b3eb3cSopenharmony_ciif __name__ == "__main__":
5223b3eb3cSopenharmony_ci    main(sys.argv[1], sys.argv[2])
53