123b3eb3cSopenharmony_ci#!/usr/bin/env python 223b3eb3cSopenharmony_ci# -*- coding: utf-8 -*- 323b3eb3cSopenharmony_ci# Copyright (c) 2022 Huawei Device Co., Ltd. 423b3eb3cSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 523b3eb3cSopenharmony_ci# you may not use this file except in compliance with the License. 623b3eb3cSopenharmony_ci# You may obtain a copy of the License at 723b3eb3cSopenharmony_ci# 823b3eb3cSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 923b3eb3cSopenharmony_ci# 1023b3eb3cSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1123b3eb3cSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1223b3eb3cSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1323b3eb3cSopenharmony_ci# See the License for the specific language governing permissions and 1423b3eb3cSopenharmony_ci# limitations under the License. 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ciimport os 1723b3eb3cSopenharmony_ciimport sys 1823b3eb3cSopenharmony_ciimport subprocess 1923b3eb3cSopenharmony_ciimport shutil 2023b3eb3cSopenharmony_ci 2123b3eb3cSopenharmony_cidef main(argv): 2223b3eb3cSopenharmony_ci project_path = os.path.abspath(argv[1]) 2323b3eb3cSopenharmony_ci target_out_path = os.path.abspath(argv[2]) 2423b3eb3cSopenharmony_ci nodejs_path = os.path.abspath(argv[3]) 2523b3eb3cSopenharmony_ci js2bundle_path = os.path.abspath(argv[4]) 2623b3eb3cSopenharmony_ci interface_path = os.path.abspath(argv[5]) 2723b3eb3cSopenharmony_ci parse5_path = os.path.abspath(argv[6]) 2823b3eb3cSopenharmony_ci weex_loader_path = os.path.abspath(argv[7]) 2923b3eb3cSopenharmony_ci 3023b3eb3cSopenharmony_ci buildEnv = os.environ 3123b3eb3cSopenharmony_ci buildEnv["PATH"] = nodejs_path + ":" + buildEnv["PATH"] 3223b3eb3cSopenharmony_ci 3323b3eb3cSopenharmony_ci interface_target_path = os.path.join(target_out_path, "interface") 3423b3eb3cSopenharmony_ci if os.path.exists(interface_target_path): 3523b3eb3cSopenharmony_ci shutil.rmtree(interface_target_path) 3623b3eb3cSopenharmony_ci shutil.copytree(interface_path, interface_target_path, ignore=shutil.ignore_patterns('.git')) 3723b3eb3cSopenharmony_ci 3823b3eb3cSopenharmony_ci third_party_target_path = os.path.join(target_out_path, "third_party") 3923b3eb3cSopenharmony_ci if os.path.exists(third_party_target_path): 4023b3eb3cSopenharmony_ci shutil.rmtree(third_party_target_path) 4123b3eb3cSopenharmony_ci os.makedirs(third_party_target_path); 4223b3eb3cSopenharmony_ci 4323b3eb3cSopenharmony_ci parse5_target_path = os.path.join(third_party_target_path, "parse5") 4423b3eb3cSopenharmony_ci shutil.copytree(parse5_path, parse5_target_path, ignore=shutil.ignore_patterns('.git')) 4523b3eb3cSopenharmony_ci 4623b3eb3cSopenharmony_ci weex_loader_target_path = os.path.join(third_party_target_path, "weex-loader") 4723b3eb3cSopenharmony_ci shutil.copytree(weex_loader_path, weex_loader_target_path, ignore=shutil.ignore_patterns('.git')) 4823b3eb3cSopenharmony_ci 4923b3eb3cSopenharmony_ci js2bundle_target_path = os.path.join(target_out_path, "developtools") 5023b3eb3cSopenharmony_ci if os.path.exists(js2bundle_target_path): 5123b3eb3cSopenharmony_ci shutil.rmtree(js2bundle_target_path) 5223b3eb3cSopenharmony_ci os.makedirs(js2bundle_target_path); 5323b3eb3cSopenharmony_ci js2bundle_target_path = os.path.join(js2bundle_target_path, "ace_js2bundle") 5423b3eb3cSopenharmony_ci shutil.copytree(js2bundle_path, js2bundle_target_path, True, ignore=shutil.ignore_patterns('.git')) 5523b3eb3cSopenharmony_ci js2bundle_target_path = os.path.join(js2bundle_target_path, "ace-loader") 5623b3eb3cSopenharmony_ci os.chdir(js2bundle_target_path) 5723b3eb3cSopenharmony_ci 5823b3eb3cSopenharmony_ci js2bundle_node_modules_target_path = os.path.join(js2bundle_target_path, "node_modules") 5923b3eb3cSopenharmony_ci if not os.path.exists(js2bundle_node_modules_target_path): 6023b3eb3cSopenharmony_ci subprocess.call(["npm", "install"], env=buildEnv) 6123b3eb3cSopenharmony_ci 6223b3eb3cSopenharmony_ci target_i18n_path = os.path.join(js2bundle_target_path, "sample", "rich", "i18n") 6323b3eb3cSopenharmony_ci if os.path.exists(target_i18n_path): 6423b3eb3cSopenharmony_ci shutil.rmtree(target_i18n_path) 6523b3eb3cSopenharmony_ci source_i18n_path = os.path.join(project_path, "i18n") 6623b3eb3cSopenharmony_ci if os.path.exists(source_i18n_path): 6723b3eb3cSopenharmony_ci shutil.copytree(source_i18n_path, target_i18n_path, ignore=shutil.ignore_patterns('.git')) 6823b3eb3cSopenharmony_ci 6923b3eb3cSopenharmony_ci target_common_path = os.path.join(js2bundle_target_path, "sample", "rich", "common") 7023b3eb3cSopenharmony_ci if os.path.exists(target_common_path): 7123b3eb3cSopenharmony_ci shutil.rmtree(target_common_path) 7223b3eb3cSopenharmony_ci source_common_path = os.path.join(project_path, "common") 7323b3eb3cSopenharmony_ci if os.path.exists(source_common_path): 7423b3eb3cSopenharmony_ci shutil.copytree(source_common_path, target_common_path, ignore=shutil.ignore_patterns('.git')) 7523b3eb3cSopenharmony_ci 7623b3eb3cSopenharmony_ci target_index_path = os.path.join(js2bundle_target_path, "sample", "rich", "pages", "index") 7723b3eb3cSopenharmony_ci shutil.copyfile( 7823b3eb3cSopenharmony_ci os.path.join(project_path, "pages", "index", "index.css"), os.path.join(target_index_path, "index.css")) 7923b3eb3cSopenharmony_ci shutil.copyfile( 8023b3eb3cSopenharmony_ci os.path.join(project_path, "pages", "index", "index.hml"), os.path.join(target_index_path, "index.hml")) 8123b3eb3cSopenharmony_ci shutil.copyfile( 8223b3eb3cSopenharmony_ci os.path.join(project_path, "pages", "index", "index.js"), os.path.join(target_index_path, "index.js")) 8323b3eb3cSopenharmony_ci 8423b3eb3cSopenharmony_ci subprocess.call(["npm", "run", "build"], env=buildEnv) 8523b3eb3cSopenharmony_ci subprocess.call(["npm", "run", "rich"], env=buildEnv) 8623b3eb3cSopenharmony_ci 8723b3eb3cSopenharmony_ci target_build_path = os.path.join(js2bundle_target_path, "sample", "rich", "build") 8823b3eb3cSopenharmony_ci target_build_dest_path = os.path.join(target_out_path, "default") 8923b3eb3cSopenharmony_ci if os.path.exists(target_build_dest_path): 9023b3eb3cSopenharmony_ci shutil.rmtree(target_build_dest_path) 9123b3eb3cSopenharmony_ci shutil.copytree(target_build_path, target_build_dest_path) 9223b3eb3cSopenharmony_ci 9323b3eb3cSopenharmony_ciif __name__ == '__main__': 9423b3eb3cSopenharmony_ci main(sys.argv) 95