1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 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. 15import os 16import platform 17import argparse 18import subprocess 19import sys 20 21def run_command(command): 22 print(" ".join(command)) 23 proc = subprocess.Popen(command, stdout=subprocess.PIPE, 24 stderr=subprocess.PIPE, universal_newlines=True, shell=False) 25 out, err = proc.communicate() 26 if out != "": 27 print(out) 28 exit(1) 29 30if __name__ == '__main__': 31 parser = argparse.ArgumentParser() 32 parser.add_argument('--dst-file', 33 help='the converted target file') 34 parser.add_argument('--relative-path', 35 help='the code root path relative the root_build_dir') 36 parser.add_argument('--out-filePath', 37 help='js output filePath') 38 input_arguments = parser.parse_args() 39 40 build_path = os.path.abspath(os.path.join(os.getcwd(), input_arguments.relative_path)) 41 os.chdir("%s/commonlibrary/ets_utils/js_util_module/container/" % build_path) 42 43 os_name = sys.platform 44 NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/current/bin/node' 45 TSC_PATH = '../../../../third_party/typescript/bin/tsc' 46 cmd = [NODE_PATH, TSC_PATH, "--outDir", input_arguments.out_filePath] 47 run_command(cmd) 48 49 for dirname in os.listdir(input_arguments.out_filePath) : 50 filepath = os.path.join(input_arguments.out_filePath, dirname) 51 for filename in os.listdir(filepath) : 52 dstpath = os.path.join(input_arguments.dst_file, filename) 53 srcpath = os.path.join(filepath, filename) 54 cmd = ['cp', "-r", srcpath, dstpath] 55 run_command(cmd) 56 57 cmd = ['rm', "-rf", input_arguments.out_filePath] 58 run_command(cmd) 59 exit(0) 60