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.
Files changed (101) hide show
  1. package/README.md +64 -18
  2. package/cjpm.toml +52 -52
  3. package/cli/cjpm.toml +10 -1
  4. package/cli/src/doctor.cj +4 -2
  5. package/cli/src/main.cj +11 -3
  6. package/cli/src/manifest.cj +558 -0
  7. package/cli/src/project.cj +38 -22
  8. package/cli/src/scaffold.cj +369 -361
  9. package/cli/src/sync.cj +526 -0
  10. package/cli/src/util.cj +168 -159
  11. package/cli/templates/app/README.md +48 -80
  12. package/cli/templates/app/{capabilities → assets/capabilities}/default.json +7 -7
  13. package/cli/templates/app/{ui → assets/ui}/index.html +118 -118
  14. package/cli/templates/app/cj-tauri.toml +22 -0
  15. package/cli/templates/app/cjpm.toml +34 -17
  16. package/cli/templates/app/src/main.cj +90 -88
  17. package/cli/templates/app-react/README.md +56 -67
  18. package/cli/templates/app-react/{capabilities → assets/capabilities}/default.json +7 -7
  19. package/cli/templates/app-react/{ui → assets/ui}/package.json +19 -19
  20. package/cli/templates/app-react/{ui → assets/ui}/src/main.jsx +6 -6
  21. package/cli/templates/app-react/{ui → assets/ui}/vite.config.js +24 -24
  22. package/cli/templates/app-react/cj-tauri.toml +23 -0
  23. package/cli/templates/app-react/cjpm.toml +34 -17
  24. package/cli/templates/app-react/src/main.cj +91 -102
  25. package/cli/templates/app-vue/README.md +56 -60
  26. package/cli/templates/app-vue/{capabilities → assets/capabilities}/default.json +7 -7
  27. package/cli/templates/app-vue/{ui → assets/ui}/package.json +18 -18
  28. package/cli/templates/app-vue/{ui → assets/ui}/src/main.js +4 -4
  29. package/cli/templates/app-vue/{ui → assets/ui}/vite.config.js +24 -24
  30. package/cli/templates/app-vue/cj-tauri.toml +23 -0
  31. package/cli/templates/app-vue/cjpm.toml +34 -17
  32. package/cli/templates/app-vue/src/main.cj +91 -102
  33. package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/app.json5 +13 -13
  34. package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/element/string.json +8 -8
  35. package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/layered_image.json +6 -6
  36. package/cli/templates/{ohos-pc → ohos-skeleton}/README.md +79 -79
  37. package/cli/templates/{ohos-pc → ohos-skeleton}/build-profile.json5 +46 -46
  38. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/build-profile.json5 +26 -26
  39. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/cjpm.toml +43 -43
  40. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/hvigorfile.ts +6 -6
  41. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/oh-package.json5 +9 -9
  42. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/ability_stage.cj +17 -17
  43. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/app_host.cj +94 -94
  44. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/index.cj +167 -167
  45. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/main_ability.cj +139 -139
  46. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/module.json5 +49 -49
  47. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/element/color.json +8 -8
  48. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/element/string.json +16 -16
  49. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/layered_image.json +6 -6
  50. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/profile/main_pages.json +2 -2
  51. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/rawfile/capabilities.json +6 -6
  52. package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/rawfile/index.html +92 -92
  53. package/cli/templates/{ohos-pc → ohos-skeleton}/hvigor/hvigor-config.json5 +5 -5
  54. package/cli/templates/{ohos-pc → ohos-skeleton}/hvigorfile.ts +6 -6
  55. package/cli/templates/{ohos-pc → ohos-skeleton}/oh-package.json5 +10 -10
  56. package/package.json +4 -2
  57. package/prebuilt/win32-x64/cj-tauri.exe +0 -0
  58. package/src/app.cj +49 -20
  59. package/src/app_spec.cj +76 -0
  60. package/src/arkweb_script.cj +142 -154
  61. package/src/host.cj +20 -17
  62. package/src/host_arkweb.cj +778 -740
  63. package/src/host_webkit.cj +22 -0
  64. package/src/host_webview2.cj +22 -0
  65. package/src/launch.cj +62 -0
  66. package/src/platform/platform_app_context.cj +77 -0
  67. package/src/platform/platform_assets.cj +33 -0
  68. package/src/platform/platform_discover.cj +176 -0
  69. package/src/platform/platform_env.cj +29 -0
  70. package/src/platform/platform_feature.cj +31 -0
  71. package/src/platform/platform_page_source.cj +87 -0
  72. package/src/platform/platform_target_info.cj +32 -0
  73. package/src/platform_host_provider.cj +87 -0
  74. package/src/plugin.cj +36 -2
  75. package/src/plugins/clipboard/plugin_clipboard.cj +8 -0
  76. package/src/plugins/menu/plugin_menu.cj +158 -150
  77. package/src/plugins/notification/plugin_notification.cj +8 -0
  78. package/src/plugins/serial/plugin_serial.cj +454 -442
  79. package/src/plugins/serial/serial_bridge.cj +194 -186
  80. package/src/plugins/serial/serial_ohos_stub.cj +61 -0
  81. package/src/plugins/shell/plugin_shell.cj +258 -230
  82. package/src/plugins/sqlite/plugin_sqlite.cj +710 -697
  83. package/src/plugins/sqlite/sqlite_ffi.cj +211 -206
  84. package/src/plugins/sqlite/sqlite_ohos_stub.cj +91 -0
  85. package/src/tests/app_spec_test.cj +127 -0
  86. package/src/tests/fake_host.cj +23 -8
  87. package/src/tests/platform_contract_test.cj +251 -0
  88. package/src/tests/plugin_test.cj +585 -542
  89. package/src/version.cj +1 -1
  90. package/src/host_factory.cj +0 -48
  91. /package/cli/templates/app-react/{ui → assets/ui}/index.html +0 -0
  92. /package/cli/templates/app-react/{ui → assets/ui}/src/App.css +0 -0
  93. /package/cli/templates/app-react/{ui → assets/ui}/src/App.jsx +0 -0
  94. /package/cli/templates/app-vue/{ui → assets/ui}/index.html +0 -0
  95. /package/cli/templates/app-vue/{ui → assets/ui}/src/App.vue +0 -0
  96. /package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/background.png +0 -0
  97. /package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/foreground.png +0 -0
  98. /package/cli/templates/{ohos-pc → ohos-skeleton}/build-hap.sh +0 -0
  99. /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/background.png +0 -0
  100. /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/foreground.png +0 -0
  101. /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/startIcon.png +0 -0
@@ -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 "1.1.2"
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
- /** 可执行产物:优先 target/release/bin/main[.exe] */
50
- func findAppBinary(projectRoot: String): Option<String> {
51
- let binDir = joinPath(joinPath(joinPath(projectRoot, "target"), "release"), "bin")
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
- return Some(AppContext(proj, fw, stdx, cjpm))
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):项目里有 ui/package.json 才启用;没有就整段跳过,行为与 0.3.x 一致 */
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 dir = joinPath(projectRoot, "ui")
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 时先打前端发布包(有 ui/package.json 才会触发) */
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
- println("[cj-tauri] cjpm build ...")
412
- let code = execute(c.cjpm, ["build"], workingDirectory: Path(c.projectRoot))
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
- // 有 ui/package.json 才走 Node 路径:dev 模式页面来自 dev server,不必先打发布包
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
- println(" 项目根目录 : ${proj}")
578
- if (let Some(bin) <- findAppBinary(proj)) {
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)")