From fd219d09ef80cb184e25f0e2e525806f561145e0 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 16 Apr 2024 23:37:58 +0800 Subject: [PATCH] feat: add loadPackage node.js API Signed-off-by: peefy --- blog/2024-04-17-newsletter/index.md | 15 ++++++++++++++- .../2024-04-17-newsletter/index.md | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/blog/2024-04-17-newsletter/index.md b/blog/2024-04-17-newsletter/index.md index 1a21f78f..a5daef86 100644 --- a/blog/2024-04-17-newsletter/index.md +++ b/blog/2024-04-17-newsletter/index.md @@ -64,7 +64,7 @@ content = template.execute("""\ cargo add --git https://github.com/kcl-lang/lib ``` -- The initial release of the KCL Node.js SDK, supporting KCL code execution API and variable reading API. Repository link: [https://github.com/kcl-lang/lib/tree/main/nodejs](https://github.com/kcl-lang/lib/tree/main/nodejs). Contributions are welcome. +- The initial release of the KCL Node.js SDK. Repository link: [https://github.com/kcl-lang/lib/tree/main/nodejs](https://github.com/kcl-lang/lib/tree/main/nodejs). Contributions are welcome. + `__test__/test_data/schema.k` @@ -103,6 +103,19 @@ function main() { main(); ``` ++ `loadPackage` + +```ts +import { listVariables, ListVariablesArgs } from "kcl-lib"; + +function main() { + const result = loadPackage(LoadPackageArgs(['__test__/test_data/schema.k'], [], true)); + console.log(result.symbols); +} + +main(); +``` + **💻 IDE Updates** - Added compilation unit caching to enhance IDE performance. diff --git a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-04-17-newsletter/index.md b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-04-17-newsletter/index.md index ffc55823..9218d889 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-04-17-newsletter/index.md +++ b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-04-17-newsletter/index.md @@ -64,7 +64,7 @@ content = template.execute("""\ cargo add --git https://github.com/kcl-lang/lib ``` -- KCL Node.js SDK 初版发布,支持 KCL 代码运行 API 和变量读取 API,仓库地址 [https://github.com/kcl-lang/lib/tree/main/nodejs](https://github.com/kcl-lang/lib/tree/main/nodejs), 欢迎共建 +- KCL Node.js SDK 初版发布,仓库地址 [https://github.com/kcl-lang/lib/tree/main/nodejs](https://github.com/kcl-lang/lib/tree/main/nodejs), 欢迎共建 + `__test__/test_data/schema.k` @@ -103,6 +103,19 @@ function main() { main(); ``` ++ `execProgram` + +```ts +import { listVariables, ListVariablesArgs } from "kcl-lib"; + +function main() { + const result = loadPackage(LoadPackageArgs(['__test__/test_data/schema.k'], [], true)); + console.log(result.symbols); +} + +main(); +``` + **💻 IDE 更新** - 新增编译单元缓存提升 IDE 性能