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 19 20def run_command(command): 21 print(" ".join(command)) 22 proc = subprocess.Popen(command, stdout=subprocess.PIPE, 23 stderr=subprocess.PIPE, universal_newlines=True) 24 out, err = proc.communicate() 25 if out != "": 26 print(out) 27 exit(1) 28 29if __name__ == '__main__': 30 parser = argparse.ArgumentParser() 31 parser.add_argument('--dst-file', 32 help='the converted target file') 33 parser.add_argument('--relative-path', 34 help='the code root path relative the root_build_dir') 35 input_arguments = parser.parse_args() 36 37 build_path = os.path.abspath(os.path.join(os.getcwd(), input_arguments.relative_path)) 38 os.chdir("%s/commonlibrary/ets_utils/js_util_module/container/" % build_path) 39 40 41 NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\ 42node-v12.18.4-linux-x64/bin/node' 43 TSC_PATH = '../../../../arkcompiler/ets_frontend/ts2panda/node_modules/typescript/bin/tsc' 44 cmd = [NODE_PATH, TSC_PATH] 45 run_command(cmd) 46 47 for dirname in os.listdir("./jscode") : 48 filepath = os.path.join("./jscode", dirname) 49 for filename in os.listdir(filepath) : 50 dstpath = os.path.join(input_arguments.dst_file, filename) 51 srcpath = os.path.join(filepath, filename) 52 cmd = ['cp', "-r", srcpath, dstpath] 53 run_command(cmd) 54 55 cmd = ['rm', "-rf", './jscode'] 56 run_command(cmd) 57 exit(0) 58