• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2022 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 shutil
17import platform
18import argparse
19import subprocess
20
21
22def run_command(in_cmd):
23    print(" ".join(in_cmd))
24    proc = subprocess.Popen(in_cmd, stdout=subprocess.PIPE,
25                          stderr=subprocess.PIPE,
26                          universal_newlines=True,
27                          shell=False)
28    stdout, stderr = proc.communicate()
29    if stdout != "":
30        raise Exception(stdout)
31
32if __name__ == '__main__':
33    PARSER_INST = argparse.ArgumentParser()
34    PARSER_INST.add_argument('--dst-file',
35                        help='the converted target file')
36    PARSER_INST.add_argument('--module-path',
37                        help='the module path')
38    PARSER_INST.add_argument('--out-file',
39                        help='js output file')
40    INPUT_ARGUMENTS = PARSER_INST.parse_args()
41
42    BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), "../.."))
43    os.chdir(("%s" + INPUT_ARGUMENTS.module_path) % BUILD_PATH)
44    NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\
45node-v12.18.4-linux-x64/bin/node'
46    if not os.path.exists(NODE_PATH):
47        raise Exception('NO souch file or directory')
48    TSC_PATH = '../../../../ark/ts2abc/ts2panda/node_modules/\
49typescript/bin/tsc'
50    CMD_INST = [NODE_PATH, TSC_PATH]
51    run_command(CMD_INST)
52    if not os.path.exists(INPUT_ARGUMENTS.out_file):
53        raise Exception('error:NO souch file or directory')
54    CMD_INST = shutil.copy(INPUT_ARGUMENTS.out_file, INPUT_ARGUMENTS.dst_file)
55
56    CMD_INST = shutil.rmtree('./out')
57
58    exit(0)