diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/.prettierignore b/static_core/plugins/ets/tools/declgen_ts2sts/.prettierignore index 3a15a7bfa6df1dba1e86fa970f2107a6162db7de..5ba3960e48e72b01d4e118586faa5df929ff2ebd 100644 --- a/static_core/plugins/ets/tools/declgen_ts2sts/.prettierignore +++ b/static_core/plugins/ets/tools/declgen_ts2sts/.prettierignore @@ -19,5 +19,6 @@ /node_modules/** /scripts/** /test/** +/third_party/** **.json **.js diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/BUILD.gn b/static_core/plugins/ets/tools/declgen_ts2sts/BUILD.gn index 674e14b5650ebcb1f9f689b04e9bf6a1e0c1c541..ecf69236b16422add193226b8709dff4e981880a 100644 --- a/static_core/plugins/ets/tools/declgen_ts2sts/BUILD.gn +++ b/static_core/plugins/ets/tools/declgen_ts2sts/BUILD.gn @@ -22,6 +22,9 @@ if ((defined(ark_standalone_build) && ark_standalone_build) || "//build/config/components/runtime_core/static_core/ark_common_config.gni") } +typescript_dir = get_label_info("//third_party/typescript:build_typescript", + "target_out_dir") + action("build_declgen") { sources = [ "package.json", @@ -42,11 +45,13 @@ action("build_declgen") { ] script = "compile_declgen.py" + external_deps = [ "typescript:build_typescript_etc" ] tgz_name = "panda-declgen-1.0.0.tgz" args = [ rebase_path(get_path_info("./", "abspath")), rebase_path("${target_out_dir}"), tgz_name, + rebase_path("${typescript_dir}/ohos-typescript-4.9.5-r4.tgz"), ] outputs = [ "${target_out_dir}/${tgz_name}" ] diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py b/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py index f38e1c8390a44d4a52541b68311d7cbc0dab45f8..81c1816785d86d16a29bfdfe4b97c5597ee8abda 100755 --- a/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py +++ b/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py @@ -20,6 +20,16 @@ import tarfile import os import shutil +def extract(package_path, dest_path, package_name): + try: + with tarfile.open(package_path, 'r:gz') as tar: + tar.extractall(path=dest_path) + except tarfile.TarError as e: + print(f'Error extracting files: {e}') + dest_package_path = os.path.join(dest_path, package_name) + if (os.path.exists(dest_package_path)): + shutil.rmtree(dest_package_path) + os.rename(os.path.join(dest_path, 'package'), dest_package_path) def copy_dir(source_path, dest_path): try: @@ -66,10 +76,13 @@ def main(args): dest_and_exec_path = args[1] tgz_name = args[2] tmp_build_dir = os.path.join(dest_and_exec_path, "build_tmp") + tsc_package_path = args[3] copy_dir(source_path, tmp_build_dir) run_build(tmp_build_dir) run_pack(tmp_build_dir) + node_modules_path = os.path.join(dest_and_exec_path,"node_modules") + extract(tsc_package_path, node_modules_path, "typescript") src_file = os.path.join(tmp_build_dir, tgz_name) dst_file = os.path.join(dest_and_exec_path, tgz_name) diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/package.json b/static_core/plugins/ets/tools/declgen_ts2sts/package.json index 95061583f4e8b23f5e5bad18b971ac85bad168e0..b1e9335f82c3a8159128325aaf4b38d71a25f25c 100644 --- a/static_core/plugins/ets/tools/declgen_ts2sts/package.json +++ b/static_core/plugins/ets/tools/declgen_ts2sts/package.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "scripts": { "tsc": "tsc", - "postinstall": "npm run build", + "postinstall": "bash ./script/install_tsc.sh && npm run build", "webpack": "webpack -t node --config webpack.config.js", "clean": "rimraf build dist bundle", "compile": "npm run tsc", @@ -28,7 +28,7 @@ "dependencies": { "commander": "^9.4.0", "log4js": "^6.4.0", - "typescript": "npm:ohos-typescript@4.9.5-r9" + "typescript": "npm:ohos-typescript@4.9.5-r4" }, "devDependencies": { "@eslint/js": "8.57.1", diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/script/install_tsc.sh b/static_core/plugins/ets/tools/declgen_ts2sts/script/install_tsc.sh index 56d8fbb9dc5d5b6ce09f0cbfbe9bbaf4a795e442..f7102722e9c3d8f2bce1213a33e00572a145189c 100755 --- a/static_core/plugins/ets/tools/declgen_ts2sts/script/install_tsc.sh +++ b/static_core/plugins/ets/tools/declgen_ts2sts/script/install_tsc.sh @@ -21,28 +21,20 @@ ROOT_DIR="${1:-$(pwd)}" # Clone the repository and checkout the current Git branch TYPESCRIPT_REPO="https://gitee.com/openharmony/third_party_typescript.git" # Replace with your correct Typescript repository URL -CURRENT_BRANCH=$(git rev-parse --abbrev-ref @{u} | sed 's/^openharmony\///') +CURRENT_BRANCH="OpenHarmony-v5.1.0-Release" # Define the third_party directory THIRD_PARTY_DIR="$ROOT_DIR/third_party" TYPESCRIPT_ROOT_DIR="$THIRD_PARTY_DIR/typescript" # Set the directory to 'typescript' inside 'third_party' # Clone the repository if it doesn't exist, or fetch the latest changes -if [ ! -d "$TYPESCRIPT_ROOT_DIR" ]; then - echo "Cloning the TypeScript repository..." - mkdir -p "$THIRD_PARTY_DIR" # Create third_party directory if it doesn't exist - git clone "$TYPESCRIPT_REPO" "$TYPESCRIPT_ROOT_DIR" -else - echo "Repository already exists. Pulling the latest changes..." - cd "$TYPESCRIPT_ROOT_DIR" - - # Fetch the latest changes and ensure we are on the correct branch - git fetch origin - - git checkout "$CURRENT_BRANCH" - git pull origin "$CURRENT_BRANCH" - cd - +if [ -d "$TYPESCRIPT_ROOT_DIR" ]; then + echo "Directory $TYPESCRIPT_ROOT_DIR exists, removing..." + rm -rf "$TYPESCRIPT_ROOT_DIR" fi +echo "Cloning the TypeScript repository, tag: $CURRENT_BRANCH" +mkdir -p "$THIRD_PARTY_DIR" +git clone --depth 1 --branch "$CURRENT_BRANCH" "$TYPESCRIPT_REPO" "$TYPESCRIPT_ROOT_DIR" old_work_dir=$(pwd) echo "-----------------------------start building typescript-----------------------------"