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.
15
16import os
17import sys
18import subprocess
19import shutil
20
21def main(argv):
22    project_path = os.path.abspath(argv[1])
23    target_out_path = os.path.abspath(argv[2])
24    nodejs_path = os.path.abspath(argv[3])
25    js2bundle_path = os.path.abspath(argv[4])
26    interface_path = os.path.abspath(argv[5])
27    parse5_path = os.path.abspath(argv[6])
28    weex_loader_path = os.path.abspath(argv[7])
29
30    buildEnv = os.environ
31    buildEnv["PATH"] = nodejs_path + ":" + buildEnv["PATH"]
32
33    interface_target_path = os.path.join(target_out_path, "interface")
34    if os.path.exists(interface_target_path):
35        shutil.rmtree(interface_target_path)
36    shutil.copytree(interface_path, interface_target_path, ignore=shutil.ignore_patterns('.git'))
37
38    third_party_target_path = os.path.join(target_out_path, "third_party")
39    if os.path.exists(third_party_target_path):
40        shutil.rmtree(third_party_target_path)
41    os.makedirs(third_party_target_path);
42
43    parse5_target_path = os.path.join(third_party_target_path, "parse5")
44    shutil.copytree(parse5_path, parse5_target_path, ignore=shutil.ignore_patterns('.git'))
45
46    weex_loader_target_path = os.path.join(third_party_target_path, "weex-loader")
47    shutil.copytree(weex_loader_path, weex_loader_target_path, ignore=shutil.ignore_patterns('.git'))
48
49    js2bundle_target_path = os.path.join(target_out_path, "developtools")
50    if os.path.exists(js2bundle_target_path):
51        shutil.rmtree(js2bundle_target_path)
52    os.makedirs(js2bundle_target_path);
53    js2bundle_target_path = os.path.join(js2bundle_target_path, "ace_js2bundle")
54    shutil.copytree(js2bundle_path, js2bundle_target_path, True, ignore=shutil.ignore_patterns('.git'))
55    js2bundle_target_path = os.path.join(js2bundle_target_path, "ace-loader")
56    os.chdir(js2bundle_target_path)
57
58    js2bundle_node_modules_target_path = os.path.join(js2bundle_target_path, "node_modules")
59    if not os.path.exists(js2bundle_node_modules_target_path):
60        subprocess.call(["npm", "install"], env=buildEnv)
61
62    target_i18n_path = os.path.join(js2bundle_target_path, "sample", "rich", "i18n")
63    if os.path.exists(target_i18n_path):
64        shutil.rmtree(target_i18n_path)
65    source_i18n_path = os.path.join(project_path, "i18n")
66    if os.path.exists(source_i18n_path):
67        shutil.copytree(source_i18n_path, target_i18n_path, ignore=shutil.ignore_patterns('.git'))
68
69    target_common_path = os.path.join(js2bundle_target_path, "sample", "rich", "common")
70    if os.path.exists(target_common_path):
71        shutil.rmtree(target_common_path)
72    source_common_path = os.path.join(project_path, "common")
73    if os.path.exists(source_common_path):
74        shutil.copytree(source_common_path, target_common_path, ignore=shutil.ignore_patterns('.git'))
75
76    target_index_path = os.path.join(js2bundle_target_path, "sample", "rich", "pages", "index")
77    shutil.copyfile(
78        os.path.join(project_path, "pages", "index", "index.css"), os.path.join(target_index_path, "index.css"))
79    shutil.copyfile(
80        os.path.join(project_path, "pages", "index", "index.hml"), os.path.join(target_index_path, "index.hml"))
81    shutil.copyfile(
82        os.path.join(project_path, "pages", "index", "index.js"), os.path.join(target_index_path, "index.js"))
83
84    subprocess.call(["npm", "run", "build"], env=buildEnv)
85    subprocess.call(["npm", "run", "rich"], env=buildEnv)
86
87    target_build_path = os.path.join(js2bundle_target_path, "sample", "rich", "build")
88    target_build_dest_path = os.path.join(target_out_path, "default")
89    if os.path.exists(target_build_dest_path):
90        shutil.rmtree(target_build_dest_path)
91    shutil.copytree(target_build_path, target_build_dest_path)
92
93if __name__ == '__main__':
94    main(sys.argv)
95