1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2025 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 16# Description 17# 18# This script is invoked by the build system and does not need to be executed directly by the developer. 19# First, it checks if --release is provided as an argument. This is the only allowed type for stateMgmt 20# that is included in the build image. It then verifies if the node_modules folder exists. If not, npm 21# install is executed. Afterward, npm run build_release is performed, which also generates generateGni.js 22# The files_to_watch.gni file contains a list of input files from tsconfig.base.json. When any of these 23# files are modified, the build system triggers this script to regenerate stateMgmt.js. 24 25import os 26import sys 27import json 28import time 29import shutil 30import subprocess 31from typing import Dict, List 32 33from preprocess import merge_component 34 35class Paths: 36 def __init__(self): 37 self.project_path = None 38 39 40def parse_argv(argv) -> Paths: 41 """ 42 parse command line arguments 43 """ 44 if len(argv) < 2: 45 print("Usage: python process.py <project_path>") 46 sys.exit(1) 47 48 path = Paths() 49 path.project_path = os.path.abspath(argv[1]) 50 51 return path 52 53def pre_processing(path: Paths): 54 start_time = time.time() 55 target_path = os.path.join( 56 path.project_path, "arkui-preprocessed") 57 58 handwritten_path = os.path.join(target_path, "src", "handwritten", "component") 59 generated_path = os.path.join(target_path, "src", "component") 60 merge_component(handwritten_path, generated_path) 61 62 if os.path.exists(handwritten_path): 63 shutil.rmtree(handwritten_path) 64 src_path = os.path.join(target_path, "src") 65 dist_path = os.path.join(target_path, "arkui") 66 # rename "src" to "arkui" 67 if os.path.exists(src_path) and (not os.path.exists(dist_path)): 68 shutil.move(src_path, dist_path) 69 end_time = time.time() 70 elapsed_time = end_time - start_time 71 print(f"Arkoala: preprocess time: {elapsed_time:.2f} seconds") 72 return 73 74def main(argv): 75 path = parse_argv(argv) 76 os.chdir(path.project_path) 77 pre_processing(path) 78 79 80if __name__ == '__main__': 81 start_time = time.time() 82 main(sys.argv) 83 end_time = time.time() 84 elapsed_time = end_time - start_time 85 print(f"Arkoala: build time: {elapsed_time:.2f} seconds")