transone-cli 0.3.1 → 0.4.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 CHANGED
@@ -23,7 +23,7 @@ Usage:
23
23
  transone dev [--host <host>] [--port <port>] [--base <path>] [--no-watch]
24
24
  transone build [--target <target>] [--out-dir <path>] [--base <path>] [--library]
25
25
 
26
- Targets: web, mp-weixin, mp-alipay, mp-bytedance, app-ios, app-android, app-harmony (default: web)
26
+ Targets: web, mp-weixin, mp-alipay, mp-bytedance, mp-xiaohongshu, app-ios, app-android, app-harmony (default: web)
27
27
  ```
28
28
 
29
29
  ### `transone create`
@@ -43,13 +43,14 @@ transone build --target web # H5 site / SPA
43
43
  transone build --target mp-weixin # WeChat mini-program project (WXML/WXSS/JS)
44
44
  transone build --target mp-alipay # Alipay mini-program project (AXML/ACSS)
45
45
  transone build --target mp-bytedance # ByteDance mini-program project (TTML/TTSS)
46
+ transone build --target mp-xiaohongshu # Xiaohongshu mini-program project (XHSML/CSS)
46
47
  ```
47
48
 
48
49
  - `--out-dir` overrides the output directory.
49
50
  - `--base` sets the deployment base path (e.g. a GitHub Pages sub-path).
50
51
  - `--library` builds in library mode (no page entry required).
51
52
 
52
- Unimplemented targets fail fast at compile time with a clear error pointing to the corresponding roadmap stage.
53
+ The iOS, Android, and Harmony native app targets are implemented. A generated project should still be opened in its platform IDE for runtime/device validation.
53
54
 
54
55
  ## Targets
55
56
 
@@ -59,7 +60,8 @@ Unimplemented targets fail fast at compile time with a clear error pointing to t
59
60
  | `mp-weixin` | Native WeChat mini-program project | Compile-time static conversion (WXML / WXSS / JS) | Implemented |
60
61
  | `mp-alipay` | Native Alipay mini-program project | Compile-time static conversion (AXML / ACSS) | Implemented |
61
62
  | `mp-bytedance` | Native ByteDance mini-program project | Compile-time static conversion (TTML / TTSS) | Implemented |
62
- | `app-ios` / `app-android` / `app-harmony` | Native app | TBD | Roadmap |
63
+ | `mp-xiaohongshu` | Native Xiaohongshu Mini Program (not Mini Widget) | Compile-time static conversion (XHSML / CSS) | Implemented |
64
+ | `app-ios` / `app-android` / `app-harmony` | Native app (SwiftUI / Jetpack Compose / ArkUI) | Compile-time source generation | Implemented |
63
65
 
64
66
  Mini-program builds emit a complete native project: `app.json` / `app.js` / app style file / project config, plus `pages/<route>/<name>.*` and `components/<tag>/<tag>.*`. Platform differences (template syntax, style language, event binding, lifecycle mapping) are handled by the `MpDialect` abstraction.
65
67
 
@@ -93,13 +95,21 @@ export default defineConfig({
93
95
  });
