Skip to content

feat: add support for ArkTS #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions language/arkts/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("//:visibility.bzl", "PUBLIC_VISIBILITY")

# Using filegroup is encouraged instead of referencing directories directly. The latter is unsound.
# When combined with glob, filegroup can ensure that all files are explicitly known to the build system.

# Only one level of depth is matched, and the templates in the resource directory under lib-gen will not be matched.
filegroup(
name = "lib",
srcs = glob(["lib/*"]),
visibility = ["//visibility:public"],
)
26 changes: 26 additions & 0 deletions language/arkts/extractor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# IDEs
.vscode
.idea

# Dependency directory
node_modules/

# Build
dist/
out/

# Bazel
bazel-*

# SQLite
*.db
*.db-journal

# Coverage reports
coverage

# API keys and secrets
.env

# OS metadata
.DS_Store
62 changes: 62 additions & 0 deletions language/arkts/extractor/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
load("//:visibility.bzl", "PUBLIC_VISIBILITY")

genrule(
name = "ohos_typescript_compile",
srcs = [],
tools = [
"@ohos_typescript_src//:compile_typescript"
],
outs = ["ohos-typescript"],
cmd = """
export OHOS_TYPESCRIPT_SRC=$$(dirname $$(pwd)/$(execpath @ohos_typescript_src//:compile_typescript))
export OUTPUT_DIR=$$(dirname $$(pwd)/$@)
export OHOS_TYPESCRIPT_SRC_CP=$$OUTPUT_DIR/ohos_typescript_src
cp -r $$OHOS_TYPESCRIPT_SRC $$OUTPUT_DIR
mkdir $(OUTS)
# must change dir to src, then execute compile script
cd $$OHOS_TYPESCRIPT_SRC_CP
python3 compile_typescript.py . $$OUTPUT_DIR/ohos-typescript
echo ohos_typescript build success: $$OUTPUT_DIR/ohos-typescript
""",
)

genrule(
name = "build-coref-arkts-src-extractor",
srcs = glob(["src/**/*.ts"]) + glob(["sdk/**/*"]) + [
"schema.prisma",
"package.json",
"package-lock.json",
"paths.json",
"tsconfig.json",
"@pkg_cache//:node-bin",
] + [":ohos_typescript_compile"],
tools = [
"@nodejs_host//:npm_bin",
],
outs = [
"coref-arkts-src-extractor",
],
cmd = """
NPM_PATH="$$(pwd)/$(execpath @nodejs_host//:npm_bin)"
echo NPM_PATH: $$NPM_PATH

export PKG_CACHE_PATH=$$(dirname $$(dirname $$(pwd)/$(execpath @pkg_cache//:node-bin)))
echo PKG_CACHE_PATH: $$PKG_CACHE_PATH

OUT_PATH="$$(pwd)/$@"
echo OUT_PATH: $$OUT_PATH

# 注意在下面cd前对需要拷贝的typescript进行路径确认
export THIRD_TYPESCIRPT_PATH=$$(pwd)/$(location :ohos_typescript_compile)
echo THIRD_TYPESCIRPT_PATH: $$THIRD_TYPESCIRPT_PATH

cd language/arkts/extractor

$$NPM_PATH i --registry https://registry.antgroup-inc.cn
cp -rf $$THIRD_TYPESCIRPT_PATH ./node_modules/
$$NPM_PATH run pkg
mv coref-arkts-src-extractor $$OUT_PATH
""",
executable = 1,
visibility = ["//visibility:public"],
)
Loading