1#!/bin/bash 2# Copyright (c) 2025 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15#!/bin/bash 16set -e 17 18if [ ! -d "../compiler" ]; then 19 echo "Error: must run this script in ace_ets2bundle/compiler root directory" 20 exit 1 21fi 22 23oriDir=$(pwd) 24 25DECLGEN_ROOT_DIR="../../../arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts" 26 27cd "$DECLGEN_ROOT_DIR" || { echo "Failed to change directory to $DECLGEN_ROOT_DIR"; exit 1; } 28 29npm install 30npm run build 31 32# Generate the npm package using `npm pack` 33if npm pack; then 34 tarball=$(ls *.tgz) # Get the generated tarball file name 35 if [ -f "$tarball" ]; then 36 # Move the tarball to the original directory 37 mv "$tarball" "$oriDir/" 38 39 # Go back to the original directory and extract the tarball 40 cd "$oriDir" 41 tar -xvzf "$tarball" 42 43 # Rename the extracted directory (assuming it is named after the package) 44 extracted_dir=$(tar -tf "$tarball" | head -n 1 | cut -f1 -d"/") # Get the extracted folder name 45 mv "$extracted_dir" "./node_modules/declgen" # Rename to 'declgen' 46 47 # Optionally, remove the tarball after extraction 48 rm "$tarball" 49 50 echo "Build successfully packed, extracted, and renamed to 'declgen' in $oriDir" 51 else 52 echo "Error: No tarball found, cannot proceed" 53 exit 1 54 fi 55else 56 echo "Error: npm pack failed" 57 exit 1 58fi 59