94
96
  ```
95
97
 
96
- The `mp` field accepts either a single `MiniProgramConfig` (applies to every mini-program target; recommended for WeChat-only apps) or a per-platform map like `{ 'mp-weixin': {...}, 'mp-alipay': {...} }` — only the config for the current target is used.
98
+ The `mp` field accepts either a single `MiniProgramConfig` (applies to every mini-program target) or a per-platform map like `{ 'mp-weixin': {...}, 'mp-alipay': {...}, 'mp-xiaohongshu': {...} }` — only the config for the current target is used. Xiaohongshu uses the default placeholder app ID unless you set its own `appId`.
99
+
100
+ Generate the Counter playground project for Xiaohongshu with:
101
+
102
+ ```bash
103
+ bun run --cwd playground/counter build:xiaohongshu
104
+ ```
105
+
106
+ The output is `playground/counter/dist/build/mp-xiaohongshu`.
97
107
 
98
108
  ## How the compiler works
99
109
 
100
110
  1. Loads the project config and resolves pages from the entry file.
101
111
  2. For Web: renders directly with the browser runtime (H5 site / SPA).
102
- 3. For mini-program targets: statically analyzes the root component class of each page, then compiles the component tree into native files — WXML/JS (WeChat), AXML/ACSS (Alipay), TTML/TTSS (ByteDance) — including styles, template bindings, event methods, and data-state mapping. The generated code is a standalone native project with no TransOne runtime.
112
+ 3. For mini-program targets: statically analyzes the root component class of each page, then compiles the component tree into native files — WXML/WXSS (WeChat), AXML/ACSS (Alipay), TTML/TTSS (ByteDance), and XHSML/CSS (Xiaohongshu) — including styles, template bindings, event methods, and data-state mapping. The generated code is a standalone native project with no TransOne runtime.
103
113
  4. Library components are resolved through the `"source"` field of each package's `package.json` (see `transone-ui`).
104
114
 
105
115
  ## Extending a new target
package/README.zh-CN.md CHANGED
@@ -8,10 +8,11 @@ TransOne 多端编译器:Bun 原生 CLI,按 Target 将一份 TypeScript 源
8
8
 
9
9
  ```text
10
10
  web 直接渲染(HTML + 浏览器运行时,M1 已实现)
11
- mp-weixin WXML / WXSS / JS 静态转换(M2 规划中)
12
- mp-alipay AXML / ACSS 静态转换(M3 规划中)
13
- mp-bytedance ttml / ttss 静态转换(M3 规划中)
14
- app-* 远期占位(app-ios / app-android / app-harmony)
11
+ mp-weixin WXML / WXSS / JS 静态转换(已实现)
12
+ mp-alipay AXML / ACSS 静态转换(已实现)
13
+ mp-bytedance TTML / TTSS 静态转换(已实现)
14
+ mp-xiaohongshu XHSML / CSS 静态转换(已实现;小红书小程序,非小组件)
15
+ app-* 原生应用代码生成(app-ios / app-android / app-harmony,已实现)
15
16
  ```
16
17
 
17
18
  新增目标端:实现 `BuildTarget` 接口并注册到 `TargetRegistry`,无需改动构建入口。
@@ -20,7 +21,8 @@ app-* 远期占位(app-ios / app-android / app-harmony)
20
21
 
21
22
  ```bash
22
23
  transone build --target web # 产出 H5 站点
23
- transone build --target mp-weixin # 未实现时编译期报错并给出路线图阶段
24
+ transone build --target mp-weixin # 生成微信小程序原生工程
25
+ transone build --target mp-xiaohongshu # 生成小红书小程序原生工程(XHSML / CSS)
24
26
  transone dev # 开发服务(仅 web)
25
27
  transone create # 脚手架
26
28
  ```
@@ -30,6 +32,17 @@ bun test # 测试
30
32
  bun run build # 构建 dist(CLI bundle + .d.ts)
31
33
  ```
32
34
 
35
+ 在 Counter 演练项目中生成微信、支付宝、字节和小红书小程序:
36
+
37
+ ```bash
38
+ bun run --cwd playground/counter build:weixin
39
+ bun run --cwd playground/counter build:alipay
40
+ bun run --cwd playground/counter build:bytedance
41
+ bun run --cwd playground/counter build:xiaohongshu
42
+ ```
43
+
44
+ 小红书产物位于 `playground/counter/dist/build/mp-xiaohongshu`。`mp` 配置既支持适用于所有小程序端的扁平配置,也支持按 target 分组;小红书未配置 `appId` 时使用占位默认值,导入开发者工具前应设置真实 App ID。
45
+
33
46
  ## 文档
34
47
 
35
48
  - 在线文档(CLI 子站):<https://geektech-team.github.io/transone/cli/>
