cj-tauri 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -18
- package/cjpm.toml +52 -52
- package/cli/cjpm.toml +10 -1
- package/cli/src/doctor.cj +4 -2
- package/cli/src/main.cj +11 -3
- package/cli/src/manifest.cj +558 -0
- package/cli/src/project.cj +38 -22
- package/cli/src/scaffold.cj +369 -361
- package/cli/src/sync.cj +526 -0
- package/cli/src/util.cj +168 -159
- package/cli/templates/app/README.md +48 -80
- package/cli/templates/app/{capabilities → assets/capabilities}/default.json +7 -7
- package/cli/templates/app/{ui → assets/ui}/index.html +118 -118
- package/cli/templates/app/cj-tauri.toml +22 -0
- package/cli/templates/app/cjpm.toml +34 -17
- package/cli/templates/app/src/main.cj +90 -88
- package/cli/templates/app-react/README.md +56 -67
- package/cli/templates/app-react/{capabilities → assets/capabilities}/default.json +7 -7
- package/cli/templates/app-react/{ui → assets/ui}/package.json +19 -19
- package/cli/templates/app-react/{ui → assets/ui}/src/main.jsx +6 -6
- package/cli/templates/app-react/{ui → assets/ui}/vite.config.js +24 -24
- package/cli/templates/app-react/cj-tauri.toml +23 -0
- package/cli/templates/app-react/cjpm.toml +34 -17
- package/cli/templates/app-react/src/main.cj +91 -102
- package/cli/templates/app-vue/README.md +56 -60
- package/cli/templates/app-vue/{capabilities → assets/capabilities}/default.json +7 -7
- package/cli/templates/app-vue/{ui → assets/ui}/package.json +18 -18
- package/cli/templates/app-vue/{ui → assets/ui}/src/main.js +4 -4
- package/cli/templates/app-vue/{ui → assets/ui}/vite.config.js +24 -24
- package/cli/templates/app-vue/cj-tauri.toml +23 -0
- package/cli/templates/app-vue/cjpm.toml +34 -17
- package/cli/templates/app-vue/src/main.cj +91 -102
- package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/app.json5 +13 -13
- package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/element/string.json +8 -8
- package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/layered_image.json +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/README.md +79 -79
- package/cli/templates/{ohos-pc → ohos-skeleton}/build-profile.json5 +46 -46
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/build-profile.json5 +26 -26
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/cjpm.toml +43 -43
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/hvigorfile.ts +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/oh-package.json5 +9 -9
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/ability_stage.cj +17 -17
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/app_host.cj +94 -94
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/index.cj +167 -167
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/main_ability.cj +139 -139
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/module.json5 +49 -49
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/element/color.json +8 -8
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/element/string.json +16 -16
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/layered_image.json +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/profile/main_pages.json +2 -2
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/rawfile/capabilities.json +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/rawfile/index.html +92 -92
- package/cli/templates/{ohos-pc → ohos-skeleton}/hvigor/hvigor-config.json5 +5 -5
- package/cli/templates/{ohos-pc → ohos-skeleton}/hvigorfile.ts +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/oh-package.json5 +10 -10
- package/package.json +4 -2
- package/prebuilt/win32-x64/cj-tauri.exe +0 -0
- package/src/app.cj +49 -20
- package/src/app_spec.cj +76 -0
- package/src/arkweb_script.cj +142 -154
- package/src/host.cj +20 -17
- package/src/host_arkweb.cj +778 -740
- package/src/host_webkit.cj +22 -0
- package/src/host_webview2.cj +22 -0
- package/src/launch.cj +62 -0
- package/src/platform/platform_app_context.cj +77 -0
- package/src/platform/platform_assets.cj +33 -0
- package/src/platform/platform_discover.cj +176 -0
- package/src/platform/platform_env.cj +29 -0
- package/src/platform/platform_feature.cj +31 -0
- package/src/platform/platform_page_source.cj +87 -0
- package/src/platform/platform_target_info.cj +32 -0
- package/src/platform_host_provider.cj +87 -0
- package/src/plugin.cj +36 -2
- package/src/plugins/clipboard/plugin_clipboard.cj +8 -0
- package/src/plugins/menu/plugin_menu.cj +158 -150
- package/src/plugins/notification/plugin_notification.cj +8 -0
- package/src/plugins/serial/plugin_serial.cj +454 -442
- package/src/plugins/serial/serial_bridge.cj +194 -186
- package/src/plugins/serial/serial_ohos_stub.cj +61 -0
- package/src/plugins/shell/plugin_shell.cj +258 -230
- package/src/plugins/sqlite/plugin_sqlite.cj +710 -697
- package/src/plugins/sqlite/sqlite_ffi.cj +211 -206
- package/src/plugins/sqlite/sqlite_ohos_stub.cj +91 -0
- package/src/tests/app_spec_test.cj +127 -0
- package/src/tests/fake_host.cj +23 -8
- package/src/tests/platform_contract_test.cj +251 -0
- package/src/tests/plugin_test.cj +585 -542
- package/src/version.cj +1 -1
- package/src/host_factory.cj +0 -48
- /package/cli/templates/app-react/{ui → assets/ui}/index.html +0 -0
- /package/cli/templates/app-react/{ui → assets/ui}/src/App.css +0 -0
- /package/cli/templates/app-react/{ui → assets/ui}/src/App.jsx +0 -0
- /package/cli/templates/app-vue/{ui → assets/ui}/index.html +0 -0
- /package/cli/templates/app-vue/{ui → assets/ui}/src/App.vue +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/background.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/foreground.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/build-hap.sh +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/background.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/foreground.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/startIcon.png +0 -0
package/cli/src/project.cj
CHANGED
|
@@ -10,7 +10,7 @@ import std.collection.*
|
|
|
10
10
|
|
|
11
11
|
/** CLI 版本:须与 cli/cjpm.toml 的 version、CHANGELOG 顶部版本一致(scripts/check-version.sh 校验) */
|
|
12
12
|
func cliVersion(): String {
|
|
13
|
-
return "
|
|
13
|
+
return "2.0.0"
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/** 一次命令所需的路径上下文 */
|
|
@@ -19,12 +19,15 @@ public class AppContext {
|
|
|
19
19
|
let frameworkRoot: String
|
|
20
20
|
let stdx: String
|
|
21
21
|
let cjpm: String
|
|
22
|
+
/** 新形态工程(工程根带 cj-tauri.toml 清单):可执行产物在 targets/desktop 骨架,前端在 assets/ui */
|
|
23
|
+
let newForm: Bool
|
|
22
24
|
|
|
23
|
-
public init(projectRoot: String, frameworkRoot: String, stdx: String, cjpm: String) {
|
|
25
|
+
public init(projectRoot: String, frameworkRoot: String, stdx: String, cjpm: String, newForm: Bool) {
|
|
24
26
|
this.projectRoot = projectRoot
|
|
25
27
|
this.frameworkRoot = frameworkRoot
|
|
26
28
|
this.stdx = stdx
|
|
27
29
|
this.cjpm = cjpm
|
|
30
|
+
this.newForm = newForm
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -46,9 +49,10 @@ func findProjectRoot(): Option<String> {
|
|
|
46
49
|
return None
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
/**
|
|
50
|
-
func findAppBinary(projectRoot: String): Option<String> {
|
|
51
|
-
let
|
|
52
|
+
/** 可执行产物:旧形态 = 工程根 target/release/bin/main[.exe];新形态 = targets/desktop 骨架 */
|
|
53
|
+
func findAppBinary(projectRoot: String, newForm: Bool): Option<String> {
|
|
54
|
+
let base = if (newForm) { joinPath(projectRoot, "targets/desktop") } else { projectRoot }
|
|
55
|
+
let binDir = joinPath(joinPath(joinPath(base, "target"), "release"), "bin")
|
|
52
56
|
if (!exists(binDir)) {
|
|
53
57
|
return None
|
|
54
58
|
}
|
|
@@ -200,10 +204,12 @@ func loadContext(): Option<AppContext> {
|
|
|
200
204
|
eprintln(" 请把仓颉 SDK 的 tools/bin 与 bin 加入 PATH,或设置 CANGJIE_HOME")
|
|
201
205
|
return None
|
|
202
206
|
}
|
|
203
|
-
|
|
207
|
+
// 新旧形态判据:工程根有没有 cj-tauri.toml(RFC-002 §7 的单一真相文件)
|
|
208
|
+
let newForm = exists(joinPath(proj, "cj-tauri.toml"))
|
|
209
|
+
return Some(AppContext(proj, fw, stdx, cjpm, newForm))
|
|
204
210
|
}
|
|
205
211
|
|
|
206
|
-
/** 前端工程(Vite
|
|
212
|
+
/** 前端工程(Vite):新形态在 assets/ui、旧形态在 ui;有 package.json 才启用,没有整段跳过 */
|
|
207
213
|
class WebUi {
|
|
208
214
|
let dir: String
|
|
209
215
|
let devUrl: String
|
|
@@ -218,8 +224,9 @@ class WebUi {
|
|
|
218
224
|
}
|
|
219
225
|
}
|
|
220
226
|
|
|
221
|
-
func detectWebUi(projectRoot: String): Option<WebUi> {
|
|
222
|
-
let
|
|
227
|
+
func detectWebUi(projectRoot: String, newForm: Bool): Option<WebUi> {
|
|
228
|
+
let uiSub = if (newForm) { "assets/ui" } else { "ui" }
|
|
229
|
+
let dir = joinPath(projectRoot, uiSub)
|
|
223
230
|
if (exists(joinPath(dir, "package.json"))) {
|
|
224
231
|
return Some(WebUi(dir))
|
|
225
232
|
}
|
|
@@ -392,10 +399,10 @@ func runWithDevServer(c: AppContext, ui: WebUi): Int64 {
|
|
|
392
399
|
return code
|
|
393
400
|
}
|
|
394
401
|
|
|
395
|
-
/** 构建:桥 + cjpm build;withUi=true 时先打前端发布包(有
|
|
402
|
+
/** 构建:桥 + cjpm build;withUi=true 时先打前端发布包(有 Vite 前端才会触发) */
|
|
396
403
|
func buildProject(c: AppContext, withUi: Bool): Bool {
|
|
397
404
|
if (withUi) {
|
|
398
|
-
if (let Some(ui) <- detectWebUi(c.projectRoot)) {
|
|
405
|
+
if (let Some(ui) <- detectWebUi(c.projectRoot, c.newForm)) {
|
|
399
406
|
if (!ensureUiDeps(ui)) {
|
|
400
407
|
return false
|
|
401
408
|
}
|
|
@@ -408,13 +415,20 @@ func buildProject(c: AppContext, withUi: Bool): Bool {
|
|
|
408
415
|
if (!ensureBridge(c.frameworkRoot)) {
|
|
409
416
|
return false
|
|
410
417
|
}
|
|
411
|
-
|
|
412
|
-
let
|
|
418
|
+
// 新形态:编 targets/desktop 骨架(path 依赖会连带编业务 static 包 + launcher 可执行)
|
|
419
|
+
let buildDir = if (c.newForm) { joinPath(c.projectRoot, "targets/desktop") } else { c.projectRoot }
|
|
420
|
+
if (!exists(joinPath(buildDir, "cjpm.toml"))) {
|
|
421
|
+
eprintln("[cj-tauri] 错误: 骨架未生成:${buildDir}")
|
|
422
|
+
eprintln(" 先运行 cj-tauri sync(按清单派生 targets/ 骨架)")
|
|
423
|
+
return false
|
|
424
|
+
}
|
|
425
|
+
println("[cj-tauri] cjpm build ... (${baseName(buildDir)})")
|
|
426
|
+
let code = execute(c.cjpm, ["build"], workingDirectory: Path(buildDir))
|
|
413
427
|
if (code != 0) {
|
|
414
428
|
eprintln("[cj-tauri] 构建失败(exit=${code})")
|
|
415
429
|
return false
|
|
416
430
|
}
|
|
417
|
-
if (let Some(bin) <- findAppBinary(c.projectRoot)) {
|
|
431
|
+
if (let Some(bin) <- findAppBinary(c.projectRoot, c.newForm)) {
|
|
418
432
|
println("[cj-tauri] 构建完成: ${bin}")
|
|
419
433
|
} else {
|
|
420
434
|
println("[cj-tauri] 构建完成(未在 target/release/bin 找到可执行产物)")
|
|
@@ -425,7 +439,7 @@ func buildProject(c: AppContext, withUi: Bool): Bool {
|
|
|
425
439
|
/** 运行已构建产物(App 以项目根为工作目录,页面/能力清单按相对路径读取) */
|
|
426
440
|
func runProject(c: AppContext): Int64 {
|
|
427
441
|
var bin = ""
|
|
428
|
-
if (let Some(b) <- findAppBinary(c.projectRoot)) {
|
|
442
|
+
if (let Some(b) <- findAppBinary(c.projectRoot, c.newForm)) {
|
|
429
443
|
bin = b
|
|
430
444
|
} else {
|
|
431
445
|
eprintln("[cj-tauri] 错误: 未找到可执行产物,请先 cj-tauri build")
|
|
@@ -510,9 +524,9 @@ func cmdDev(): Int64 {
|
|
|
510
524
|
return buildOhos(root, false)
|
|
511
525
|
}
|
|
512
526
|
if (let Some(c) <- loadContext()) {
|
|
513
|
-
// 有
|
|
527
|
+
// 有 Vite 前端才走 Node 路径:dev 模式页面来自 dev server,不必先打发布包
|
|
514
528
|
var withUi = true
|
|
515
|
-
if (let Some(ui) <- detectWebUi(c.projectRoot)) {
|
|
529
|
+
if (let Some(ui) <- detectWebUi(c.projectRoot, c.newForm)) {
|
|
516
530
|
if (!ensureUiDeps(ui)) {
|
|
517
531
|
return 1
|
|
518
532
|
}
|
|
@@ -521,7 +535,7 @@ func cmdDev(): Int64 {
|
|
|
521
535
|
if (!buildProject(c, withUi)) {
|
|
522
536
|
return 1
|
|
523
537
|
}
|
|
524
|
-
if (let Some(ui) <- detectWebUi(c.projectRoot)) {
|
|
538
|
+
if (let Some(ui) <- detectWebUi(c.projectRoot, c.newForm)) {
|
|
525
539
|
return runWithDevServer(c, ui)
|
|
526
540
|
}
|
|
527
541
|
return runProject(c)
|
|
@@ -574,11 +588,12 @@ func cmdInfo(asJson: Bool): Int64 {
|
|
|
574
588
|
println(" 框架根目录 : 未找到(请设置 CJ_TAURI_ROOT)")
|
|
575
589
|
}
|
|
576
590
|
if (let Some(proj) <- findProjectRoot()) {
|
|
577
|
-
|
|
578
|
-
if (
|
|
591
|
+
let newForm = exists(joinPath(proj, "cj-tauri.toml"))
|
|
592
|
+
println(" 项目根目录 : ${proj}${if (newForm) { "(新形态:cj-tauri.toml)" } else { "" }}")
|
|
593
|
+
if (let Some(bin) <- findAppBinary(proj, newForm)) {
|
|
579
594
|
println(" 可执行产物 : ${bin}")
|
|
580
595
|
} else {
|
|
581
|
-
println(" 可执行产物 : 未构建(cj-tauri build)")
|
|
596
|
+
println(" 可执行产物 : 未构建(cj-tauri sync + cj-tauri build)")
|
|
582
597
|
}
|
|
583
598
|
} else {
|
|
584
599
|
println(" 项目根目录 : (当前不在 cj-tauri 项目内)")
|
|
@@ -641,8 +656,9 @@ func pluginManifest(mode: String): Option<String> {
|
|
|
641
656
|
eprintln("[cj-tauri] 跳过插件清单: 当前目录不在 cj-tauri 项目内")
|
|
642
657
|
return None
|
|
643
658
|
}
|
|
659
|
+
let newForm = exists(joinPath(proj, "cj-tauri.toml"))
|
|
644
660
|
var bin = ""
|
|
645
|
-
if (let Some(b) <- findAppBinary(proj)) {
|
|
661
|
+
if (let Some(b) <- findAppBinary(proj, newForm)) {
|
|
646
662
|
bin = b
|
|
647
663
|
} else {
|
|
648
664
|
eprintln("[cj-tauri] 跳过插件清单: 未找到可执行产物(先跑 cj-tauri build)")
|