1#!/usr/bin/env python 2# coding: utf-8 3# Copyright (c) 2023 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 shutil 18import sys 19import subprocess 20 21 22def run_cmd(cmd, execution_path=None): 23 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, 24 stdin=subprocess.PIPE, 25 stderr=subprocess.PIPE, 26 cwd=execution_path) 27 stdout, stderr = proc.communicate() 28 if proc.returncode != 0: 29 print(stdout.decode(), stderr.decode()) 30 raise Exception(stderr.decode()) 31 32target_files = [ 33 "lib", 34 "bin", 35 "package.json", 36 "LICENSE", 37 "README.md", 38 "README.OpenSource", 39 "SECURITY.md", 40 "ThirdPartyNoticeText.txt" 41] 42 43def run_pack(execution_path, dest_out_path): 44 copy_cmd = ["cp", "-r"] + target_files + [dest_out_path] 45 run_cmd(copy_cmd, execution_path) 46 run_cmd(["npm", "pack"], dest_out_path) 47 48 49def main(args): 50 source_path = args[0] 51 dest_out_path = args[1] 52 run_pack(source_path, dest_out_path) 53 54 55if __name__ == '__main__': 56 main(sys.argv[1:])