cj-tauri 2.3.2 → 2.3.6
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/cjpm.toml +1 -1
- package/cli/cjpm.toml +12 -1
- package/cli/src/main.cj +8 -0
- package/cli/src/project.cj +15 -16
- package/cli/src/scaffold.cj +1 -1
- package/cli/src/sign_agc.cj +386 -0
- package/cli/src/sign_auto.cj +592 -0
- package/cli/src/sign_cloud.cj +724 -0
- package/cli/src/sign_cmd.cj +444 -0
- package/cli/src/sign_gcm.cj +703 -0
- package/cli/src/sign_login.cj +602 -0
- package/cli/src/sign_offline.cj +1183 -0
- package/cli/src/sign_test.cj +298 -0
- package/cli/src/sign_tool.cj +235 -0
- package/cli/src/sync.cj +90 -25
- package/cli/src/util.cj +26 -1
- package/cli/src/util_path_test.cj +72 -0
- package/cli/templates/app/README.md +1 -0
- package/cli/templates/app-react/README.md +1 -0
- package/cli/templates/app-vue/README.md +1 -0
- package/cli/templates/ohos-skeleton/README.md +19 -1
- package/cli/templates/ohos-skeleton/build-hap.bat +219 -0
- package/package.json +1 -1
- package/src/host_arkweb.cj +10 -0
- package/src/version.cj +1 -1
- package/cli/templates/ohos-skeleton/build-hap.ps1 +0 -205
package/cli/src/sync.cj
CHANGED
|
@@ -74,8 +74,7 @@ func checkDesktopDrift(m: Manifest, fwRoot: String): Bool {
|
|
|
74
74
|
var failed = false
|
|
75
75
|
if (!exists(tomlPath)) {
|
|
76
76
|
eprintln("[cj-tauri] 提示:骨架尚未生成(${tomlPath})——运行 cj-tauri sync desktop")
|
|
77
|
-
} else if (
|
|
78
|
-
eprintln("[cj-tauri] 骨架漂移:${tomlPath} 与生成器输出不一致(运行 cj-tauri sync desktop 重新生成)")
|
|
77
|
+
} else if (sameGeneratedToml(tomlPath, expectToml, "运行 cj-tauri sync desktop 重新生成")) {
|
|
79
78
|
failed = true
|
|
80
79
|
}
|
|
81
80
|
if (exists(mainPath) && readText(mainPath) != expectMain) {
|
|
@@ -85,6 +84,27 @@ func checkDesktopDrift(m: Manifest, fwRoot: String): Bool {
|
|
|
85
84
|
return failed
|
|
86
85
|
}
|
|
87
86
|
|
|
87
|
+
/**
|
|
88
|
+
* 取框架根的**唯一入口**(issue #10):业务包声明优先,取不到再自动定位。
|
|
89
|
+
*
|
|
90
|
+
* 为什么必须只有一个入口:`sync` 用业务包 `cjpm.toml` 里的 cjTauri 声明渲染骨架,
|
|
91
|
+
* 而 `check` 早先自己调 `resolveFrameworkRoot()` 重新渲染再比字符串——两条来源给出的
|
|
92
|
+
* 字符串形式不同(例如一个是 `E:/a`、另一个是 `/e/a`),于是**「刚 sync 完就报骨架漂移」**
|
|
93
|
+
* 稳定复现,用户按提示重跑 sync 也治不好。渲染/比对骨架的地方一律走这里。
|
|
94
|
+
*
|
|
95
|
+
* verbose:sync 打「框架路径取自业务包声明」这一行(用户要知道用的是哪份),check 不必。
|
|
96
|
+
*/
|
|
97
|
+
func resolveSkeletonFrameworkRoot(verbose: Bool): Option<String> {
|
|
98
|
+
match (readBizFrameworkPath()) {
|
|
99
|
+
case Some(p) =>
|
|
100
|
+
if (verbose) {
|
|
101
|
+
eprintln("[cj-tauri] 框架路径取自业务包声明:${p}")
|
|
102
|
+
}
|
|
103
|
+
return Some(p)
|
|
104
|
+
case None => return resolveFrameworkRoot()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
88
108
|
func cmdCheck(): Int64 {
|
|
89
109
|
let mOpt = loadValidatedManifest()
|
|
90
110
|
if (let None <- mOpt) {
|
|
@@ -92,7 +112,8 @@ func cmdCheck(): Int64 {
|
|
|
92
112
|
}
|
|
93
113
|
let m = mOpt.getOrThrow()
|
|
94
114
|
var failed = checkManifestOnDisk(m)
|
|
95
|
-
|
|
115
|
+
// 与 sync 同一个取根入口:否则「刚 sync 完」也会判漂移(issue #10)
|
|
116
|
+
match (resolveSkeletonFrameworkRoot(false)) {
|
|
96
117
|
case Some(fw) =>
|
|
97
118
|
let drift = checkDesktopDrift(m, fw)
|
|
98
119
|
failed = drift || failed
|
|
@@ -185,10 +206,18 @@ func checkThreeWay(m: Manifest): Bool {
|
|
|
185
206
|
setVariable("CJ_TAURI_MANIFEST", "json")
|
|
186
207
|
var outText = ""
|
|
187
208
|
try {
|
|
188
|
-
let (code, raw,
|
|
209
|
+
let (code, raw, errRaw) = executeWithOutput(binPath, [])
|
|
189
210
|
outText = String.fromUtf8(raw)
|
|
190
211
|
if (code != 0) {
|
|
191
|
-
|
|
212
|
+
// 子进程的 stderr 以前被丢掉了:缺 libcjtbridge.dll / stdx 动态库时退出码是
|
|
213
|
+
// 0xC0000135(十进制 3221225781),而真正的「缺哪个库」只写在 stderr 里。
|
|
214
|
+
// 接住它拼进诊断——否则这条错误看起来就像骨架漂移。
|
|
215
|
+
let errText = String.fromUtf8(errRaw).trimAscii()
|
|
216
|
+
var detail = errText
|
|
217
|
+
if (detail == "") {
|
|
218
|
+
detail = "(子进程没有 stderr 输出;先查 libcjtbridge.dll 与 stdx 的 dynamic/stdx 是否在 PATH / LD_LIBRARY_PATH)"
|
|
219
|
+
}
|
|
220
|
+
eprintln("[cj-tauri] 三方比对:无头导出退出异常(code=${code}):${detail}")
|
|
192
221
|
return true
|
|
193
222
|
}
|
|
194
223
|
} catch (e: Exception) {
|
|
@@ -347,23 +376,18 @@ func cmdSync(args: Array<String>): Int64 {
|
|
|
347
376
|
case Some(f) => fwRoot = f
|
|
348
377
|
case None =>
|
|
349
378
|
// 业务包 cjpm.toml 里若已声明 cjTauri 路径(create 写入、用户可能手改),launcher
|
|
350
|
-
// 必须用**同一份**——否则两个依赖指向两个框架副本,cjpm 报模块冲突(issue #6
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
eprintln("[cj-tauri] 框架路径取自业务包声明:${p}")
|
|
379
|
+
// 必须用**同一份**——否则两个依赖指向两个框架副本,cjpm 报模块冲突(issue #6-①)。
|
|
380
|
+
// 入口与 check 共用(issue #10):两处各写一套时,渲染出的字符串形式不同就永远判漂移。
|
|
381
|
+
match (resolveSkeletonFrameworkRoot(true)) {
|
|
382
|
+
case Some(f) => fwRoot = f
|
|
355
383
|
case None =>
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
eprintln("[cj-tauri] 未定位到框架根:请 `$env:CJ_TAURI_ROOT = \"<框架仓库根>\"`(或 setx 持久化),或 --framework <路径>")
|
|
362
|
-
} else {
|
|
363
|
-
eprintln("[cj-tauri] 未定位到框架根:请 export CJ_TAURI_ROOT=<框架仓库根>,或 --framework <路径>")
|
|
364
|
-
}
|
|
365
|
-
return 1
|
|
384
|
+
// 提示跟着宿主 shell 走:PowerShell 里给 export 命令是误导(报「无法将 export 项识别为 cmdlet」)
|
|
385
|
+
if (hostIsWindows()) {
|
|
386
|
+
eprintln("[cj-tauri] 未定位到框架根:请 `$env:CJ_TAURI_ROOT = \"<框架仓库根>\"`(或 setx 持久化),或 --framework <路径>")
|
|
387
|
+
} else {
|
|
388
|
+
eprintln("[cj-tauri] 未定位到框架根:请 export CJ_TAURI_ROOT=<框架仓库根>,或 --framework <路径>")
|
|
366
389
|
}
|
|
390
|
+
return 1
|
|
367
391
|
}
|
|
368
392
|
}
|
|
369
393
|
var code = 0
|
|
@@ -510,8 +534,22 @@ func pathFromCjTauriLine(line: ArrayList<Byte>): Option<String> {
|
|
|
510
534
|
return None // 空引号对:当没解析到
|
|
511
535
|
}
|
|
512
536
|
var out = ArrayList<Byte>()
|
|
513
|
-
|
|
514
|
-
|
|
537
|
+
var k = first + 1
|
|
538
|
+
while (k < i) {
|
|
539
|
+
let c = line.get(k).getOrThrow()
|
|
540
|
+
// TOML 基本串的转义要还原:`E:\\test\\a` 必须读成 `E:\test\a`。
|
|
541
|
+
// 不还原时 `toTomlPath` 只会把 `\` 换成 `/`,于是渲染出 `E://test//a`
|
|
542
|
+
// ——骨架里出现重复分隔符,check 重算时必然判漂移(issue #10)。
|
|
543
|
+
if (c == 92 && k + 1 < i) {
|
|
544
|
+
let nx = line.get(k + 1).getOrThrow()
|
|
545
|
+
if (nx == 92 || nx == 34) { // 只认 `\\` 与 `\"`,其余 `\x` 原样留着
|
|
546
|
+
out.add(nx)
|
|
547
|
+
k += 2
|
|
548
|
+
continue
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
out.add(c)
|
|
552
|
+
k += 1
|
|
515
553
|
}
|
|
516
554
|
let s = String.fromUtf8(out.toArray())
|
|
517
555
|
if (s.size > 0) {
|
|
@@ -612,7 +650,11 @@ func listCapsFiles(dir: String): ArrayList<String> {
|
|
|
612
650
|
return out
|
|
613
651
|
}
|
|
614
652
|
|
|
615
|
-
/** 资产递归拷贝:资产根目录整体拷入 rawfile 目录(字节级、二进制安全——RFC §7.3 的 rawfile 资产注入口)
|
|
653
|
+
/** 资产递归拷贝:资产根目录整体拷入 rawfile 目录(字节级、二进制安全——RFC §7.3 的 rawfile 资产注入口)
|
|
654
|
+
*
|
|
655
|
+
* **node_modules 必须跳过**:Vite 工程的依赖树上万文件,拷进 hap 是无意义的体积(实测
|
|
656
|
+
* 一万多文件),而且 `cj-tauri build` 桌面链路读的是 `assets/ui/dist`,依赖目录没有任何消费方。
|
|
657
|
+
*/
|
|
616
658
|
func copyAssetsToRawfile(srcRoot: String, dstRoot: String): Int64 {
|
|
617
659
|
if (!exists(srcRoot)) {
|
|
618
660
|
eprintln("[cj-tauri] 错误:资产根不存在:${srcRoot}")
|
|
@@ -625,6 +667,9 @@ func copyAssetsToRawfile(srcRoot: String, dstRoot: String): Int64 {
|
|
|
625
667
|
if (nm.size == 0) {
|
|
626
668
|
continue
|
|
627
669
|
}
|
|
670
|
+
if (info.isDirectory() && nm == "node_modules") {
|
|
671
|
+
continue
|
|
672
|
+
}
|
|
628
673
|
let s = joinPath(srcRoot, nm)
|
|
629
674
|
let d = joinPath(dstRoot, nm)
|
|
630
675
|
if (info.isDirectory()) {
|
|
@@ -670,7 +715,7 @@ func syncOhos(m: Manifest, fwRoot: String): Int64 {
|
|
|
670
715
|
println("[cj-tauri] 已生成 targets/ohos:模板 ${count} 文件 + 清单派生 4 文件 + rawfile ${copied} 资产")
|
|
671
716
|
if (hostIsWindows()) {
|
|
672
717
|
println("[cj-tauri] 下一步:`$env:CANGJIE_STDX_OHOS = \"<鸿蒙版 stdx>\\linux_ohos_aarch64_cjnative\\dynamic\\stdx\"`(PowerShell)")
|
|
673
|
-
println(" cd targets\\ohos && npx cj-tauri build(走 build-hap.
|
|
718
|
+
println(" cd targets\\ohos && npx cj-tauri build(走 build-hap.bat;装设备加 --install 走 run)")
|
|
674
719
|
} else {
|
|
675
720
|
println("[cj-tauri] 下一步:export CANGJIE_STDX_OHOS=<鸿蒙版 stdx>/linux_ohos_aarch64_cjnative/dynamic/stdx")
|
|
676
721
|
println(" cd targets/ohos && bash build-hap.sh")
|
|
@@ -689,7 +734,7 @@ func checkOhosDrift(m: Manifest, fwRoot: String): Bool {
|
|
|
689
734
|
let capsFiles = listCapsFiles(m.capabilitiesDir)
|
|
690
735
|
var failed = false
|
|
691
736
|
failed = sameGeneratedFile("targets/ohos/AppScope/app.json5", m.renderOhosAppJson(ver), failed)
|
|
692
|
-
failed =
|
|
737
|
+
failed = sameGeneratedToml("targets/ohos/entry/cjpm.toml", m.renderOhosEntryToml(fwRoot, ver), "重跑 cj-tauri sync ohos") || failed
|
|
693
738
|
failed = sameGeneratedFile("targets/ohos/entry/src/main/cangjie/app_host.cj", m.renderOhosAppHost(ver, capsFiles), failed)
|
|
694
739
|
failed = sameGeneratedFile("targets/ohos/entry/src/main/cangjie/main_ability.cj", m.renderOhosMainAbility(ver), failed)
|
|
695
740
|
// rawfile 资产:page 必须与资产根字节一致;能力文件名单必须与清单目录一致
|
|
@@ -725,6 +770,26 @@ func checkOhosDrift(m: Manifest, fwRoot: String): Bool {
|
|
|
725
770
|
}
|
|
726
771
|
|
|
727
772
|
/** 生成物比对:缺失 = 漂移,内容不一致 = 漂移 */
|
|
773
|
+
/**
|
|
774
|
+
* 生成物比对(**TOML 专用**):两侧都过一遍 `toTomlPath` 再比。
|
|
775
|
+
*
|
|
776
|
+
* 只归一化路径分隔符,不放宽内容比对。为什么两侧都要过:旧版 `sync` 会把业务包里的
|
|
777
|
+
* `E:\\test\\…` 原样渲染成 `E://test//…` 写进用户的 targets/(issue #10);只归一化期望值
|
|
778
|
+
* 的话,这些老工程仍被判漂移,用户按提示重跑 sync 也会觉得「明明照做了还是红的」。
|
|
779
|
+
* `.cj` 生成物不走这个函数——它们的注释里有 `//`,不该参与路径归一化。
|
|
780
|
+
*/
|
|
781
|
+
func sameGeneratedToml(path: String, expect: String, hint: String): Bool {
|
|
782
|
+
if (!exists(path)) {
|
|
783
|
+
eprintln("[cj-tauri] 骨架漂移:缺生成文件 ${path}(${hint})")
|
|
784
|
+
return true
|
|
785
|
+
}
|
|
786
|
+
if (toTomlPath(readText(path)) != toTomlPath(expect)) {
|
|
787
|
+
eprintln("[cj-tauri] 骨架漂移:${path} 与生成器输出不一致(${hint})")
|
|
788
|
+
return true
|
|
789
|
+
}
|
|
790
|
+
return false
|
|
791
|
+
}
|
|
792
|
+
|
|
728
793
|
func sameGeneratedFile(path: String, expect: String, failed: Bool): Bool {
|
|
729
794
|
if (!exists(path)) {
|
|
730
795
|
eprintln("[cj-tauri] 骨架漂移:缺生成文件 ${path}(重跑 cj-tauri sync ohos)")
|
package/cli/src/util.cj
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
package cli
|
|
8
8
|
|
|
9
|
+
import std.collection.*
|
|
9
10
|
import std.fs.*
|
|
10
11
|
|
|
11
12
|
// ===== 字节级字符判定 =====
|
|
@@ -163,6 +164,30 @@ func escapeTomlString(p: String): String {
|
|
|
163
164
|
* 为什么:Windows 的 `E:\a\b` 在 TOML 基本字符串里是转义序列,`\a` / `\t` 会让 cjpm 解析期直接
|
|
164
165
|
* `errLexEscape` 失败(AGENTS §4「生成 toml 的脚本用正斜杠」);正斜杠 cjpm 与 gcc/ld 都认。
|
|
165
166
|
*/
|
|
167
|
+
/**
|
|
168
|
+
* 路径 → TOML 里的写法:反斜杠转正斜杠,并**合并重复分隔符**。
|
|
169
|
+
*
|
|
170
|
+
* 合并是为了兼容旧骨架:`readBizFrameworkPath` 曾把 TOML 里的 `\\` 原样带下去,
|
|
171
|
+
* 渲染成 `E://test//a` 并写进了用户的 targets/(issue #10)。现在两侧都过这个函数,
|
|
172
|
+
* 老骨架不会因为「多一个斜杠」被判漂移;开头的 `//` 是 UNC,必须保留。
|
|
173
|
+
*/
|
|
166
174
|
func toTomlPath(p: String): String {
|
|
167
|
-
|
|
175
|
+
let s = p.replace("\\", "/")
|
|
176
|
+
let b = s.toArray()
|
|
177
|
+
let out = ArrayList<Byte>()
|
|
178
|
+
var i = 0
|
|
179
|
+
while (i < b.size && b[i] == 47 && i < 2) { // 保留开头最多两个分隔符(UNC)
|
|
180
|
+
out.add(b[i])
|
|
181
|
+
i += 1
|
|
182
|
+
}
|
|
183
|
+
while (i < b.size) {
|
|
184
|
+
out.add(b[i])
|
|
185
|
+
if (b[i] == 47) {
|
|
186
|
+
while (i + 1 < b.size && b[i + 1] == 47) {
|
|
187
|
+
i += 1
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
i += 1
|
|
191
|
+
}
|
|
192
|
+
return String.fromUtf8(out.toArray())
|
|
168
193
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
package cli
|
|
2
|
+
|
|
3
|
+
import std.collection.*
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 框架路径的「取出来 → 写进骨架」这条链路的用例(issue #10)
|
|
7
|
+
*
|
|
8
|
+
* 守两条不变量:
|
|
9
|
+
* ① **业务包里的 TOML 转义要还原**——`cjpm.toml` 写的是 `path = "E:\\test\\a"`,
|
|
10
|
+
* 读出来必须是 `E:\test\a`;不还原就会一路变成 `E://test//a` 写进 targets/;
|
|
11
|
+
* ② **渲染/toTomlPath 要把重复分隔符合并**——老骨架里已经躺着 `E://test//a`,
|
|
12
|
+
* 只归一化期望值的话,这些工程会被永久判漂移、且重跑 sync 也「看着没修好」。
|
|
13
|
+
*
|
|
14
|
+
* 放在根包内(同 `manifest_test.cj`):CLI 是 executable 工程,子包 import 根包会被 cjpm 拒绝。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** 按字节把字符串塞进 ArrayList(`pathFromCjTauriLine` 收的就是这种行缓冲) */
|
|
18
|
+
private func lineBytes(s: String): ArrayList<Byte> {
|
|
19
|
+
let out = ArrayList<Byte>()
|
|
20
|
+
for (b in s) {
|
|
21
|
+
out.add(b)
|
|
22
|
+
}
|
|
23
|
+
return out
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test
|
|
27
|
+
func toTomlPathCollapsesRepeatedSeparators(): Unit {
|
|
28
|
+
// 老骨架写出来的形状:每个分隔符都翻了倍
|
|
29
|
+
@Expect(toTomlPath("E://test//harmonyos//test//cj-tauri") == "E:/test/harmonyos/test/cj-tauri")
|
|
30
|
+
@Expect(toTomlPath("/a///b////c") == "/a/b/c")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test
|
|
34
|
+
func toTomlPathConvertsBackslashAndIsIdempotent(): Unit {
|
|
35
|
+
@Expect(toTomlPath("E:\\test\\a") == "E:/test/a")
|
|
36
|
+
let once = toTomlPath("E://test//a")
|
|
37
|
+
@Expect(toTomlPath(once) == once) // 幂等:再跑一遍不会再变
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test
|
|
41
|
+
func toTomlPathKeepsUncPrefix(): Unit {
|
|
42
|
+
// 开头两个分隔符是 UNC(Windows 共享路径;Linux 上 `//x` 也是绝对路径),不能合并掉
|
|
43
|
+
@Expect(toTomlPath("//server/share//a") == "//server/share/a")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test
|
|
47
|
+
func bizDeclarationUnescapesTomlBackslashes(): Unit {
|
|
48
|
+
// 业务包 cjpm.toml 的原文(TOML 基本串里 `\` 必须转义)
|
|
49
|
+
match (pathFromCjTauriLine(lineBytes(" cjTauri = { path = \"E:\\\\test\\\\a\" }"))) {
|
|
50
|
+
case Some(p) => @Expect(p == "E:\\test\\a")
|
|
51
|
+
case None => @Expect(false)
|
|
52
|
+
}
|
|
53
|
+
// 正斜杠写法原样返回(不必动)
|
|
54
|
+
match (pathFromCjTauriLine(lineBytes(" cjTauri = { path = \"E:/test/a\" }"))) {
|
|
55
|
+
case Some(p) => @Expect(p == "E:/test/a")
|
|
56
|
+
case None => @Expect(false)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Test
|
|
61
|
+
func bizDeclarationKeepsUnknownEscapes(): Unit {
|
|
62
|
+
// 只认 `\\` 与 `\"`:其它 `\x` 原样留着,别把用户路径里的字符吃掉
|
|
63
|
+
match (pathFromCjTauriLine(lineBytes(" cjTauri = { path = \"a\\nb\" }"))) {
|
|
64
|
+
case Some(p) => @Expect(p == "a\\nb")
|
|
65
|
+
case None => @Expect(false)
|
|
66
|
+
}
|
|
67
|
+
// 没有 cjTauri 这一行 → None(交给 resolveFrameworkRoot 兜底)
|
|
68
|
+
match (pathFromCjTauriLine(lineBytes(" other = \"x\""))) {
|
|
69
|
+
case Some(_) => @Expect(false)
|
|
70
|
+
case None => @Expect(true)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -34,6 +34,7 @@ cj-tauri check # 清单校验 + 骨架漂移 + 插件三方比对
|
|
|
34
34
|
export CANGJIE_STDX_OHOS=<鸿蒙版 stdx>/linux_ohos_aarch64_cjnative/dynamic/stdx
|
|
35
35
|
cd targets/ohos && bash build-hap.sh # 编 hap
|
|
36
36
|
cd targets/ohos && bash build-hap.sh --install # 编完装到设备并拉起
|
|
37
|
+
# Windows:cd targets\ohos && build-hap.bat --install(cmd / PowerShell 窗口都能跑,无需 Git Bash)
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
提示:模板不带签名证书——首次在 DevEco 里 File → Project Structure → Signing Configs
|
|
@@ -42,6 +42,7 @@ cj-tauri run
|
|
|
42
42
|
export CANGJIE_STDX_OHOS=<鸿蒙版 stdx>/linux_ohos_aarch64_cjnative/dynamic/stdx
|
|
43
43
|
cd targets/ohos && bash build-hap.sh # 编 hap
|
|
44
44
|
cd targets/ohos && bash build-hap.sh --install # 编完装到设备并拉起
|
|
45
|
+
# Windows:cd targets\ohos && build-hap.bat --install(cmd / PowerShell 窗口都能跑,无需 Git Bash)
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
提示:模板不带签名证书——首次在 DevEco 里 File → Project Structure → Signing Configs
|
|
@@ -42,6 +42,7 @@ cj-tauri run
|
|
|
42
42
|
export CANGJIE_STDX_OHOS=<鸿蒙版 stdx>/linux_ohos_aarch64_cjnative/dynamic/stdx
|
|
43
43
|
cd targets/ohos && bash build-hap.sh # 编 hap
|
|
44
44
|
cd targets/ohos && bash build-hap.sh --install # 编完装到设备并拉起
|
|
45
|
+
# Windows:cd targets\ohos && build-hap.bat --install(cmd / PowerShell 窗口都能跑,无需 Git Bash)
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
提示:模板不带签名证书——首次在 DevEco 里 File → Project Structure → Signing Configs
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
├─ AppScope/app.json5 应用级配置(bundleName = {{BUNDLE_NAME}})
|
|
11
11
|
├─ build-profile.json5 工程级构建配置(签名留空,见下)
|
|
12
12
|
├─ build-hap.sh 构建入口(编 hap / 装到设备)
|
|
13
|
+
├─ build-hap.bat 同上,Windows 入口(cmd / PowerShell 窗口都能跑)
|
|
13
14
|
├─ entry/
|
|
14
15
|
│ ├─ cjpm.toml cjTauri 依赖 + aarch64-linux-ohos 目标段
|
|
15
16
|
│ ├─ build-profile.json5 cangjieOptions.checkDeviceTypes=false(放行 2in1)
|
|
@@ -44,7 +45,24 @@ bash build-hap.sh
|
|
|
44
45
|
bash build-hap.sh --install
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
Windows(cmd 或 PowerShell 窗口都能跑 `build-hap.bat`,无需 Git Bash):
|
|
49
|
+
|
|
50
|
+
```bat
|
|
51
|
+
:: 1) 鸿蒙版 stdx
|
|
52
|
+
set CANGJIE_STDX_OHOS=<stdx>\linux_ohos_aarch64_cjnative\dynamic\stdx
|
|
53
|
+
|
|
54
|
+
:: 2) DevEco 安装根(脚本会自动探测,探测不到就自己给)
|
|
55
|
+
set "DEVECO_WIN=D:\Program Files\Huawei\DevEco Studio"
|
|
56
|
+
|
|
57
|
+
:: 3) 编 hap
|
|
58
|
+
build-hap.bat
|
|
59
|
+
|
|
60
|
+
:: 4) 编完装到设备并拉起(需要设备已连上、应用已签名)
|
|
61
|
+
build-hap.bat --install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
改了鸿蒙侧仓颉代码却没生效时:`bash build-hap.sh --clean` / `build-hap.bat --clean`
|
|
65
|
+
(hvigor 与框架 cjpm 各有一份增量缓存)。
|
|
48
66
|
|
|
49
67
|
**DevEco IDE 内点 Build 不经过 build-hap.sh**:assets 自动同步段(工程根 assets/ → rawfile)在
|
|
50
68
|
命令行入口里,IDE 构建不会执行——在 IDE 里改了 `assets/ui` 或 `assets/capabilities` 后,
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal EnableExtensions
|
|
3
|
+
rem ============================================================
|
|
4
|
+
rem {{PROJECT_NAME}} - HarmonyOS PC (2in1) HAP build entry for Windows.
|
|
5
|
+
rem
|
|
6
|
+
rem Bat twin of build-hap.sh (same steps, native Windows paths; no Git Bash
|
|
7
|
+
rem needed). Runs from a cmd prompt or a PowerShell window alike.
|
|
8
|
+
rem Usage:
|
|
9
|
+
rem build-hap.bat build the hap
|
|
10
|
+
rem build-hap.bat --install build + hdc install + aa start
|
|
11
|
+
rem build-hap.bat --clean remove entry/build first (stale .so/.hap)
|
|
12
|
+
rem build-hap.bat -h show this help
|
|
13
|
+
rem
|
|
14
|
+
rem Prerequisites (each checked below with an actionable message):
|
|
15
|
+
rem 1. DevEco Studio 6.1+ (ships hvigor + node). Probed at common locations;
|
|
16
|
+
rem set DEVECO_WIN=<install root, Windows form> to override.
|
|
17
|
+
rem 2. Ohos stdx: set CANGJIE_STDX_OHOS=<stdx>\linux_ohos_aarch64_cjnative\dynamic\stdx
|
|
18
|
+
rem - without it cjpm reports a misleading "missing dependency" error.
|
|
19
|
+
rem 3. Signing: the template ships no certificate. In DevEco: File - Project
|
|
20
|
+
rem Structure - Signing Configs - "Automatically generate signature"
|
|
21
|
+
rem (needs a Huawei account). Unsigned builds yield *-unsigned.hap and
|
|
22
|
+
rem cannot be installed (hdc install reports 9568289 etc.).
|
|
23
|
+
rem
|
|
24
|
+
rem To capture the full hvigor output to a file: build-hap.bat > build.log 2>&1
|
|
25
|
+
rem
|
|
26
|
+
rem Comments are ASCII on purpose: Chinese text in a .bat file breaks parsing
|
|
27
|
+
rem under the default OEM code page.
|
|
28
|
+
rem ============================================================
|
|
29
|
+
|
|
30
|
+
cd /d "%~dp0"
|
|
31
|
+
|
|
32
|
+
rem ---------------- arguments ----------------
|
|
33
|
+
set "DO_INSTALL=0"
|
|
34
|
+
set "DO_CLEAN=0"
|
|
35
|
+
:arg_parse
|
|
36
|
+
if "%~1"=="" goto args_done
|
|
37
|
+
if /i "%~1"=="--install" (set "DO_INSTALL=1" & shift & goto arg_parse)
|
|
38
|
+
if /i "%~1"=="-install" (set "DO_INSTALL=1" & shift & goto arg_parse)
|
|
39
|
+
if /i "%~1"=="--clean" (set "DO_CLEAN=1" & shift & goto arg_parse)
|
|
40
|
+
if /i "%~1"=="-clean" (set "DO_CLEAN=1" & shift & goto arg_parse)
|
|
41
|
+
if /i "%~1"=="-h" goto help
|
|
42
|
+
if /i "%~1"=="--help" goto help
|
|
43
|
+
echo [ohos] unknown arg: %~1 (supported: --install / --clean / -h) 1>&2
|
|
44
|
+
exit /b 2
|
|
45
|
+
:args_done
|
|
46
|
+
goto :main
|
|
47
|
+
:help
|
|
48
|
+
echo Usage:
|
|
49
|
+
echo build-hap.bat build the hap
|
|
50
|
+
echo build-hap.bat --install build + hdc install + aa start
|
|
51
|
+
echo build-hap.bat --clean remove entry/build first
|
|
52
|
+
exit /b 0
|
|
53
|
+
|
|
54
|
+
:main
|
|
55
|
+
rem ---------------- DevEco install root ----------------
|
|
56
|
+
rem DEVECO_WIN first, then a few common locations.
|
|
57
|
+
if not defined DEVECO_WIN if exist "D:\oh\DevEcoStudio\tools\hvigor" set "DEVECO_WIN=D:\oh\DevEcoStudio"
|
|
58
|
+
if not defined DEVECO_WIN if exist "C:\Program Files\Huawei\DevEco Studio\tools\hvigor" set "DEVECO_WIN=C:\Program Files\Huawei\DevEco Studio"
|
|
59
|
+
if not defined DEVECO_WIN if exist "D:\Program Files\Huawei\DevEco Studio\tools\hvigor" set "DEVECO_WIN=D:\Program Files\Huawei\DevEco Studio"
|
|
60
|
+
if not defined DEVECO_WIN if exist "C:\Program Files (x86)\Huawei\DevEco Studio\tools\hvigor" set "DEVECO_WIN=C:\Program Files (x86)\Huawei\DevEco Studio"
|
|
61
|
+
if not defined DEVECO_WIN (
|
|
62
|
+
echo [ohos] DevEco Studio not found. Set DEVECO_WIN=^<install root, Windows form^> 1>&2
|
|
63
|
+
echo e.g. set "DEVECO_WIN=C:\Program Files\Huawei\DevEco Studio" 1>&2
|
|
64
|
+
exit /b 1
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
rem An invalid preset value makes hvigor fail with "Invalid value of ...":
|
|
68
|
+
rem fall back to the path under DEVECO_WIN and say what was ignored.
|
|
69
|
+
if not defined DEVECO_SDK_HOME set "DEVECO_SDK_HOME=%DEVECO_WIN%\sdk"
|
|
70
|
+
if defined DEVECO_SDK_HOME if not exist "%DEVECO_SDK_HOME%" (
|
|
71
|
+
echo [ohos] ignoring invalid DEVECO_SDK_HOME: %DEVECO_SDK_HOME^> 1>&2
|
|
72
|
+
set "DEVECO_SDK_HOME=%DEVECO_WIN%\sdk"
|
|
73
|
+
)
|
|
74
|
+
if not defined NODE_HOME set "NODE_HOME=%DEVECO_WIN%\tools\node"
|
|
75
|
+
if defined NODE_HOME if not exist "%NODE_HOME%" (
|
|
76
|
+
echo [ohos] ignoring invalid NODE_HOME: %NODE_HOME^> 1>&2
|
|
77
|
+
set "NODE_HOME=%DEVECO_WIN%\tools\node"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if not defined CANGJIE_STDX_OHOS (
|
|
81
|
+
echo [ohos] set CANGJIE_STDX_OHOS=^<ohos stdx^\>linux_ohos_aarch64_cjnative\dynamic\stdx first 1>&2
|
|
82
|
+
exit /b 1
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
set "NODE_EXE=%DEVECO_WIN%\tools\node\node.exe"
|
|
86
|
+
set "HVIGOR_JS=%DEVECO_WIN%\tools\hvigor\bin\hvigorw.js"
|
|
87
|
+
if not exist "%HVIGOR_JS%" (
|
|
88
|
+
echo [ohos] %HVIGOR_JS% not found - is DEVECO_WIN correct? 1>&2
|
|
89
|
+
exit /b 1
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
rem hvigorw locates the Cangjie build plugin itself and creates the node_modules
|
|
93
|
+
rem junctions; a headless run must hand it the path, or the failure surfaces as
|
|
94
|
+
rem "property name must be valid: cangjieOptions" (looks like a project config
|
|
95
|
+
rem error, actually the plugin was not loaded).
|
|
96
|
+
if not defined DEVECO_HVIGOR_CANGJIE_PLUGIN (
|
|
97
|
+
if not defined APPDATA set "APPDATA=%USERPROFILE%\AppData\Roaming"
|
|
98
|
+
for /d %%D in ("%APPDATA%\Huawei\DevEcoStudio*") do (
|
|
99
|
+
for /d %%P in ("%%~D\plugins\devecostudio-cangjie-plugin-*") do (
|
|
100
|
+
if exist "%%~P\lib\hvigor\cangjie-build-support" (
|
|
101
|
+
if not defined DEVECO_HVIGOR_CANGJIE_PLUGIN set "DEVECO_HVIGOR_CANGJIE_PLUGIN=%%~P\lib\hvigor\cangjie-build-support"
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
if not defined DEVECO_HVIGOR_CANGJIE_PLUGIN (
|
|
107
|
+
echo [ohos] Cangjie build plugin not found under %APPDATA%\Huawei\DevEcoStudio*\plugins\devecostudio-cangjie-plugin-*\lib\hvigor\cangjie-build-support 1>&2
|
|
108
|
+
echo set DEVECO_HVIGOR_CANGJIE_PLUGIN=^<that dir^> 1>&2
|
|
109
|
+
exit /b 1
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
rem The plugin being loadable is not the same as being enabled: when disabled it
|
|
113
|
+
rem deletes the cangjie schema silently (terminal only shows 00303038). Set both.
|
|
114
|
+
set "DEVECO_CANGJIE_PLUGIN_ENABLED=true"
|
|
115
|
+
set "NODE_PATH=%CD%\node_modules"
|
|
116
|
+
|
|
117
|
+
rem The SDK's cjpm.exe hard-depends on libcangjie-runtime.dll (under runtime/lib):
|
|
118
|
+
rem without it hvigor exits 0xC0000139 within milliseconds. First match wins; with
|
|
119
|
+
rem several SDK versions set CANGJIE_SDK explicitly.
|
|
120
|
+
if not defined CANGJIE_SDK (
|
|
121
|
+
for /d %%D in ("%USERPROFILE%\.cangjie-sdk\*\cangjie") do (
|
|
122
|
+
if not defined CANGJIE_SDK set "CANGJIE_SDK=%%~D"
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
if defined CANGJIE_SDK (
|
|
126
|
+
set "CJS_RT=%CANGJIE_SDK%\build-tools\runtime\lib\windows_x86_64_cjnative"
|
|
127
|
+
set "CJS_BIN=%CANGJIE_SDK%\build-tools\bin"
|
|
128
|
+
set "CJS_TOOLS=%CANGJIE_SDK%\build-tools\tools\bin"
|
|
129
|
+
if exist "%CJS_RT%" (
|
|
130
|
+
set "PATH=%CJS_RT%;%PATH%"
|
|
131
|
+
) else (
|
|
132
|
+
echo [ohos] Cangjie runtime dir not found: %CJS_RT% - cjpm will exit 0xC0000139 1>&2
|
|
133
|
+
echo set CANGJIE_SDK=^<.cangjie-sdk\<version>\cangjie^> 1>&2
|
|
134
|
+
)
|
|
135
|
+
if exist "%CJS_BIN%" (
|
|
136
|
+
set "PATH=%CJS_BIN%;%CJS_TOOLS%;%PATH%"
|
|
137
|
+
set "CANGJIE_HOME=%CANGJIE_SDK%\build-tools"
|
|
138
|
+
echo [ohos] cjc = %CJS_BIN%\cjc.exe
|
|
139
|
+
echo [ohos] CANGJIE_HOME = %CANGJIE_HOME%
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
rem entry/cjpm.toml references stdx via the relative path "../stdx" = a junction on
|
|
144
|
+
rem the project root. hvigor only substitutes its own template vars, any other
|
|
145
|
+
rem ${...} expands to an empty string which kills the whole path-option line
|
|
146
|
+
rem (reported as "not added as a dependency").
|
|
147
|
+
if not exist "stdx" (
|
|
148
|
+
if not exist "%CANGJIE_STDX_OHOS%" (
|
|
149
|
+
echo [ohos] CANGJIE_STDX_OHOS points to a non-existent dir: %CANGJIE_STDX_OHOS% 1>&2
|
|
150
|
+
exit /b 1
|
|
151
|
+
)
|
|
152
|
+
mklink /J "stdx" "%CANGJIE_STDX_OHOS%" >nul
|
|
153
|
+
echo [ohos] stdx junction created: stdx -^> %CANGJIE_STDX_OHOS%
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
rem Stale artifacts: hvigor's CompileCangjie and framework-side cjpm each keep
|
|
157
|
+
rem their own incremental cache; clearing only one feeds back an old .so.
|
|
158
|
+
if "%DO_CLEAN%"=="1" (
|
|
159
|
+
echo [ohos] cleaning entry/build (--clean)
|
|
160
|
+
if exist "entry\build" rmdir /s /q "entry\build"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
rem Assets sync: the project root assets/ dir is the single source of truth
|
|
164
|
+
rem (RFC-002 section 7). Pages and capability manifests are real rawfile files
|
|
165
|
+
rem inside the hap - building without this sync installs STALE pages.
|
|
166
|
+
if exist "..\..\cj-tauri.toml" if exist "..\..\assets" (
|
|
167
|
+
set "RAWFILE=entry\src\main\resources\rawfile"
|
|
168
|
+
if exist "%RAWFILE%\ui" rmdir /s /q "%RAWFILE%\ui"
|
|
169
|
+
if exist "%RAWFILE%\capabilities" rmdir /s /q "%RAWFILE%\capabilities"
|
|
170
|
+
xcopy /e /i /y /q "..\..\assets\ui" "%RAWFILE%\ui\" >nul
|
|
171
|
+
xcopy /e /i /y /q "..\..\assets\capabilities" "%RAWFILE%\capabilities\" >nul
|
|
172
|
+
echo [ohos] assets synced from project root to rawfile (ui/ + capabilities/)
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
rem --no-daemon is mandatory: the resident daemon's CompileCangjie uses the env
|
|
176
|
+
rem captured at daemon start; PATH/CANGJIE_HOME exported here never reach it.
|
|
177
|
+
call "%NODE_EXE%" "%HVIGOR_JS%" --no-daemon --mode module -p product=default -p module=entry@default assembleHap
|
|
178
|
+
if errorlevel 1 (
|
|
179
|
+
echo [ohos] hvigor assembleHap failed (see output above) 1>&2
|
|
180
|
+
exit /b 1
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
set "HAP_DIR=entry\build\default\outputs\default"
|
|
184
|
+
set "HAP="
|
|
185
|
+
for /f "delims=" %%F in ('dir /b /o-d "%HAP_DIR%\*.hap" 2^>nul') do (
|
|
186
|
+
if not defined HAP set "HAP=%HAP_DIR%\%%~F"
|
|
187
|
+
)
|
|
188
|
+
if not defined HAP (
|
|
189
|
+
echo [ohos] build finished but no hap artifact; check the hvigor output above 1>&2
|
|
190
|
+
exit /b 1
|
|
191
|
+
)
|
|
192
|
+
for %%A in ("%HAP%") do set "HAP_SIZE=%%~zA"
|
|
193
|
+
echo [ohos] HAP = %HAP% (%HAP_SIZE% bytes)
|
|
194
|
+
echo "%HAP%" | findstr /i "unsigned" >nul && (
|
|
195
|
+
echo [ohos] unsigned hap: cannot be installed. Configure auto-signing in DevEco and rebuild. 1>&2
|
|
196
|
+
set "DO_INSTALL=0"
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
if "%DO_INSTALL%"=="1" (
|
|
200
|
+
set "HDC=%DEVECO_SDK_HOME%\default\openharmony\toolchains\hdc.exe"
|
|
201
|
+
if not exist "%HDC%" (
|
|
202
|
+
echo [ohos] hdc not found: %HDC% (--install needs it; or put your own hdc on PATH) 1>&2
|
|
203
|
+
exit /b 1
|
|
204
|
+
)
|
|
205
|
+
echo [ohos] connected devices:
|
|
206
|
+
call "%HDC%" list targets
|
|
207
|
+
echo [ohos] installing %HAP%
|
|
208
|
+
call "%HDC%" install -r "%HAP%"
|
|
209
|
+
if errorlevel 1 (
|
|
210
|
+
echo [ohos] hdc install failed 1>&2
|
|
211
|
+
exit /b 1
|
|
212
|
+
)
|
|
213
|
+
echo [ohos] starting EntryAbility
|
|
214
|
+
rem -a must be the ability name in module.json5 (EntryAbility), not the Cangjie class name.
|
|
215
|
+
call "%HDC%" shell aa start -a EntryAbility -b {{BUNDLE_NAME}}
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
endlocal
|
|
219
|
+
exit /b 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cj-tauri",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.6",
|
|
4
4
|
"description": "Tauri for the Cangjie language: a scaffold CLI for hybrid desktop apps — Cangjie backend (statically compiled) plus a system WebView frontend (HTML/CSS/JS), with a bidirectional IPC bridge and a capability-based security model. Windows, Linux and HarmonyOS PC.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cangjie",
|
package/src/host_arkweb.cj
CHANGED
|
@@ -653,6 +653,16 @@ public class ArkWebHost <: WebViewHost {
|
|
|
653
653
|
return false
|
|
654
654
|
}
|
|
655
655
|
|
|
656
|
+
/**
|
|
657
|
+
* 鸿蒙侧 C 桥未落地,读不到 WebView cookie 仓库——按接口契约返回错误 JSON,
|
|
658
|
+
* 不抛异常(调用方不必判 null)
|
|
659
|
+
*/
|
|
660
|
+
public func cookiesJson(filter: String): String {
|
|
661
|
+
let _ = filter
|
|
662
|
+
logd("[cj-tauri] ArkWeb: cookiesJson unsupported (C bridge not landed on ohos)")
|
|
663
|
+
return "{\"ok\":false,\"error\":\"cookies are not available on this platform\"}"
|
|
664
|
+
}
|
|
665
|
+
|
|
656
666
|
/**
|
|
657
667
|
* 在页面里执行一段脚本(框架的 `resolve` / `event` 回投就走这条)
|
|
658
668
|
*
|
package/src/version.cj
CHANGED