@@ -0,0 +1,2 @@
1
+ import type { NativeScreen } from './types';
2
+ export declare function analyzeNativeScreen(entry: string): Promise<NativeScreen>;
@@ -0,0 +1,3 @@
1
+ import type { BuildResult, ResolvedConfig } from '../types';
2
+ import type { NativeDialect } from './types';
3
+ export declare function buildNativeApp(config: ResolvedConfig, dialect: NativeDialect): Promise<BuildResult>;
@@ -0,0 +1,4 @@
1
+ import type { NativeDialect } from './types';
2
+ export declare const IOS_DIALECT: NativeDialect;
3
+ export declare const ANDROID_DIALECT: NativeDialect;
4
+ export declare const HARMONY_DIALECT: NativeDialect;
@@ -0,0 +1 @@
1
+ export declare function nativeError(filePath: string, message: string): Error;
@@ -0,0 +1,61 @@
1
+ import type { ResolvedAppConfig } from '../types';
2
+ export type NativeStateValue = string | number | boolean;
3
+ export interface NativeStateEntry {
4
+ key: string;
5
+ value: NativeStateValue;
6
+ }
7
+ export interface NativeStyle {
8
+ color?: string;
9
+ backgroundColor?: string;
10
+ fontSize?: number;
11
+ fontWeight?: string | number;
12
+ padding?: number;
13
+ margin?: number;
14
+ width?: number;
15
+ height?: number;
16
+ borderRadius?: number;
17
+ textAlign?: string;
18
+ }
19
+ export type NativeTextPart = {
20
+ kind: 'literal';
21
+ value: string;
22
+ } | {
23
+ kind: 'state';
24
+ key: string;
25
+ };
26
+ export type NativeAction = {
27
+ kind: 'increment';
28
+ key: string;
29
+ by: number;
30
+ } | {
31
+ kind: 'set-literal';
32
+ key: string;
33
+ value: NativeStateValue;
34
+ };
35
+ export type NativeNode = {
36
+ kind: 'container';
37
+ children: NativeNode[];
38
+ style?: NativeStyle;
39
+ } | {
40
+ kind: 'text';
41
+ parts: NativeTextPart[];
42
+ style?: NativeStyle;
43
+ } | {
44
+ kind: 'button';
45
+ parts: NativeTextPart[];
46
+ action: NativeAction;
47
+ style?: NativeStyle;
48
+ };
49
+ export interface NativeScreen {
50
+ name: string;
51
+ state: NativeStateEntry[];
52
+ root: Extract<NativeNode, {
53
+ kind: 'container';
54
+ }>;
55
+ }
56
+ export interface NativeDialect {
57
+ readonly id: 'app-ios' | 'app-android' | 'app-harmony';
58
+ readonly label: string;
59
+ readonly resourceDirectory: string;
60
+ generateProject(screen: NativeScreen, config: ResolvedAppConfig): Record<string, string>;
61
+ }
@@ -1,23 +1,14 @@
1
1
  // @bun
2
2
  import {
3
- __require
4
- } from "./index-yb2wsc7f.js";
3
+ loadTypescript
4
+ } from "./index-k1qfvp0y.js";
5
+ import"./index-yb2wsc7f.js";
5
6
 
6
7
  // src/mp/build-mp.ts
7
8
  import { cp, mkdir, readdir, rm, writeFile } from "fs/promises";
8
9
  import { existsSync as existsSync2 } from "fs";
9
10
  import { basename, dirname as dirname3, join as join3, relative, resolve as resolve2 } from "path";
10
11
 
11
- // src/mp/ts-loader.ts
12
- var tsModule = null;
13
- async function loadTypescript() {
14
- if (tsModule) {
15
- return tsModule;
16
- }
17
- tsModule = await import("typescript");
18
- return tsModule;
19
- }
20
-
21
12
  // src/mp/analyze.ts
22
13
  import { existsSync, readFileSync } from "fs";
23
14
  import { dirname, join, resolve } from "path";
@@ -2805,5 +2796,5 @@ export {
2805
2796
  buildMiniProgram
2806
2797
  };
2807
2798
 
2808
- //# debugId=EBDB309ADE017FFC64756E2164756E21
2809
- //# sourceMappingURL=build-mp-k1dgvwwx.js.map
2799
+ //# debugId=B563DD7B11FB4E5E64756E2164756E21
2800
+ //# sourceMappingURL=build-mp-6j38wf4r.js.map