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 16import argparse 17import sys 18import os 19import shutil 20import subprocess 21 22PARSE_ETS2_API = "interface/sdk-js/build-tools/arkui_transformer" 23PACKAGE_PATH = "build/arkui_transformer.js" 24 25 26def compile_package(options): 27 tool_path = os.path.abspath(os.path.join(options.source_root_dir, PARSE_ETS2_API)) 28 npm = os.path.abspath(options.npm_path) 29 package_path = os.path.abspath(os.path.join(options.source_root_dir, PARSE_ETS2_API, PACKAGE_PATH)) 30 nodejs = os.path.abspath(options.node_js) 31 input_dir = os.path.abspath(options.input) 32 output = os.path.abspath(options.output) 33 config_path = '' 34 if (len(options.config_path) > 0): 35 config_path = os.path.abspath(options.config_path) 36 37 custom_env = { 38 'PATH': f"{os.path.dirname(os.path.abspath(options.node_js))}:{os.environ.get('PATH')}", 39 'NODE_HOME': os.path.dirname(os.path.abspath(options.node_js)), 40 } 41 42 process = subprocess.run([npm, "run", "compile:arkui"], env=custom_env, cwd=tool_path, shell=False) 43 44 if os.path.exists(package_path): 45 if (len(config_path) > 0): 46 p = subprocess.run([nodejs, package_path, "--input-dir", input_dir, "--target-dir", output, "--config-path", config_path], cwd=tool_path, shell=False) 47 else: 48 p = subprocess.run([nodejs, package_path, "--input-dir", input_dir, "--target-dir", output], cwd=tool_path, shell=False) 49 else: 50 print("arkui_transformer: tool path does not exist") 51 52 return process 53 54 55def main(): 56 parser = argparse.ArgumentParser() 57 parser.add_argument('--input', required=True) 58 parser.add_argument('--output', required=True) 59 parser.add_argument('--config_path', required=False, default='') 60 parser.add_argument('--source_root_dir', required=True) 61 parser.add_argument('--npm-path', required=True) 62 parser.add_argument('--node-js', required=True) 63 options = parser.parse_args() 64 compile_package(options) 65 66 67if __name__ == '__main__': 68 sys.exit(main()) 69